summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-misc.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-01-18 12:11:42 +1300
committerDarren Tucker <dtucker@dtucker.net>2019-01-18 10:16:11 +1100
commit091093d25802b87d3b2b09f2c88d9f33e1ae5562 (patch)
tree16a433e3317c60c7a245b70818726d0a85203b19 /openbsd-compat/bsd-misc.c
parent609644027dde1f82213699cb6599e584c7efcb75 (diff)
Add a minimal implementation of utimensat().
Some systems (eg older OS X) do not have utimensat, so provide minimal implementation in compat layer. Fixes build on at least El Capitan.
Diffstat (limited to 'openbsd-compat/bsd-misc.c')
-rw-r--r--openbsd-compat/bsd-misc.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 5d7540a70..4bae96548 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -25,6 +25,7 @@
25# include <sys/time.h> 25# include <sys/time.h>
26#endif 26#endif
27 27
28#include <fcntl.h>
28#include <string.h> 29#include <string.h>
29#include <signal.h> 30#include <signal.h>
30#include <stdlib.h> 31#include <stdlib.h>
@@ -117,6 +118,42 @@ int utimes(char *filename, struct timeval *tvp)
117} 118}
118#endif 119#endif
119 120
121#ifndef HAVE_UTIMENSAT
122/*
123 * A limited implementation of utimensat() that only implements the
124 * functionality used by OpenSSH, currently only AT_FDCWD and
125 * AT_SYMLINK_NOFOLLOW.
126 */
127int
128utimensat(int fd, const char *path, const struct timespec times[2],
129 int flag)
130{
131 struct timeval tv[2];
132 int ret, oflags = O_WRONLY;
133
134 tv[0].tv_sec = times[0].tv_sec;
135 tv[0].tv_usec = times[0].tv_nsec / 1000;
136 tv[1].tv_sec = times[1].tv_sec;
137 tv[1].tv_usec = times[1].tv_nsec / 1000;
138
139 if (fd != AT_FDCWD) {
140 errno = ENOSYS;
141 return -1;
142 }
143# ifndef HAVE_FUTIMES
144 return utimes(path, tv);
145# else
146 if (flag & AT_SYMLINK_NOFOLLOW)
147 oflags |= O_NOFOLLOW;
148 if ((fd = open(path, oflags)) == -1)
149 return -1;
150 ret = futimes(fd, tv);
151 close(fd);
152 return ret;
153# endif
154}
155#endif
156
120#ifndef HAVE_TRUNCATE 157#ifndef HAVE_TRUNCATE
121int truncate(const char *path, off_t length) 158int truncate(const char *path, off_t length)
122{ 159{