Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 224483 | Differences between
and this patch

Collapse All | Expand All

(-)coreutils-6.12.orig/lib/utimens.c (-84 / +71 lines)
Lines 24-34 Link Here
24
24
25
#include "utimens.h"
25
#include "utimens.h"
26
26
27
#include <errno.h>
27
#include <errno.h>
28
#include <fcntl.h>
28
#include <fcntl.h>
29
#include <sys/stat.h>
30
#include <sys/time.h>
29
#include <sys/time.h>
31
#include <unistd.h>
30
#include <unistd.h>
32
31
33
#if HAVE_UTIME_H
32
#if HAVE_UTIME_H
34
# include <utime.h>
33
# include <utime.h>
Lines 93-197 Link Here
93
    sync ();
92
    sync ();
94
  else
93
  else
95
    fsync (fd);
94
    fsync (fd);
96
#endif
95
#endif
97
96
98
  /* POSIX 200x added two interfaces to set file timestamps with
97
  /* There's currently no interface to set file timestamps with
99
     nanosecond resolution.  */
100
#if HAVE_UTIMENSAT
101
  if (fd < 0)
102
    return utimensat (AT_FDCWD, file, timespec, 0);
103
#endif
104
#if HAVE_FUTIMENS
105
  return futimens (fd, timespec);
106
#else
107
108
  /* The platform lacks an interface to set file timestamps with
109
     nanosecond resolution, so do the best we can, discarding any
98
     nanosecond resolution, so do the best we can, discarding any
110
     fractional part of the timestamp.  */
99
     fractional part of the timestamp.  */
111
  {
100
#if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES
112
# if HAVE_FUTIMESAT || HAVE_WORKING_UTIMES
101
  struct timeval timeval[2];
113
    struct timeval timeval[2];
102
  struct timeval const *t;
114
    struct timeval const *t;
103
  if (timespec)
115
    if (timespec)
104
    {
116
      {
105
      timeval[0].tv_sec = timespec[0].tv_sec;
117
	timeval[0].tv_sec = timespec[0].tv_sec;
106
      timeval[0].tv_usec = timespec[0].tv_nsec / 1000;
118
	timeval[0].tv_usec = timespec[0].tv_nsec / 1000;
107
      timeval[1].tv_sec = timespec[1].tv_sec;
119
	timeval[1].tv_sec = timespec[1].tv_sec;
108
      timeval[1].tv_usec = timespec[1].tv_nsec / 1000;
120
	timeval[1].tv_usec = timespec[1].tv_nsec / 1000;
109
      t = timeval;
121
	t = timeval;
110
    }
122
      }
111
  else
123
    else
112
    t = NULL;
124
      t = NULL;
125
113
126
    if (fd < 0)
127
      {
128
#  if HAVE_FUTIMESAT
129
	return futimesat (AT_FDCWD, file, t);
130
#  endif
131
      }
132
    else
133
      {
134
	/* If futimesat or futimes fails here, don't try to speed things
135
	   up by returning right away.  glibc can incorrectly fail with
136
	   errno == ENOENT if /proc isn't mounted.  Also, Mandrake 10.0
137
	   in high security mode doesn't allow ordinary users to read
138
	   /proc/self, so glibc incorrectly fails with errno == EACCES.
139
	   If errno == EIO, EPERM, or EROFS, it's probably safe to fail
140
	   right away, but these cases are rare enough that they're not
141
	   worth optimizing, and who knows what other messed-up systems
142
	   are out there?  So play it safe and fall back on the code
143
	   below.  */
144
#  if HAVE_FUTIMESAT
145
	if (futimesat (fd, NULL, t) == 0)
146
	  return 0;
147
#  elif HAVE_FUTIMES
148
	if (futimes (fd, t) == 0)
149
	  return 0;
150
#  endif
151
      }
152
# endif /* HAVE_FUTIMESAT || HAVE_WORKING_UTIMES */
153
114
154
    if (!file)
115
  if (fd < 0)
155
      {
116
    {
156
# if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES))
117
# if HAVE_FUTIMESAT
157
	errno = ENOSYS;
118
      return futimesat (AT_FDCWD, file, t);
158
# endif
119
# endif
120
    }
121
  else
122
    {
123
      /* If futimesat or futimes fails here, don't try to speed things
124
	 up by returning right away.  glibc can incorrectly fail with
125
	 errno == ENOENT if /proc isn't mounted.  Also, Mandrake 10.0
126
	 in high security mode doesn't allow ordinary users to read
127
	 /proc/self, so glibc incorrectly fails with errno == EACCES.
128
	 If errno == EIO, EPERM, or EROFS, it's probably safe to fail
129
	 right away, but these cases are rare enough that they're not
130
	 worth optimizing, and who knows what other messed-up systems
131
	 are out there?  So play it safe and fall back on the code
132
	 below.  */
133
# if HAVE_FUTIMESAT
134
      if (futimesat (fd, NULL, t) == 0)
135
	return 0;
136
# elif HAVE_FUTIMES
137
      if (futimes (fd, t) == 0)
138
	return 0;
139
# endif
140
    }
141
#endif
159
142
160
	/* Prefer EBADF to ENOSYS if both error numbers apply.  */
143
  if (!file)
161
	if (errno == ENOSYS)
162
	  {
163
	    int fd2 = dup (fd);
164
	    int dup_errno = errno;
165
	    if (0 <= fd2)
166
	      close (fd2);
167
	    errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS);
168
	  }
169
170
	return -1;
171
      }
172
173
# if HAVE_WORKING_UTIMES
174
    return utimes (file, t);
175
# else
176
    {
144
    {
177
      struct utimbuf utimbuf;
145
#if ! (HAVE_FUTIMESAT || (HAVE_WORKING_UTIMES && HAVE_FUTIMES))
178
      struct utimbuf const *ut;
146
      errno = ENOSYS;
179
      if (timespec)
147
#endif
148
149
      /* Prefer EBADF to ENOSYS if both error numbers apply.  */
150
      if (errno == ENOSYS)
180
	{
151
	{
181
	  utimbuf.actime = timespec[0].tv_sec;
152
	  int fd2 = dup (fd);
182
	  utimbuf.modtime = timespec[1].tv_sec;
153
	  int dup_errno = errno;
183
	  ut = &utimbuf;
154
	  if (0 <= fd2)
155
	    close (fd2);
156
	  errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS);
184
	}
157
	}
185
      else
186
	ut = NULL;
187
158
188
      return utime (file, ut);
159
      return -1;
189
    }
160
    }
190
# endif /* !HAVE_WORKING_UTIMES */
161
162
#if HAVE_WORKING_UTIMES
163
  return utimes (file, t);
164
#else
165
  {
166
    struct utimbuf utimbuf;
167
    struct utimbuf const *ut;
168
    if (timespec)
169
      {
170
	utimbuf.actime = timespec[0].tv_sec;
171
	utimbuf.modtime = timespec[1].tv_sec;
172
	ut = &utimbuf;
173
      }
174
    else
175
      ut = NULL;
176
177
    return utime (file, ut);
191
  }
178
  }
192
#endif /* !HAVE_FUTIMENS */
179
#endif
193
}
180
}
194
181
195
/* Set the access and modification time stamps of FILE to be
182
/* Set the access and modification time stamps of FILE to be
196
   TIMESPEC[0] and TIMESPEC[1], respectively.  */
183
   TIMESPEC[0] and TIMESPEC[1], respectively.  */
197
int
184
int
(-)coreutils-6.12.orig/m4/utimens.m4 (-5 / +2 lines)
Lines 1-18 Link Here
1
dnl Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software
1
dnl Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
2
dnl Foundation, Inc.
3
dnl This file is free software; the Free Software Foundation
2
dnl This file is free software; the Free Software Foundation
4
dnl gives unlimited permission to copy and/or distribute it,
3
dnl gives unlimited permission to copy and/or distribute it,
5
dnl with or without modifications, as long as this notice is preserved.
4
dnl with or without modifications, as long as this notice is preserved.
6
5
7
dnl serial 2
8
9
AC_DEFUN([gl_UTIMENS],
6
AC_DEFUN([gl_UTIMENS],
10
[
7
[
11
  AC_LIBOBJ([utimens])
8
  AC_LIBOBJ([utimens])
12
9
13
  dnl Prerequisites of lib/utimens.c.
10
  dnl Prerequisites of lib/utimens.c.
14
  AC_REQUIRE([gl_FUNC_UTIMES])
11
  AC_REQUIRE([gl_FUNC_UTIMES])
15
  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
12
  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
16
  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
13
  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
17
  AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat])
14
  AC_CHECK_FUNCS_ONCE([futimes futimesat])
18
])
15
])

Return to bug 224483