summary refs log tree commit diff
path: root/io/test-utime.c
diff options
context:
space:
mode:
authorGreg McGary <greg@mcgary.org>2000-08-03 20:04:31 +0000
committerGreg McGary <greg@mcgary.org>2000-08-03 20:04:31 +0000
commit274aead3955a31c8dc9da865c8b9a7345bbc0ea8 (patch)
treec2459c82e41603032b9abbed70d583b2c6cccdaa /io/test-utime.c
parent0d019734966f91c3511933d207802631a7774def (diff)
downloadglibc-274aead3955a31c8dc9da865c8b9a7345bbc0ea8.tar.gz
glibc-274aead3955a31c8dc9da865c8b9a7345bbc0ea8.tar.xz
glibc-274aead3955a31c8dc9da865c8b9a7345bbc0ea8.zip
* sysdeps/unix/sysv/syscalls.list (time, utime): Correct signatures.
* io/test-utime.c: Test passing NULL as utimbuf* arg.
Diffstat (limited to 'io/test-utime.c')
-rw-r--r--io/test-utime.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/io/test-utime.c b/io/test-utime.c
index 32e14bd161..8dbbcf990d 100644
--- a/io/test-utime.c
+++ b/io/test-utime.c
@@ -22,6 +22,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <utime.h>
+#include <time.h>
 
 int
 main (int argc, char *argv[])
@@ -29,6 +30,8 @@ main (int argc, char *argv[])
   char file[L_tmpnam];
   struct utimbuf ut;
   struct stat st;
+  struct stat stnow;
+  time_t now1, now2;
   int fd;
 
   if (tmpnam (file) == 0)
@@ -45,6 +48,7 @@ main (int argc, char *argv[])
     }
   close (fd);
 
+  /* Test utime with arg */
   ut.actime = 500000000;
   ut.modtime = 500000001;
   if (utime (file, &ut))
@@ -61,6 +65,39 @@ main (int argc, char *argv[])
       exit (1);
     }
 
+  /* Test utime with NULL.
+     Since there's a race condition possible here, we check
+     the time before and after the call to utime.  */
+  now1 = time (NULL);
+  if (now1 == (time_t)-1)
+    {
+      perror ("time");
+      remove (file);
+      exit (1);
+    }
+
+  if (utime (file, NULL))
+    {
+      perror ("utime NULL");
+      remove (file);
+      exit (1);
+    }
+
+  now2 = time (NULL);
+  if (now2 == (time_t)-1)
+    {
+      perror ("time");
+      remove (file);
+      exit (1);
+    }
+
+  if (stat (file, &stnow))
+    {
+      perror ("stat");
+      remove (file);
+      exit (1);
+    }
+
   remove (file);
 
   if (st.st_mtime != ut.modtime)
@@ -75,6 +112,18 @@ main (int argc, char *argv[])
       exit (1);
     }
 
+  if (stnow.st_mtime < now1 || stnow.st_mtime > now2)
+    {
+      printf ("modtime %ld <%ld >%ld\n", st.st_mtime, now1, now2);
+      exit (1);
+    }
+
+  if (stnow.st_atime < now1 || stnow.st_atime > now2)
+    {
+      printf ("actime %ld <%ld >%ld\n", st.st_atime, now1, now2);
+      exit (1);
+    }
+
   puts ("Test succeeded.");
   exit (0);
 }