Update.
[glibc.git] / io / test-utime.c
blob32e14bd161fb952736b7f86dd459a29d744051a3
1 /* Copyright (C) 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <fcntl.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <utime.h>
26 int
27 main (int argc, char *argv[])
29 char file[L_tmpnam];
30 struct utimbuf ut;
31 struct stat st;
32 int fd;
34 if (tmpnam (file) == 0)
36 perror ("tmpnam");
37 exit (1);
40 fd = creat (file, 0666);
41 if (fd < 0)
43 perror ("creat");
44 exit (1);
46 close (fd);
48 ut.actime = 500000000;
49 ut.modtime = 500000001;
50 if (utime (file, &ut))
52 perror ("utime");
53 remove (file);
54 exit (1);
57 if (stat (file, &st))
59 perror ("stat");
60 remove (file);
61 exit (1);
64 remove (file);
66 if (st.st_mtime != ut.modtime)
68 printf ("modtime %ld != %ld\n", st.st_mtime, ut.modtime);
69 exit (1);
72 if (st.st_atime != ut.actime)
74 printf ("actime %ld != %ld\n", st.st_atime, ut.actime);
75 exit (1);
78 puts ("Test succeeded.");
79 exit (0);