]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/futimes.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / futimes.c
CommitLineData
82bae9f9
UD
1/* futimes -- change access and modification times of open file. Stub version.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#include <errno.h>
21#include <sysdep.h>
22#include <utime.h>
23#include <sys/time.h>
24#include <stdio-common/_itoa.h>
25
f4e0175f
UD
26#include "kernel-features.h"
27
82bae9f9
UD
28/* Change the access time of FILE to TVP[0] and
29 the modification time of FILE to TVP[1], but do not follow symlinks.
30
31 The Linux kernel has no futimes() syscall so we use the /proc
32 filesystem. */
33int
34__futimes (int fd, const struct timeval tvp[2])
35{
36 static const char selffd[] = "/proc/self/fd/";
f4e0175f
UD
37 char fname[sizeof (selffd) + 3 * sizeof (int)];
38 fname[sizeof (fname) - 1] = '\0';
b1b060c3 39 char *cp = _itoa_word ((unsigned int) fd, fname + sizeof (fname) - 1, 10, 0);
82bae9f9
UD
40 cp = memcpy (cp - sizeof (selffd) + 1, selffd, sizeof (selffd) - 1);
41
42#ifdef __NR_utimes
43 int result = INLINE_SYSCALL (utimes, 2, cp, tvp);
44# ifndef __ASSUME_UTIMES
45 if (result != -1 || errno != ENOSYS)
46# endif
47 return result;
48#endif
49
50 /* The utimes() syscall does not exist or is not available in the
51 used kernel. Use utime(). For this we have to convert to the
52 data format utime() expects. */
53#ifndef __ASSUME_UTIMES
f4e0175f
UD
54 struct utimbuf buf;
55 struct utimbuf *times;
56
57 if (tvp != NULL)
82bae9f9 58 {
f4e0175f
UD
59 times = &buf;
60 buf.actime = tvp[0].tv_sec + tvp[0].tv_usec >= 500000;
61 buf.modtime = tvp[1].tv_sec + tvp[1].tv_usec >= 500000;
62 }
63 else
64 times = NULL;
65
66 return INLINE_SYSCALL (utime, 2, cp, times);
82bae9f9
UD
67#endif
68}
69weak_alias (__futimes, futimes)