fcrypt: fix Mac OS compile error
Mac OS does not provide utimensat (), so we have to work around with utimes ().
Fixes .
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
@@ -168,6 +169,23 @@ static int fcryptSaveMtime (Key * parentKey, struct stat * fileStat)
*/
static void fcryptRestoreMtime (Key * parentKey, struct stat * fileStat)
{
+#if defined(__APPLE__)
+ struct timeval times[2];
+
+ // atime - not changing
+ times[0].tv_sec = fileStat->st_atime;
+ times[0].tv_usec = fileStat->st_atimespec.tv_nsec;
+
+ // mtime
+ times[1].tv_sec = ELEKTRA_STAT_SECONDS ((*fileStat));
+ times[1].tv_usec = ELEKTRA_STAT_NANO_SECONDS ((*fileStat));
+
+ // restore mtime on parentKeyFd
+ if (utimes (keyString (parentKey), times) < 0)
+ {
+ ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_FCRYPT_FUTIMENS, parentKey, "Filename: %s", keyString (parentKey));
+ }
+#else
struct timespec times[2];
// atime - not changing
@@ -179,11 +197,11 @@ static void fcryptRestoreMtime (Key * parentKey, struct stat * fileStat)
times[1].tv_nsec = ELEKTRA_STAT_NANO_SECONDS ((*fileStat));
// restore mtime on parentKeyFd
- // if (futimens (fileDescriptor, times))
if (utimensat (AT_FDCWD, keyString (parentKey), times, 0))
{
ELEKTRA_ADD_WARNINGF (ELEKTRA_WARNING_FCRYPT_FUTIMENS, parentKey, "Filename: %s", keyString (parentKey));
}
+#endif
}
static int fcryptGpgCallAndCleanup (Key * parentKey, KeySet * pluginConfig, char ** argv, int argc, int tmpFileFd, char * tmpFile)
