1 /* Copyright (C) 1998, 2001 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 /* derived from a function in touch.c */
24 #include <sys/types.h>
30 #include "full-write.h"
31 #include "safe-read.h"
33 /* Some systems (even some that do have <utime.h>) don't declare this
34 structure anywhere. */
35 #ifndef HAVE_STRUCT_UTIMBUF
43 /* Emulate utime (file, NULL) for systems (like 4.3BSD) that do not
44 interpret it to set the access and modification times of FILE to
45 the current time. Return 0 if successful, -1 if not. */
48 utime_null (const char *file
)
51 return utimes (file
, 0);
58 fd
= open (file
, O_RDWR
);
60 || fstat (fd
, &sb
) < 0
61 || safe_read (fd
, &c
, sizeof c
) < 0
62 || lseek (fd
, (off_t
) 0, SEEK_SET
) < 0
63 || full_write (fd
, &c
, sizeof c
) != sizeof c
64 /* Maybe do this -- it's necessary on SunOS4.1.3 with some combination
65 of patches, but that system doesn't use this code: it has utimes.
68 || ftruncate (fd
, st
.st_size
) < 0
76 rpl_utime (const char *file
, const struct utimbuf
*times
)
79 return utime (file
, times
);
81 return utime_null (file
);