Annotation of researchv10no/cmd/mk/export/t_file.c, revision 1.1.1.1

1.1       root        1: #include       "mk.h"
                      2: #include       <sys/types.h>
                      3: #include       <sys/stat.h>
                      4: #include       <errno.h>
                      5: 
                      6: #define        MYSEP(s)        ((*s == ' ') || (*s == ',') || (*s == '\n'))
                      7: 
                      8: timeinit(s)
                      9:        register char *s;
                     10: {
                     11:        register long t;
                     12:        register char *os;
                     13: 
                     14:        for(t = time((long *)0); *s; s = os){
                     15:                for(os = s; !MYSEP(os); os++)
                     16:                        if(*os == 0){
                     17:                                symlook(strdup(s), S_TIME, (char *)t)->value = (char *)t;
                     18:                                return;
                     19:                        }
                     20:                *os++ = 0;
                     21:                symlook(strdup(s), S_TIME, (char *)t)->value = (char *)t;
                     22:                while(MYSEP(os))
                     23:                        os++;
                     24:        }
                     25: }
                     26: 
                     27: long
                     28: ftimeof(force, name)
                     29:        char *name;
                     30: {
                     31:        struct stat sbuf;
                     32:        Symtab *sym;
                     33: 
                     34:        if(!force && (sym = symlook(name, S_TIME, (char *)0))){
                     35:                return((long)sym->value);
                     36:        }
                     37:        if(stat(name, &sbuf) < 0)
                     38:                sbuf.st_mtime = 0;
                     39:        symlook(name, S_TIME, (char *)sbuf.st_mtime);
                     40:        return((long)sbuf.st_mtime);
                     41: }
                     42: 
                     43: void
                     44: ftouch(name)
                     45:        char *name;
                     46: {
                     47:        int fd;
                     48:        char buf[1];
                     49:        struct stat sbuf;
                     50: 
                     51:        if(stat(name, &sbuf) < 0)       /* not there and zero length are same case */
                     52:                sbuf.st_size = 0;
                     53:        if(sbuf.st_size == 0){
                     54:                if((fd = creat(name, 0666)) < 0){
                     55:        bad:
                     56:                        perror(name);
                     57:                        Exit();
                     58:                }
                     59:                close(fd);
                     60:                return;
                     61:        }
                     62:        if((fd = open(name, 2)) < 0)
                     63:                goto bad;
                     64:        if(read(fd, buf, 1) != 1)
                     65:                goto bad;
                     66:        if(lseek(fd, 0L, 0) < 0)
                     67:                goto bad;
                     68:        if(write(fd, buf, 1) != 1)
                     69:                goto bad;
                     70:        close(fd);
                     71: }
                     72: 
                     73: void
                     74: fdelete(s)
                     75:        char *s;
                     76: {
                     77:        if(unlink(s) < 0)
                     78:                perror(s);
                     79: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.