]> git.cworth.org Git - tar/blob - gnu/fdutimensat.c
Imported Upstream version 1.24
[tar] / gnu / fdutimensat.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Set file access and modification times.
4
5    Copyright (C) 2009-2010 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by the
9    Free Software Foundation; either version 3 of the License, or any
10    later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Written by Eric Blake.  */
21
22 /* derived from a function in utimens.c */
23
24 #include <config.h>
25
26 #include "utimens.h"
27
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <sys/stat.h>
31
32 /* Set the access and modification time stamps of FD (a.k.a. FILE) to be
33    TIMESPEC[0] and TIMESPEC[1], respectively; relative to directory DIR.
34    FD must be either negative -- in which case it is ignored --
35    or a file descriptor that is open on FILE.
36    If FD is nonnegative, then FILE can be NULL, which means
37    use just futimes (or equivalent) instead of utimes (or equivalent),
38    and fail if on an old system without futimes (or equivalent).
39    If TIMESPEC is null, set the time stamps to the current time.
40    ATFLAG is passed to utimensat if FD is negative or futimens was
41    unsupported, which can allow operation on FILE as a symlink.
42    Return 0 on success, -1 (setting errno) on failure.  */
43
44 int
45 fdutimensat (int fd, int dir, char const *file, struct timespec const ts[2],
46              int atflag)
47 {
48   int result = 1;
49   if (0 <= fd)
50     result = futimens (fd, ts);
51   if (file && (fd < 0 || (result == -1 && errno == ENOSYS)))
52     result = utimensat (dir, file, ts, atflag);
53   if (result == 1)
54     {
55       errno = EBADF;
56       result = -1;
57     }
58   return result;
59 }