Blob


1 #define NOPLAN9DEFINES
2 #include <u.h>
3 #include <libc.h>
4 #include <sys/time.h>
5 #include <sys/stat.h>
7 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__linux__)
8 /* do nothing -- futimes exists and is fine */
10 #elif defined(__SunOS5_9__)
11 /* use futimesat */
12 static int
13 futimes(int fd, struct timeval *tv)
14 {
15 return futimesat(fd, 0, tv);
16 }
18 #else
19 /* provide dummy */
20 /* rename just in case -- linux provides an unusable one */
21 #undef futimes
22 #define futimes myfutimes
23 static int
24 futimes(int fd, struct timeval *tv)
25 {
26 werrstr("futimes not available");
27 return -1;
28 }
30 #endif
32 int
33 dirfwstat(int fd, Dir *dir)
34 {
35 int ret;
36 struct timeval tv[2];
38 ret = 0;
39 if(~dir->mode != 0){
40 if(fchmod(fd, dir->mode) < 0)
41 ret = -1;
42 }
43 if(~dir->mtime != 0){
44 tv[0].tv_sec = dir->mtime;
45 tv[0].tv_usec = 0;
46 tv[1].tv_sec = dir->mtime;
47 tv[1].tv_usec = 0;
48 if(futimes(fd, tv) < 0)
49 ret = -1;
50 }
51 if(~dir->length != 0){
52 if(ftruncate(fd, dir->length) < 0)
53 ret = -1;
54 }
55 return ret;
56 }