-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OSX doesn’t like AT_FDCWD in it’s fcntl, but getcwd does the job. Also fixed an issue with absolute paths in the process.
- Loading branch information
Showing
4 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "futimesat.hpp" | ||
|
||
#ifdef __APPLE__ | ||
#include "futimesat_osx.icpp" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef __UTIMESAT_HPP__ | ||
#define __UTIMESAT_HPP__ | ||
|
||
#if __APPLE__ | ||
int | ||
_futimesat(int dirfd, const char* path, struct timeval *tvp); | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <err.h> | ||
#include <sys/errno.h> | ||
#include <sys/time.h> | ||
#include <sys/param.h> /* MAXPATHLEN */ | ||
|
||
|
||
int | ||
_futimesat(int fd, const char* path, struct timeval *tvp) { | ||
char fullpath[MAXPATHLEN]; | ||
|
||
// Handle absolute paths | ||
if(path[0] == '/') { | ||
return ::utimes(path,tvp); | ||
} | ||
|
||
// OS X 10.12 (at least) has an issue with using AT_FDCWD in this specific call. | ||
if (fd == AT_FDCWD) { | ||
if (getcwd((char*)fullpath, MAXPATHLEN) == NULL) { | ||
return -1; | ||
} | ||
} else { | ||
if (fcntl(fd,F_GETPATH,fullpath) < 0) { | ||
return -1; | ||
} | ||
} | ||
|
||
if (strlcat(fullpath, "/", MAXPATHLEN) > MAXPATHLEN || strlcat(fullpath, path, MAXPATHLEN) > MAXPATHLEN) { | ||
return (errno=ENAMETOOLONG,-1); | ||
} | ||
|
||
return ::utimes(fullpath,tvp);; | ||
} |