Annotation of 43BSDReno/sys/nfs/TEST/unix-tests/special/open-chmod.c, revision 1.1

1.1     ! root        1: /*     @(#)open-chmod.c        1.2 90/01/03 NFS Rev 2 Testsuite
        !             2:  *     1.3 Lachman ONC Test Suite source
        !             3:  *
        !             4:  *  tests operation on open file which has been chmod'd to 0.
        !             5:  *  steps taken:
        !             6:  *     1.  create file
        !             7:  *     2.  open for read/write
        !             8:  *     3.  chmod 0
        !             9:  *     4.  write data
        !            10:  *     5.  rewind
        !            11:  *     6.  read data back
        !            12:  */
        !            13: 
        !            14: #include <stdio.h>
        !            15: #ifdef SVR3
        !            16: #include <fcntl.h>
        !            17: #else
        !            18: #include <sys/file.h>
        !            19: #endif
        !            20: #include <errno.h>
        !            21: extern int errno;
        !            22: #define TBUFSIZ 100
        !            23: char wbuf[TBUFSIZ], rbuf[TBUFSIZ];
        !            24: char buf[BUFSIZ];
        !            25: #define TMSG "This is a test message written to the chmod'd file\n"
        !            26: 
        !            27: main(argc, argv)
        !            28: int argc;
        !            29: char *argv[];
        !            30: {
        !            31:        int fd, ret;
        !            32:        char *tname = "nfstestXXXXXX";
        !            33:        int errcount = 0;
        !            34:        long lret;
        !            35:        extern long lseek();
        !            36: 
        !            37:        setbuf(stdout, NULL);
        !            38:        mktemp(tname);
        !            39: #ifdef O_RDWR
        !            40:        if ((fd = open(tname, O_CREAT|O_TRUNC|O_RDWR, 0777)) < 0) {
        !            41:                fprintf(stderr, "can't create %s: ", tname);
        !            42:                xxit("open");
        !            43:        }
        !            44: #else
        !            45:        if ((fd = creat(tname, 0777)) < 0) {
        !            46:                fprintf(stderr, "can't create %s: ", tname);
        !            47:                xxit("creat");
        !            48:        }
        !            49:        close(fd);
        !            50:        if ((fd = open(tname, 2)) < 0) {
        !            51:                fprintf(stderr, "can't reopen %s: ", tname);
        !            52:                unlink(tname);
        !            53:                xxit("open");
        !            54:        }
        !            55: #endif /* O_RDWR */
        !            56:        printf("testfile before chmod:\n  ");
        !            57:        sprintf(buf, "ls -l %s", tname);
        !            58:        system(buf);
        !            59:        ret = chmod(tname, 0);
        !            60:        printf("%s open; chmod ret = %d\n", tname, ret);
        !            61:        if (ret)
        !            62:                xxit(" chmod");
        !            63:        printf("testfile after chmod:\n  ");
        !            64:        system(buf);
        !            65:        strcpy(wbuf, TMSG);
        !            66:        if ((ret = write(fd, wbuf, TBUFSIZ)) != TBUFSIZ) {
        !            67:                fprintf(stderr, "write ret %d; expected %d\n", ret, TBUFSIZ);
        !            68:                if (ret < 0)
        !            69:                        perror(" write");
        !            70:                exit(1);
        !            71:        }
        !            72:        if ((lret = lseek(fd, 0L, 0)) != 0L) {
        !            73:                fprintf(stderr, "lseek ret %ld; expected 0\n", lret);
        !            74:                if (lret < 0)
        !            75:                        perror(" lseek");
        !            76:                exit(1);
        !            77:        }
        !            78:        if ((ret = read(fd, rbuf, TBUFSIZ)) != TBUFSIZ) {
        !            79:                fprintf(stderr, "read ret %d; expected %d\n", ret, TBUFSIZ);
        !            80:                if (ret < 0)
        !            81:                        perror(" read");
        !            82:                exit(1);
        !            83:        }
        !            84:        if (strcmp(wbuf, rbuf) != NULL) {
        !            85:                errcount++;
        !            86:                printf("read data not same as written data\n");
        !            87:                printf(" written: '%s'\n read:    '%s'\n", wbuf, rbuf);
        !            88:        } else {
        !            89:                printf("data compare ok\n");
        !            90:        }
        !            91: 
        !            92:        printf("testfile after write/read:\n  ");
        !            93:        system(buf);
        !            94:        if (unlink(tname) < 0) {
        !            95:                fprintf(stderr, "can't unlink %s", tname);
        !            96:                xxit(" ");
        !            97:        }
        !            98: 
        !            99:        if (close(fd))
        !           100:                xxit("error on close");
        !           101: 
        !           102:        printf("test completed successfully.\n");
        !           103:        exit(0);
        !           104: }
        !           105: 
        !           106: xxit(s)
        !           107: char *s;
        !           108: {
        !           109:        perror(s);
        !           110:        exit(1);
        !           111: }

unix.superglobalmegacorp.com

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