Mercurial > hg > octave-shane > gnulib-hg
annotate lib/utimens.c @ 9613:c4fa39bf5223
Don't redefine __attribute__ without a need.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 13 Jan 2008 16:51:48 +0100 |
parents | bbbbbf4cd1c5 |
children | bbccff5988c3 |
rev | line source |
---|---|
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
1 /* Set file access and modification times. |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
2 |
9613
c4fa39bf5223
Don't redefine __attribute__ without a need.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7713
diff
changeset
|
4 Foundation, Inc. |
5147 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8842
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify it |
5147 | 7 under the terms of the GNU General Public License as published by the |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8842
diff
changeset
|
8 Free Software Foundation; either version 3 of the License, or any |
5147 | 9 later version. |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8842
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5147 | 18 |
19 /* Written by Paul Eggert. */ | |
20 | |
21 /* derived from a function in touch.c */ | |
22 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6819
diff
changeset
|
23 #include <config.h> |
5147 | 24 |
25 #include "utimens.h" | |
26 | |
5589
6ddb405e16b6
(futimens): Account for the fact that futimes
Paul Eggert <eggert@cs.ucla.edu>
parents:
5485
diff
changeset
|
27 #include <errno.h> |
6283
b377d8796118
* lib/utimens.c (futimens): Use futimesat if available.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
28 #include <fcntl.h> |
7897
b7a83a69ac23
* MODULES.html.sh (Support for systems lacking POSIX:2001): New
Paul Eggert <eggert@cs.ucla.edu>
parents:
7713
diff
changeset
|
29 #include <sys/time.h> |
6322 | 30 #include <unistd.h> |
5589
6ddb405e16b6
(futimens): Account for the fact that futimes
Paul Eggert <eggert@cs.ucla.edu>
parents:
5485
diff
changeset
|
31 |
5147 | 32 #if HAVE_UTIME_H |
33 # include <utime.h> | |
34 #endif | |
35 | |
36 /* Some systems (even some that do have <utime.h>) don't declare this | |
37 structure anywhere. */ | |
38 #ifndef HAVE_STRUCT_UTIMBUF | |
39 struct utimbuf | |
40 { | |
41 long actime; | |
42 long modtime; | |
43 }; | |
44 #endif | |
45 | |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
46 /* Some systems don't have ENOSYS. */ |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
47 #ifndef ENOSYS |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
48 # ifdef ENOTSUP |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
49 # define ENOSYS ENOTSUP |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
50 # else |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
51 /* Some systems don't have ENOTSUP either. */ |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
52 # define ENOSYS EINVAL |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
53 # endif |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
54 #endif |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
55 |
6819
3449832bdc37
* getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6734
diff
changeset
|
56 #ifndef __attribute__ |
9613
c4fa39bf5223
Don't redefine __attribute__ without a need.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
57 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) |
6819
3449832bdc37
* getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6734
diff
changeset
|
58 # define __attribute__(x) |
3449832bdc37
* getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6734
diff
changeset
|
59 # endif |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
60 #endif |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
61 |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
62 #ifndef ATTRIBUTE_UNUSED |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
63 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
64 #endif |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
65 |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
66 /* Set the access and modification time stamps of FD (a.k.a. FILE) to be |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
67 TIMESPEC[0] and TIMESPEC[1], respectively. |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
68 FD must be either negative -- in which case it is ignored -- |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
69 or a file descriptor that is open on FILE. |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
70 If FD is nonnegative, then FILE can be NULL, which means |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
71 use just futimes (or equivalent) instead of utimes (or equivalent), |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
72 and fail if on an old system without futimes (or equivalent). |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
73 If TIMESPEC is null, set the time stamps to the current time. |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
74 Return 0 on success, -1 (setting errno) on failure. */ |
5147 | 75 |
76 int | |
8842
7605663b153e
* lib/utimens.c (gl_futimens): Rename from futimens,
Jim Meyering <jim@meyering.net>
parents:
7897
diff
changeset
|
77 gl_futimens (int fd ATTRIBUTE_UNUSED, |
7605663b153e
* lib/utimens.c (gl_futimens): Rename from futimens,
Jim Meyering <jim@meyering.net>
parents:
7897
diff
changeset
|
78 char const *file, struct timespec const timespec[2]) |
5147 | 79 { |
7712
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
80 /* Some Linux-based NFS clients are buggy, and mishandle time stamps |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
81 of files in NFS file systems in some cases. We have no |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
82 configure-time test for this, but please see |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
83 <http://bugs.gentoo.org/show_bug.cgi?id=132673> for references to |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
84 some of the problems with Linux 2.6.16. If this affects you, |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
85 compile with -DHAVE_BUGGY_NFS_TIME_STAMPS; this is reported to |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
86 help in some cases, albeit at a cost in performance. But you |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
87 really should upgrade your kernel to a fixed version, since the |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
88 problem affects many applications. */ |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
89 |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
90 #if HAVE_BUGGY_NFS_TIME_STAMPS |
7713
064005e1c3c3
Prefer fd < 0 to ! (0 <= fd).
Paul Eggert <eggert@cs.ucla.edu>
parents:
7712
diff
changeset
|
91 if (fd < 0) |
064005e1c3c3
Prefer fd < 0 to ! (0 <= fd).
Paul Eggert <eggert@cs.ucla.edu>
parents:
7712
diff
changeset
|
92 sync (); |
064005e1c3c3
Prefer fd < 0 to ! (0 <= fd).
Paul Eggert <eggert@cs.ucla.edu>
parents:
7712
diff
changeset
|
93 else |
7712
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
94 fsync (fd); |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
95 #endif |
aead3397193a
* lib/utimens.c (futimens) [HAVE_BUGGY_NFS_TIME_STAMPS]: Add a
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
96 |
5147 | 97 /* There's currently no interface to set file timestamps with |
98 nanosecond resolution, so do the best we can, discarding any | |
99 fractional part of the timestamp. */ | |
6283
b377d8796118
* lib/utimens.c (futimens): Use futimesat if available.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
100 #if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES |
5147 | 101 struct timeval timeval[2]; |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
102 struct timeval const *t; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
103 if (timespec) |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
104 { |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
105 timeval[0].tv_sec = timespec[0].tv_sec; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
106 timeval[0].tv_usec = timespec[0].tv_nsec / 1000; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
107 timeval[1].tv_sec = timespec[1].tv_sec; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
108 timeval[1].tv_usec = timespec[1].tv_nsec / 1000; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
109 t = timeval; |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
110 } |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
111 else |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
112 t = NULL; |
6283
b377d8796118
* lib/utimens.c (futimens): Use futimesat if available.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
113 |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
114 |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
115 if (fd < 0) |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
116 { |
6283
b377d8796118
* lib/utimens.c (futimens): Use futimesat if available.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
117 # if HAVE_FUTIMESAT |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
118 return futimesat (AT_FDCWD, file, t); |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
119 # endif |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
120 } |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
121 else |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
122 { |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
123 /* If futimesat or futimes fails here, don't try to speed things |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
124 up by returning right away. glibc can incorrectly fail with |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
125 errno == ENOENT if /proc isn't mounted. Also, Mandrake 10.0 |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
126 in high security mode doesn't allow ordinary users to read |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
127 /proc/self, so glibc incorrectly fails with errno == EACCES. |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
128 If errno == EIO, EPERM, or EROFS, it's probably safe to fail |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
129 right away, but these cases are rare enough that they're not |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
130 worth optimizing, and who knows what other messed-up systems |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
131 are out there? So play it safe and fall back on the code |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
132 below. */ |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
133 # if HAVE_FUTIMESAT |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
134 if (futimesat (fd, NULL, t) == 0) |
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
135 return 0; |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
136 # elif HAVE_FUTIMES |
5589
6ddb405e16b6
(futimens): Account for the fact that futimes
Paul Eggert <eggert@cs.ucla.edu>
parents:
5485
diff
changeset
|
137 if (futimes (fd, t) == 0) |
6ddb405e16b6
(futimens): Account for the fact that futimes
Paul Eggert <eggert@cs.ucla.edu>
parents:
5485
diff
changeset
|
138 return 0; |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
139 # endif |
5589
6ddb405e16b6
(futimens): Account for the fact that futimes
Paul Eggert <eggert@cs.ucla.edu>
parents:
5485
diff
changeset
|
140 } |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
141 #endif |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
142 |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
143 if (!file) |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
144 { |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
145 #if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES)) |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
146 errno = ENOSYS; |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
147 #endif |
6322 | 148 |
149 /* Prefer EBADF to ENOSYS if both error numbers apply. */ | |
150 if (errno == ENOSYS) | |
151 { | |
152 int fd2 = dup (fd); | |
153 int dup_errno = errno; | |
154 if (0 <= fd2) | |
155 close (fd2); | |
156 errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS); | |
157 } | |
158 | |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
159 return -1; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
160 } |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
161 |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
162 #if HAVE_WORKING_UTIMES |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
163 return utimes (file, t); |
6734
3e5ad4566013
* utimens.c (futimens): glibc futimesat messes up if /proc
Paul Eggert <eggert@cs.ucla.edu>
parents:
6440
diff
changeset
|
164 #else |
6297
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
165 { |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
166 struct utimbuf utimbuf; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
167 struct utimbuf const *ut; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
168 if (timespec) |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
169 { |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
170 utimbuf.actime = timespec[0].tv_sec; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
171 utimbuf.modtime = timespec[1].tv_sec; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
172 ut = &utimbuf; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
173 } |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
174 else |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
175 ut = NULL; |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
176 |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
177 return utime (file, ut); |
10379892281e
* utimens.c (ENOSYS): Define if not already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6283
diff
changeset
|
178 } |
5147 | 179 #endif |
180 } | |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
181 |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
182 /* Set the access and modification time stamps of FILE to be |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
183 TIMESPEC[0] and TIMESPEC[1], respectively. */ |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
184 int |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
185 utimens (char const *file, struct timespec const timespec[2]) |
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
186 { |
8842
7605663b153e
* lib/utimens.c (gl_futimens): Rename from futimens,
Jim Meyering <jim@meyering.net>
parents:
7897
diff
changeset
|
187 return gl_futimens (-1, file, timespec); |
5485
863556283cee
(__attribute__, ATTRIBUTE_UNUSED): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5147
diff
changeset
|
188 } |