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