1 /* POSIX test program (39). Author: Andy Tanenbaum */
3 /* The following POSIX calls are tested:
13 #include <sys/types.h>
26 #define DIR_NULL (DIR*) NULL
27 #define ITERATIONS 3 /* LINK_MAX is high, so time consuming */
28 #define MAX_FD 100 /* must be large enough to cause error */
29 #define BUF_SIZE PATH_MAX+20
30 #define ERR_CODE -1 /* error return */
34 char str
[] = {"The time has come the walrus said to talk of many things.\n"};
35 char str2
[] = {"Of ships and shoes and sealing wax, of cabbages and kings.\n"};
36 char str3
[] = {"Of why the sea is boiling hot and whether pigs have wings\n"};
40 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
41 _PROTOTYPE(void test39a
, (void));
42 _PROTOTYPE(void checkdir
, (DIR *dirp
, int t
));
43 _PROTOTYPE(void test39b
, (void));
44 _PROTOTYPE(void test39c
, (void));
45 _PROTOTYPE(void test39d
, (void));
46 _PROTOTYPE(void test39e
, (void));
47 _PROTOTYPE(void test39f
, (void));
48 _PROTOTYPE(void test39g
, (void));
49 _PROTOTYPE(void test39h
, (void));
50 _PROTOTYPE(void test39i
, (void));
51 _PROTOTYPE(void test39j
, (void));
52 _PROTOTYPE(void e
, (int n
));
53 _PROTOTYPE(void quit
, (void));
63 if (geteuid() == 0 || getuid() == 0) {
64 printf("Test 39 cannot run as root; test aborted\n");
68 if (argc
== 2) m
= atoi(argv
[1]);
72 system("rm -rf DIR_39; mkdir DIR_39");
75 for (i
= 0; i
< ITERATIONS
; i
++) {
76 if (m
& 00001) test39a(); /* test for correct operation */
77 if (m
& 00002) test39b(); /* test general error handling */
78 if (m
& 00004) test39c(); /* test for EMFILE error */
79 if (m
& 00010) test39d(); /* test chdir() and getcwd() */
80 if (m
& 00020) test39e(); /* test open() */
81 if (m
& 00040) test39f(); /* test umask(), stat(), fstat() */
82 if (m
& 00100) test39g(); /* test link() and unlink() */
83 if (m
& 00200) test39h(); /* test access() */
84 if (m
& 00400) test39i(); /* test chmod() and chown() */
85 if (m
& 01000) test39j(); /* test utime() */
88 return(-1); /* impossible */
93 /* Subtest 1. Correct operation */
95 int f1
, f2
, f3
, f4
, f5
;
98 /* Remove any residue of previous tests. */
101 system("rm -rf foo");
103 /* Create a directory foo with 5 files in it. */
105 if ((f1
= creat("foo/f1", 0666)) < 0) e(1);
106 if ((f2
= creat("foo/f2", 0666)) < 0) e(2);
107 if ((f3
= creat("foo/f3", 0666)) < 0) e(3);
108 if ((f4
= creat("foo/f4", 0666)) < 0) e(4);
109 if ((f5
= creat("foo/f5", 0666)) < 0) e(5);
111 /* Now remove 2 files to create holes in the directory. */
112 if (unlink("foo/f2") < 0) e(6);
113 if (unlink("foo/f4") < 0) e(7);
115 /* Close the files. */
122 /* Open the directory. */
123 dirp
= opendir("./foo");
124 if (dirp
== DIR_NULL
) e(6);
126 /* Read the 5 files from it. */
129 /* Rewind dir and test again. */
133 /* We're done. Close the directory stream. */
134 if (closedir(dirp
) < 0) e(7);
136 /* Remove dir for next time. */
137 system("rm -rf foo");
140 void checkdir(dirp
, t
)
141 DIR *dirp
; /* poinrter to directory stream */
142 int t
; /* subtest number to use */
145 int i
, f1
, f2
, f3
, f4
, f5
, dot
, dotdot
, subt
;
149 /* Save subtest number */
153 /* Clear the counters. */
162 /* Read the directory. It should contain 5 entries, ".", ".." and 3
164 for (i
= 0; i
< 5; i
++) {
166 if (d
== (struct dirent
*) NULL
) {
168 subtest
= subt
; /* restore subtest number */
172 if (strcmp(s
, ".") == 0) dot
++;
173 if (strcmp(s
, "..") == 0) dotdot
++;
174 if (strcmp(s
, "f1") == 0) f1
++;
175 if (strcmp(s
, "f2") == 0) f2
++;
176 if (strcmp(s
, "f3") == 0) f3
++;
177 if (strcmp(s
, "f4") == 0) f4
++;
178 if (strcmp(s
, "f5") == 0) f5
++;
183 if (d
!= (struct dirent
*) NULL
) e(2);
184 if (f1
!= 1 || f3
!= 1 || f5
!= 1) e(3);
185 if (f2
!= 0 || f4
!= 0) e(4);
186 if (dot
!= 1 || dotdot
!= 1) e(5);
193 /* Subtest 4. Test error handling. */
200 if (opendir("foo/xyz/---") != DIR_NULL
) e(1);
201 if (errno
!= ENOENT
) e(2);
202 if (mkdir("foo", 0777) < 0) e(3);
203 if (chmod("foo", 0) < 0) e(4);
204 if (opendir("foo/xyz/--") != DIR_NULL
) e(5);
205 if (errno
!= EACCES
) e(6);
206 if (chmod("foo", 0777) != 0) e(7);
207 if (rmdir("foo") != 0) e(8);
208 if ((fd
= creat("abc", 0666)) < 0) e(9);
209 if (close(fd
) < 0) e(10);
210 if (opendir("abc/xyz") != DIR_NULL
) e(11);
211 if (errno
!= ENOTDIR
) e(12);
212 if ((dirp
= opendir(".")) == DIR_NULL
) e(13);
213 if (closedir(dirp
) != 0) e(14);
214 if (unlink("abc") != 0) e(15);
220 /* Subtest 5. See what happens if we open too many directory streams. */
227 for (i
= 0; i
< MAX_FD
; i
++) {
228 dirp
[i
] = opendir(".");
229 if (dirp
[i
] == (DIR *) NULL
) {
230 /* We have hit the limit. */
231 if (errno
!= EMFILE
&& errno
!= ENOMEM
) e(1);
232 for (j
= 0; j
< i
; j
++) {
233 if (closedir(dirp
[j
]) != 0) e(2); /* close */
239 /* Control should never come here. This is an error. */
241 for (i
= 0; i
< MAX_FD
; i
++) closedir(dirp
[i
]); /* don't check */
246 /* Test chdir and getcwd(). */
250 char base
[BUF_SIZE
], buf2
[BUF_SIZE
], tmp
[BUF_SIZE
];
254 if (getcwd(base
, BUF_SIZE
) == (char *) NULL
) e(1); /* get test dir's path */
255 if (system("rm -rf Dir") != 0) e(2); /* remove residue of previous test */
256 if (mkdir("Dir", 0777) < 0) e(3); /* create directory called "Dir" */
258 /* Change to Dir and verify that it worked. */
259 if (chdir("Dir") < 0) e(4); /* go to Dir */
260 s
= getcwd(buf2
, BUF_SIZE
); /* get full path of Dir */
261 if (s
== (char *) NULL
) e(5); /* check for error return */
262 if (s
!= buf2
) e(6); /* if successful, first arg is returned */
263 strcpy(tmp
, base
); /* concatenate base name and "/Dir" */
266 if (strcmp(tmp
, s
) != 0) e(7);
268 /* Change to ".." and verify that it worked. */
269 if (chdir("..") < 0) e(8);
270 if (getcwd(buf2
, BUF_SIZE
) != buf2
) e(9);
271 if (strcmp(buf2
, base
) != 0) e(10);
273 /* Now make calls that do nothing, but do it in a strange way. */
274 if (chdir("Dir/..") < 0) e(11);
275 if (getcwd(buf2
, BUF_SIZE
) != buf2
) e(12);
276 if (strcmp(buf2
, base
) != 0) e(13);
278 if (chdir("Dir/../Dir/..") < 0) e(14);
279 if (getcwd(buf2
, BUF_SIZE
) != buf2
) e(15);
280 if (strcmp(buf2
, base
) != 0) e(16);
282 if (chdir("Dir/../Dir/../Dir/../Dir/../Dir/../Dir/../Dir/..") < 0) e(17);
283 if (getcwd(buf2
, BUF_SIZE
) != buf2
) e(18);
284 if (strcmp(buf2
, base
) != 0) e(19);
286 /* Make Dir unreadable and unsearchable. Check error message. */
287 if (chmod("Dir", 0) < 0) e(20);
288 if (chdir("Dir") >= 0) e(21);
289 if (errno
!= EACCES
) e(22);
291 /* Check error message for bad path. */
292 if (chmod("Dir", 0777) < 0) e(23);
293 if (chdir("Dir/x/y") != ERR_CODE
) e(24);
294 if (errno
!= ENOENT
) e(25);
296 if ( (fd
=creat("Dir/x", 0777)) < 0) e(26);
297 if (close(fd
) != 0) e(27);
298 if (chdir("Dir/x/y") != ERR_CODE
) e(28);
299 if (errno
!= ENOTDIR
) e(29);
301 /* Check empty string. */
302 if (chdir("") != ERR_CODE
) e(30);
303 if (errno
!= ENOENT
) e(31);
305 /* Remove the directory. */
306 if (unlink("Dir/x") != 0) e(32);
307 if (system("rmdir Dir") != 0) e(33);
314 int fd
, bytes
, bytes2
;
319 unlink("T39"); /* get rid of it in case it exists */
321 /* Create a test file. */
323 bytes2
= strlen(str2
);
324 if ((fd
= creat("T39", 0777)) < 0) e(1);
325 if (write(fd
, str
, bytes
) != bytes
) e(2); /* T39 now has 'bytes' bytes */
326 if (close(fd
) != 0) e(3);
328 /* Test opening a file with O_RDONLY. */
329 if ((fd
= open("T39", O_RDONLY
)) < 0) e(4);
331 if (read(fd
, buf
, RD_BUF
) != bytes
) e(5);
332 if (strncmp(buf
, str
, bytes
) != 0) e(6);
333 if (close(fd
) < 0) e(7);
335 /* Test the same thing, only with O_RDWR now. */
336 if ((fd
= open("T39", O_RDWR
)) < 0) e(8);
338 if (read(fd
, buf
, RD_BUF
) != bytes
) e(9);
339 if (strncmp(buf
, str
, bytes
) != 0) e(10);
340 if (close(fd
) < 0) e(11);
342 /* Try opening and reading with O_WRONLY. It should fail. */
343 if ((fd
= open("T39", O_WRONLY
)) < 0) e(12);
345 if (read(fd
, buf
, RD_BUF
) >= 0) e(13);
346 if (close(fd
) != 0) e(14);
349 if ((fd
= open("T39", O_RDWR
| O_APPEND
)) < 0) e(15);
350 if (lseek(fd
, 0L, SEEK_SET
) < 0) e(16); /* go to start of file */
351 if ( write(fd
, str2
, bytes2
) != bytes2
) e(17); /* write at start of file */
352 if (lseek(fd
, 0L, SEEK_SET
) < 0) e(18); /* go back to start again */
353 if (read(fd
, buf
, RD_BUF
) != bytes
+ bytes2
) e(19); /* read whole file */
354 if (strncmp(buf
, str
, bytes
) != 0) e(20);
355 if (close(fd
) != 0) e(21);
357 /* Get rid of the file. */
358 if (unlink("T39") < 0) e(22);
363 /* Test stat, fstat, umask. */
366 struct stat stbuf1
, stbuf2
;
372 if (system("rm -rf foo xxx") != 0) e(1);
373 if ((fd
= creat("foo", 0777)) < 0) e(2);
374 if (stat("foo", &stbuf1
) < 0) e(3);
375 if (fstat(fd
, &stbuf2
) < 0) e(4);
376 if (stbuf1
.st_mode
!= stbuf2
.st_mode
) e(5);
377 if (stbuf1
.st_ino
!= stbuf2
.st_ino
) e(6);
378 if (stbuf1
.st_dev
!= stbuf2
.st_dev
) e(7);
379 if (stbuf1
.st_nlink
!= stbuf2
.st_nlink
) e(8);
380 if (stbuf1
.st_uid
!= stbuf2
.st_uid
) e(9);
381 if (stbuf1
.st_gid
!= stbuf2
.st_gid
) e(10);
382 if (stbuf1
.st_size
!= stbuf2
.st_size
) e(11);
383 if (stbuf1
.st_atime
!= stbuf2
.st_atime
) e(12);
384 if (stbuf1
.st_mtime
!= stbuf2
.st_mtime
) e(13);
385 if (stbuf1
.st_ctime
!= stbuf2
.st_ctime
) e(14);
387 if (!S_ISREG(stbuf1
.st_mode
)) e(15);
388 if (S_ISDIR(stbuf1
.st_mode
)) e(16);
389 if (S_ISCHR(stbuf1
.st_mode
)) e(17);
390 if (S_ISBLK(stbuf1
.st_mode
)) e(18);
391 if (S_ISFIFO(stbuf1
.st_mode
)) e(19);
393 if ((stbuf1
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
)) != 0777) e(20);
394 if (stbuf1
.st_nlink
!= 1) e(21);
395 if (stbuf1
.st_uid
!= getuid()) e(22);
396 if (stbuf1
.st_gid
!= getgid()) e(23);
397 if (stbuf1
.st_size
!= 0L) e(24);
399 /* First unlink, then close -- harder test */
400 if (unlink("foo") < 0) e(25);
401 if (close(fd
) < 0) e(26);
403 /* Now try umask a bit more. */
405 if ((i
= umask(~0704)) != 0) e(27);
406 if ((fd
= creat("foo", 0777)) < 0) e(28);
407 if (stat("foo", &stbuf1
) < 0) e(29);
408 if (fstat(fd
, &stbuf2
) < 0) e(30);
409 if (stbuf1
.st_mode
!= stbuf2
.st_mode
) e(31);
410 if ((stbuf1
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
)) != 0704) e(32);
412 /* First unlink, then close -- harder test */
413 if (unlink("foo") < 0) e(33);
414 if (close(fd
) < 0) e(34);
415 if (umask(m1
) != 073) e(35);
417 /* Test some errors. */
418 if (system("mkdir Dir; date >Dir/x; chmod 666 Dir") != 0) e(36);
419 if (stat("Dir/x", &stbuf1
) >= 0) e(37);
420 if (errno
!= EACCES
) e(38);
421 if (stat("......", &stbuf1
) >= 0) e(39);
422 if (errno
!= ENOENT
) e(40);
423 if (stat("", &stbuf1
) >= 0) e(41);
424 if (errno
!= ENOENT
) e(42);
425 if (stat("xxx/yyy/zzz", &stbuf1
) >= 0) e(43);
426 if (errno
!= ENOENT
) e(44);
427 if (fstat(10000, &stbuf1
) >= 0) e(45);
428 if (errno
!= EBADF
) e(46);
429 if (chmod("Dir", 0777) != 0) e(47);
430 if (system("rm -rf foo Dir") != 0) e(48);
432 /* See if time looks reasonable. */
434 t
= time(&t1
); /* current time */
435 if (t
< 650000000L) e(49); /* 650000000 is Sept. 1990 */
437 fd
= creat("T39f", 0777);
439 if (close(fd
) < 0) e(51);
440 if (stat("T39f", &stbuf1
) < 0) e(52);
441 if (stbuf1
.st_mtime
< t
) e(53);
442 if (unlink("T39f") < 0) e(54);
447 /* Test link and unlink. */
454 if (system("rm -rf L? L?? Dir; mkdir Dir") != 0) e(1);
455 if ( (fd
= creat("L1", 0666)) < 0) e(2);
456 if (fstat(fd
, &stbuf
) != 0) e(3);
457 if (stbuf
.st_nlink
!= 1) e(4);
458 if (link("L1", "L2") != 0) e(5);
459 if (fstat(fd
, &stbuf
) != 0) e(6);
460 if (stbuf
.st_nlink
!= 2) e(7);
461 if (unlink("L2") != 0) e(8);
462 if (link("L1", "L2") != 0) e(9);
463 if (unlink("L1") != 0) e(10);
464 if (close(fd
) != 0) e(11);
466 /* L2 exists at this point. */
467 if ( (fd
= creat("L1", 0666)) < 0) e(12);
468 if (stat("L1", &stbuf
) != 0) e(13);
469 if (stbuf
.st_nlink
!= 1) e(14);
470 if (link("L1", "Dir/L2") != 0) e(15);
471 if (stat("L1", &stbuf
) != 0) e(16);
472 if (stbuf
.st_nlink
!= 2) e(17);
473 if (stat("Dir/L2", &stbuf
) != 0) e(18);
474 if (stbuf
.st_nlink
!= 2) e(19);
476 /* L1, L2, and Dir/L2 exist at this point. */
477 if (unlink("Dir/L2") != 0) e(20);
478 if (link("L1", "Dir/L2") != 0) e(21);
479 if (unlink("L1") != 0) e(22);
480 if (close(fd
) != 0) e(23);
481 if (chdir("Dir") != 0) e(24);
482 if (unlink("L2") != 0) e(25);
483 if (chdir("..") != 0) e(26);
485 /* L2 exists at this point. Test linking to unsearchable dir. */
486 if (link("L2", "Dir/L2") != 0) e(27);
487 if (chmod("Dir", 0666) != 0) e(27);
488 if (link("L2", "Dir/L2") != -1) e(28);
489 if (errno
!= EACCES
) e(29);
491 if (link("Dir/L2", "L3") != -1) e(30);
492 if (errno
!= EACCES
) e(31);
493 if (chmod("Dir", 0777) != 0) e(32);
494 if (unlink("Dir/L2") != 0) e(33);
495 if (unlink("L3") == 0) e(34);
497 /* L2 exists at this point. Test linking to unwriteable dir. */
498 if (chmod("Dir", 0555) != 0) e(35);
499 if (link("L2", "Dir/L2") != -1) e(36);
500 if (errno
!= EACCES
) e(37);
501 if (chmod("Dir", 0777) != 0) e(38);
503 /* L2 exists at this point. Test linking mode 0 file. */
504 if (chmod("L2", 0) != 0) e(39);
505 if (link("L2", "L3") != 0) e(40);
506 if (stat("L3", &stbuf
) != 0) e(41);
507 if (stbuf
.st_nlink
!= 2) e(42);
508 if (unlink("L2") != 0) e(43);
510 /* L3 exists at this point. Test linking to an existing file. */
511 if ( (fd
= creat("L1", 0666)) < 0) e(44);
512 if (link("L1", "L3") != -1) e(45);
513 if (errno
!= EEXIST
) e(46);
515 if (link("L1", "L1") != -1) e(47);
516 if (errno
!= EEXIST
) e(48);
517 if (unlink("L3") != 0) e(49);
519 /* L1 exists at this point. Test creating too many links. */
520 for (i
= 2; i
<= LINK_MAX
; i
++) {
521 sprintf(name
, "Lx%d", i
);
522 if (link("L1", name
) != 0) e(50);
524 if (stat("L1", &stbuf
) != 0) e(51);
525 if (stbuf
.st_nlink
!= LINK_MAX
) e(52);
526 if (link("L1", "L2") != -1) e(53);
527 if (errno
!= EMLINK
) e(54);
528 for (i
= 2; i
<= LINK_MAX
; i
++) {
529 sprintf(name
, "Lx%d", i
);
530 if (unlink(name
) != 0) e(55);
533 if (stat("L1", &stbuf
) != 0) e(56);
534 if (stbuf
.st_nlink
!= 1) e(57);
536 /* L1 exists. Test ENOENT. */
538 if (link("xx/L1", "L2") != -1) e(58);
539 if (errno
!= ENOENT
) e(59);
541 if (link("L1", "xx/L2") != -1) e(60);
542 if (errno
!= ENOENT
) e(61);
544 if (link("L4", "L5") != -1) e(62);
545 if (errno
!= ENOENT
) e(63);
547 if (link("", "L5") != -1) e(64);
548 if (errno
!= ENOENT
) e(65);
550 if (link("L1", "") != -1) e(66);
551 if (errno
!= ENOENT
) e(67);
553 /* L1 exists. Test ENOTDIR. */
555 if (link("/dev/tty/x", "L2") != -1) e(68);
556 if (errno
!= ENOTDIR
) e(69);
558 /* L1 exists. Test EPERM. */
559 if (link(".", "L2") != -1) e(70);
560 if (errno
!= EPERM
) e(71);
562 /* L1 exists. Test unlink. */
563 if (link("L1", "Dir/L1") != 0) e(72);
564 if (chmod("Dir", 0666) != 0) e(73);
565 if (unlink("Dir/L1") != -1) e(74);
566 if (errno
!= EACCES
) e(75);
568 if (chmod("Dir", 0555) != 0) e(76);
569 if (unlink("Dir/L1") != -1) e(77);
570 if (errno
!= EACCES
) e(78);
572 if (unlink("L7") != -1) e(79);
573 if (errno
!= ENOENT
) e(80);
575 if (unlink("") != -1) e(81);
576 if (errno
!= ENOENT
) e(82);
578 if (unlink("Dir/L1/L2") != -1) e(83);
579 if (errno
!= ENOTDIR
) e(84);
581 if (chmod("Dir", 0777) != 0) e(85);
582 if (unlink("Dir/L1") != 0) e(86);
583 if (unlink("Dir") != -1) e(87);
584 if (errno
!= EPERM
) e(88);
585 if (unlink("L1") != 0) e(89);
586 if (system("rm -rf Dir") != 0) e(90);
587 if (close(fd
) != 0) e(91);
598 if ( (fd
= creat("A1", 0777)) < 0) e(1);
599 if (close(fd
) != 0) e(2);
600 if (access("A1", R_OK
) != 0) e(3);
601 if (access("A1", W_OK
) != 0) e(4);
602 if (access("A1", X_OK
) != 0) e(5);
603 if (access("A1", (R_OK
|W_OK
|X_OK
)) != 0) e(6);
605 if (chmod("A1", 0400) != 0) e(7);
606 if (access("A1", R_OK
) != 0) e(8);
607 if (access("A1", W_OK
) != -1) e(9);
608 if (access("A1", X_OK
) != -1) e(10);
609 if (access("A1", (R_OK
|W_OK
|X_OK
)) != -1) e(11);
611 if (chmod("A1", 0077) != 0) e(12);
612 if (access("A1", R_OK
) != -1) e(13);
613 if (access("A1", W_OK
) != -1) e(14);
614 if (access("A1", X_OK
) != -1) e(15);
615 if (access("A1", (R_OK
|W_OK
|X_OK
)) != -1) e(16);
616 if (errno
!= EACCES
) e(17);
618 if (access("", R_OK
) != -1) e(18);
619 if (errno
!= ENOENT
) e(19);
620 if (access("./A1/x", R_OK
) != -1) e(20);
621 if (errno
!= ENOTDIR
) e(21);
623 if (unlink("A1") != 0) e(22);
635 if ( (fd
= creat("A1", 0777)) < 0) e(1);
637 for (i
= 0; i
< 511; i
++) {
638 if (chmod("A1", i
) != 0) e(100+i
);
639 if (fstat(fd
, &stbuf
) != 0) e(200+i
);
640 if ( (stbuf
.st_mode
&(S_IRWXU
|S_IRWXG
|S_IRWXO
)) != i
) e(300+i
);
642 if (close(fd
) != 0) e(2);
644 if (chmod("A1/x", 0777) != -1) e(3);
645 if (errno
!= ENOTDIR
) e(4);
646 if (chmod("Axxx", 0777) != -1) e(5);
647 if (errno
!= ENOENT
) e(6);
649 if (chmod ("", 0777) != -1) e(7);
650 if (errno
!= ENOENT
) e(8);
652 /* Now perform limited chown tests. These should work even as non su */
654 /* DEBUG -- Not yet implemented
655 if (chown("A1", i, 0) != 0) e(9);
656 if (chown("A1", i, 1) != 0) e(10);
657 if (chown("A1", i, 2) != 0) e(11);
658 if (chown("A1", i, 3) != 0) e(12);
659 if (chown("A1", i, 4) != 0) e(13);
660 if (chown("A1", i, 0) != 0) e(14);
663 if (unlink("A1") != 0) e(9);
672 struct utimbuf times
;
676 if (system("rm -rf A2") != 0) e(1);
677 if ( (fd
= creat("A2", 0666)) < 0) e(2);
679 if (utime("A2", ×
) != 0) e(3);
680 if (stat("A2", &stbuf
) != 0) e(4);
681 if (stbuf
.st_mtime
!= 100) e(5);
683 tloc
= time((time_t *)NULL
); /* get current time */
684 times
.modtime
= tloc
;
685 if (utime("A2", ×
) != 0) e(6);
686 if (stat("A2", &stbuf
) != 0) e(7);
687 if (stbuf
.st_mtime
!= tloc
) e(8);
688 if (close(fd
) != 0) e(9);
689 if (unlink("A2") != 0) e(10);
695 int err_num
= errno
; /* save errno in case printf clobbers it */
697 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
698 fflush(stdout
); /* stdout and stderr are mixed horribly */
699 errno
= err_num
; /* restore errno, just in case */
701 if (errct
++ > MAX_ERROR
) {
702 printf("Too many errors; test aborted\n");
704 system("rm -rf DIR*");
713 system("rm -rf DIR*");
719 printf("%d errors\n", errct
);