* tst-trans.c: Include <stdlib.h> and <string.h>.
[jlayton/glibc.git] / io / test-utime.c
1 /* Copyright (C) 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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.  */
18
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>
25
26 int
27 main (int argc, char *argv[])
28 {
29   char file[L_tmpnam];
30   struct utimbuf ut;
31   struct stat st;
32   int fd;
33
34   if (tmpnam (file) == 0)
35     {
36       perror ("tmpnam");
37       exit (1);
38     }
39
40   fd = creat (file, 0666);
41   if (fd < 0)
42     {
43       perror ("creat");
44       exit (1);
45     }
46   close (fd);
47
48   ut.actime = 500000000;
49   ut.modtime = 500000001;
50   if (utime (file, &ut))
51     {
52       perror ("utime");
53       remove (file);
54       exit (1);
55     }
56
57   if (stat (file, &st))
58     {
59       perror ("stat");
60       remove (file);
61       exit (1);
62     }
63
64   remove (file);
65
66   if (st.st_mtime != ut.modtime)
67     {
68       printf ("modtime %ld != %ld\n", st.st_mtime, ut.modtime);
69       exit (1);
70     }
71
72   if (st.st_atime != ut.actime)
73     {
74       printf ("actime %ld != %ld\n", st.st_atime, ut.actime);
75       exit (1);
76     }
77
78   puts ("Test succeeded.");
79   exit (0);
80 }