|
|
1.1 root 1: #include <stdio.h>
2:
3:
4: main(argc,argv)
5: int argc;
6: char *argv[];
7: {
8: int i;
9: static int force = 1;
10:
11: for(i = 1 ; i < argc ; ++i)
12: if( strcmp(argv[i], "-c") )
13: touch(force, argv[i]);
14: else
15: force = 0;
16: return 0;
17: }
18:
19:
20:
21:
22: #include <sys/types.h>
23: #include <sys/stat.h>
24:
25:
26: touch(force, name)
27: int force;
28: char *name;
29: {
30: struct stat stbuff;
31: char junk[1];
32: int fd;
33:
34: if( stat(name,&stbuff) < 0)
35: if(force)
36: goto create;
37: else
38: {
39: fprintf(stderr, "touch: file %s does not exist.\n", name);
40: return;
41: }
42:
43: if(stbuff.st_size == 0)
44: goto create;
45:
46: if( (fd = open(name, 2)) < 0)
47: goto bad;
48:
49: if( read(fd, junk, 1) < 1)
50: {
51: close(fd);
52: goto bad;
53: }
54: lseek(fd, 0L, 0);
55: if( write(fd, junk, 1) < 1 )
56: {
57: close(fd);
58: goto bad;
59: }
60: close(fd);
61: return;
62:
63: bad:
64: fprintf(stderr, "Cannot touch %s\n", name);
65: return;
66:
67: create:
68: if( (fd = creat(name, 0666)) < 0)
69: goto bad;
70: close(fd);
71: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.