1 /* Copyright (C) 2003 Free Software Foundation, Inc.
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 /* Written by Paul Eggert. */
19 /* derived from a function in touch.c */
31 /* Some systems (even some that do have <utime.h>) don't declare this
32 structure anywhere. */
33 #ifndef HAVE_STRUCT_UTIMBUF
41 /* Set the access and modification time stamps of FILE to be
42 TIMESPEC[0] and TIMESPEC[1], respectively. */
45 utimens (char const *file
, struct timespec
const timespec
[2])
47 /* There's currently no interface to set file timestamps with
48 nanosecond resolution, so do the best we can, discarding any
49 fractional part of the timestamp. */
50 #if HAVE_WORKING_UTIMES
51 struct timeval timeval
[2];
52 timeval
[0].tv_sec
= timespec
[0].tv_sec
;
53 timeval
[0].tv_usec
= timespec
[0].tv_nsec
/ 1000;
54 timeval
[1].tv_sec
= timespec
[1].tv_sec
;
55 timeval
[1].tv_usec
= timespec
[1].tv_nsec
/ 1000;
56 return utimes (file
, timeval
);
58 struct utimbuf utimbuf
;
59 utimbuf
.actime
= timespec
[0].tv_sec
;
60 utimbuf
.modtime
= timespec
[1].tv_sec
;
61 return utime (file
, &utimbuf
);