plan9port/src/lib9/dirfwstat.c

54 lines
913 B
C
Raw Normal View History

2003-11-25 02:22:49 +00:00
#define NOPLAN9DEFINES
2003-11-23 18:12:54 +00:00
#include <u.h>
#include <libc.h>
#include <sys/time.h>
2003-11-25 02:22:49 +00:00
#include <sys/stat.h>
2003-11-23 18:12:54 +00:00
2005-07-21 18:29:04 +00:00
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
2003-11-25 02:11:11 +00:00
/* do nothing -- futimes exists and is fine */
2004-03-26 05:06:22 +00:00
#elif defined(__SunOS5_9__)
2003-11-25 02:11:11 +00:00
/* use futimesat */
2003-11-23 19:49:17 +00:00
static int
futimes(int fd, struct timeval *tv)
{
return futimesat(fd, 0, tv);
}
2003-11-25 02:11:11 +00:00
#else
/* provide dummy */
/* rename just in case -- linux provides an unusable one */
#undef futimes
#define futimes myfutimes
2003-11-24 00:43:41 +00:00
static int
futimes(int fd, struct timeval *tv)
{
werrstr("futimes not available");
return -1;
}
2003-11-25 02:11:11 +00:00
2003-11-23 19:49:17 +00:00
#endif
2003-11-23 18:12:54 +00:00
int
dirfwstat(int fd, Dir *dir)
{
int ret;
2003-11-23 18:12:54 +00:00
struct timeval tv[2];
2003-11-25 02:11:11 +00:00
ret = 0;
if(~dir->mode != 0){
if(fchmod(fd, dir->mode) < 0)
ret = -1;
}
if(~dir->mtime != 0){
tv[0].tv_sec = dir->mtime;
tv[0].tv_usec = 0;
tv[1].tv_sec = dir->mtime;
tv[1].tv_usec = 0;
if(futimes(fd, tv) < 0)
ret = -1;
}
return ret;
2003-11-23 18:12:54 +00:00
}
2003-11-23 19:49:17 +00:00