plan9port/src/lib9/dirfwstat.c
Dan Cross fa325e9b42 Trivial changes: whitespace and modes.
Remote whitespace at the ends of lines.
Remove blank lines from the ends of files.
Change modes on source files so that they
are not executable.

Signed-off-by: Dan Cross <cross@gajendra.net>
2020-01-10 14:54:30 +00:00

57 lines
1011 B
C

#define NOPLAN9DEFINES
#include <u.h>
#include <libc.h>
#include <sys/time.h>
#include <sys/stat.h>
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__linux__)
/* do nothing -- futimes exists and is fine */
#elif defined(__SunOS5_9__)
/* use futimesat */
static int
futimes(int fd, struct timeval *tv)
{
return futimesat(fd, 0, tv);
}
#else
/* provide dummy */
/* rename just in case -- linux provides an unusable one */
#undef futimes
#define futimes myfutimes
static int
futimes(int fd, struct timeval *tv)
{
werrstr("futimes not available");
return -1;
}
#endif
int
dirfwstat(int fd, Dir *dir)
{
int ret;
struct timeval tv[2];
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;
}
if(~dir->length != 0){
if(ftruncate(fd, dir->length) < 0)
ret = -1;
}
return ret;
}