Annotation of coherent/b/kernel/tools/newer.c, revision 1.1

1.1     ! root        1: /* newer.c - exit with status 1 if first arg is newer than second,
        !             2:      else exit with status 0
        !             3:    -v option gives verbose response to stdout
        !             4:  */
        !             5: 
        !             6: #include <fcntl.h>
        !             7: #include <stdio.h>
        !             8: #include <sys/stat.h>
        !             9: 
        !            10: main(argc, argv)
        !            11: int argc;
        !            12: char * argv[];
        !            13: {
        !            14:        int fd1, fd2;
        !            15:        int argn, verbose = 0;
        !            16:        struct stat s1, s2;
        !            17: 
        !            18:        if (argc < 3 || argc > 4) {
        !            19:                fprintf(stderr, "Usage: %s [-v] file1 file2\n", argv[0]);
        !            20:                exit(2);
        !            21:        }
        !            22:        argn = 1;
        !            23: 
        !            24:        if (argc == 4) {
        !            25:                if (strcmp(argv[1], "-v")) {
        !            26:                        fprintf(stderr, "Usage: %s [-v] file1 file2\n", argv[0]);
        !            27:                        exit(2);
        !            28:                } else {
        !            29:                        verbose = 1;
        !            30:                        argn++;
        !            31:                }
        !            32:        }
        !            33: 
        !            34:        if ((fd1 = open(argv[argn], O_RDONLY)) < 0) {
        !            35:                if (verbose)
        !            36:                        fprintf(stderr, "%s: can't open file %s\n",
        !            37:                          argv[0], argv[argn]);
        !            38:                exit(2);
        !            39:        }
        !            40: 
        !            41:        if (fstat(fd1, &s1) < 0) {
        !            42:                if (verbose)
        !            43:                        fprintf(stderr, "%s: can't stat file %s\n",
        !            44:                          argv[0], argv[argn]);
        !            45:                exit(2);
        !            46:        }
        !            47: 
        !            48:        argn++;
        !            49:        if ((fd2 = open(argv[argn], O_RDONLY)) < 0) {
        !            50:                if (verbose)
        !            51:                        fprintf(stderr, "%s: can't open file %s\n",
        !            52:                          argv[0], argv[argn]);
        !            53:                exit(2);
        !            54:        }
        !            55: 
        !            56:        if (fstat(fd2, &s2) < 0) {
        !            57:                if (verbose)
        !            58:                        fprintf(stderr, "%s: can't stat file %s\n",
        !            59:                          argv[0], argv[argn]);
        !            60:                exit(2);
        !            61:        }
        !            62: 
        !            63:        close(fd1);
        !            64:        close(fd2);
        !            65: 
        !            66:        if (s1.st_mtime > s2.st_mtime) {
        !            67:                if (verbose)
        !            68:                        printf("%s is newer than %s\n",
        !            69:                          argv[argn-1], argv[argn]);
        !            70:                exit (0);
        !            71:        } else {
        !            72:                if (verbose)
        !            73:                        printf("%s is NOT newer than %s\n",
        !            74:                          argv[argn-1], argv[argn]);
        !            75:                exit (1);
        !            76:        }
        !            77: }

unix.superglobalmegacorp.com

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