Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
linux: add futimes() fallback
The utimensat() syscall was added in 2.6.22. Add a fallback mode for
older kernels that uses utimes("/proc/self/fd/<fd>").

Fixes #687.
  • Loading branch information
bnoordhuis committed Jan 17, 2013
1 parent 629a59b commit 9d4a16e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/unix/fs.c
Expand Up @@ -113,12 +113,39 @@ static ssize_t uv__fs_futime(uv_fs_t* req) {
/* utimesat() has nanosecond resolution but we stick to microseconds
* for the sake of consistency with other platforms.
*/
static int no_utimesat;
struct timespec ts[2];
struct timeval tv[2];
char path[sizeof("/proc/self/fd/") + 3 * sizeof(int)];
int r;

if (no_utimesat)

This comment has been minimized.

Copy link
@indutny

indutny Jan 17, 2013

Contributor

Missing initialization?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Jan 17, 2013

Author Contributor

It's static so it defaults to zero.

goto skip;

ts[0].tv_sec = req->atime;
ts[0].tv_nsec = (unsigned long)(req->atime * 1000000) % 1000000 * 1000;
ts[1].tv_sec = req->mtime;
ts[1].tv_nsec = (unsigned long)(req->mtime * 1000000) % 1000000 * 1000;
return uv__utimesat(req->file, NULL, ts, 0);

r = uv__utimesat(req->file, NULL, ts, 0);
if (r == 0)
return r;

if (errno != ENOSYS)
return r;

no_utimesat = 1;

skip:

tv[0].tv_sec = req->atime;
tv[0].tv_usec = (unsigned long)(req->atime * 1000000) % 1000000;
tv[1].tv_sec = req->mtime;
tv[1].tv_usec = (unsigned long)(req->mtime * 1000000) % 1000000;
snprintf(path, sizeof(path), "/proc/self/fd/%d", (int) req->file);

return utimes(path, tv);

#elif defined(__APPLE__) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
Expand Down

1 comment on commit 9d4a16e

@indutny
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, lgtm

Please sign in to comment.