Mercurial > hg > octave-kai > gnulib-hg
annotate lib/utime.c @ 4474:f1650b772bb6
Correct SunOS and Solaris version number notation to match Sun's usage.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 22 Jul 2003 22:56:34 +0000 |
parents | 7f998811f2f0 |
children | 9583f9cee522 |
rev | line source |
---|---|
4474
f1650b772bb6
Correct SunOS and Solaris version number notation to match Sun's usage.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4105
diff
changeset
|
1 /* Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. |
1442 | 2 |
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 | |
6 later version. | |
7 | |
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. | |
12 | |
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. */ | |
16 | |
17 /* derived from a function in touch.c */ | |
18 | |
19 #ifdef HAVE_CONFIG_H | |
20 # include <config.h> | |
21 #endif | |
22 #undef utime | |
23 | |
24 #include <sys/types.h> | |
25 | |
26 #ifdef HAVE_UTIME_H | |
27 # include <utime.h> | |
28 #endif | |
29 | |
3406 | 30 #include "full-write.h" |
1442 | 31 #include "safe-read.h" |
32 | |
33 /* Some systems (even some that do have <utime.h>) don't declare this | |
34 structure anywhere. */ | |
35 #ifndef HAVE_STRUCT_UTIMBUF | |
36 struct utimbuf | |
37 { | |
38 long actime; | |
39 long modtime; | |
40 }; | |
41 #endif | |
42 | |
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. */ | |
46 | |
47 static int | |
48 utime_null (const char *file) | |
49 { | |
50 #if HAVE_UTIMES_NULL | |
51 return utimes (file, 0); | |
52 #else | |
53 int fd; | |
54 char c; | |
55 int status = 0; | |
56 struct stat sb; | |
57 | |
1820
6908e7ed16b7
(utime_null): Don't pass 0666 to open; it's not needed and isn't
Jim Meyering <jim@meyering.net>
parents:
1442
diff
changeset
|
58 fd = open (file, O_RDWR); |
1442 | 59 if (fd < 0 |
60 || fstat (fd, &sb) < 0 | |
4088
815386455680
Update for changed signature of safe_read.
Bruno Haible <bruno@clisp.org>
parents:
3407
diff
changeset
|
61 || safe_read (fd, &c, sizeof c) == SAFE_READ_ERROR |
1442 | 62 || lseek (fd, (off_t) 0, SEEK_SET) < 0 |
3406 | 63 || full_write (fd, &c, sizeof c) != sizeof c |
4474
f1650b772bb6
Correct SunOS and Solaris version number notation to match Sun's usage.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4105
diff
changeset
|
64 /* Maybe do this -- it's necessary on SunOS 4.1.3 with some combination |
1442 | 65 of patches, but that system doesn't use this code: it has utimes. |
66 || fsync (fd) < 0 | |
67 */ | |
4105
7f998811f2f0
Don't call ftruncate() when it's not needed.
Bruno Haible <bruno@clisp.org>
parents:
4088
diff
changeset
|
68 || (st.st_size == 0 && ftruncate (fd, st.st_size) < 0) |
1442 | 69 || close (fd) < 0) |
70 status = -1; | |
71 return status; | |
72 #endif | |
73 } | |
74 | |
75 int | |
76 rpl_utime (const char *file, const struct utimbuf *times) | |
77 { | |
78 if (times) | |
79 return utime (file, times); | |
80 | |
81 return utime_null (file); | |
82 } |