reindent-20030715
[openafs.git] / src / venus / test / owntest.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #ifdef HAVE_STDLIB_H
13 #include <stdlib.h>
14 #endif
15
16 RCSID
17     ("$Header$");
18
19 #include <sys/types.h>
20 #include <sys/file.h>
21 #include <sys/stat.h>
22 #include <sys/time.h>
23 #include <errno.h>
24
25 extern int errno;
26
27 main(argc, argv)
28      int argc;
29      char **argv;
30 {
31     struct timeval tv[2];
32     struct stat tstat;
33     register long code;
34     register char *pn;          /* path name we're dealing with */
35
36     if (argc != 2) {
37         printf
38             ("usage: owntest <file owned by somoneelse, but still writable>\n");
39         exit(1);
40     }
41
42     pn = argv[1];
43     printf("Starting tests on %s.\n", pn);
44     code = chmod(pn, 0444);
45     if (code < 0) {
46         perror("chmod to RO");
47         exit(errno);
48     }
49     code = chmod(pn, 0666);
50     if (code < 0) {
51         perror("chmod back to RW");
52         exit(errno);
53     }
54     gettimeofday(&tv[0], NULL);
55     gettimeofday(&tv[1], NULL);
56     tv[0].tv_sec -= 10000;
57     tv[0].tv_usec = 0;
58     tv[1].tv_sec -= 20000;
59     tv[1].tv_usec = 0;
60     code = utimes(pn, tv);
61     if (code < 0) {
62         perror("utimes");
63         exit(errno);
64     }
65     code = stat(pn, &tstat);
66     if (code < 0) {
67         perror("stat");
68         exit(errno);
69     }
70     if (tstat.st_mtime != tv[1].tv_sec) {
71         printf("modtime didn't stick\n");
72         exit(1);
73     }
74     printf("Done.\n");
75     exit(0);
76 }