assorted-warning-cleanup-20071126
[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 #include <stdio.h>
16
17 RCSID
18     ("$Header$");
19
20 #include <sys/types.h>
21 #include <sys/file.h>
22 #include <sys/stat.h>
23 #include <sys/time.h>
24 #include <errno.h>
25
26 extern int errno;
27
28 main(argc, argv)
29      int argc;
30      char **argv;
31 {
32     struct timeval tv[2];
33     struct stat tstat;
34     register long code;
35     register char *pn;          /* path name we're dealing with */
36
37     if (argc != 2) {
38         printf
39             ("usage: owntest <file owned by somoneelse, but still writable>\n");
40         exit(1);
41     }
42
43     pn = argv[1];
44     printf("Starting tests on %s.\n", pn);
45     code = chmod(pn, 0444);
46     if (code < 0) {
47         perror("chmod to RO");
48         exit(errno);
49     }
50     code = chmod(pn, 0666);
51     if (code < 0) {
52         perror("chmod back to RW");
53         exit(errno);
54     }
55     gettimeofday(&tv[0], NULL);
56     gettimeofday(&tv[1], NULL);
57     tv[0].tv_sec -= 10000;
58     tv[0].tv_usec = 0;
59     tv[1].tv_sec -= 20000;
60     tv[1].tv_usec = 0;
61     code = utimes(pn, tv);
62     if (code < 0) {
63         perror("utimes");
64         exit(errno);
65     }
66     code = stat(pn, &tstat);
67     if (code < 0) {
68         perror("stat");
69         exit(errno);
70     }
71     if (tstat.st_mtime != tv[1].tv_sec) {
72         printf("modtime didn't stick\n");
73         exit(1);
74     }
75     printf("Done.\n");
76     exit(0);
77 }