aboutsummaryrefslogtreecommitdiff
path: root/src/lib9
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib9')
-rw-r--r--src/lib9/_p9dir.c12
-rw-r--r--src/lib9/date.c36
-rw-r--r--src/lib9/dirfwstat.c17
-rw-r--r--src/lib9/dirread.c26
-rw-r--r--src/lib9/dirwstat.c1
5 files changed, 67 insertions, 25 deletions
diff --git a/src/lib9/_p9dir.c b/src/lib9/_p9dir.c
index d94208cc..43752222 100644
--- a/src/lib9/_p9dir.c
+++ b/src/lib9/_p9dir.c
@@ -4,13 +4,19 @@
#include <sys/types.h>
#include <sys/stat.h>
-#ifdef _HAVEDISKLABEL
-#include <sys/disklabel.h>
-#endif
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
+#if defined(__FreeBSD__)
+#include <sys/disklabel.h>
+#define _HAVEDISKLABEL
+#endif
+
+#if !defined(__linux__) && !defined(__sun__)
+#define _HAVESTGEN
+#endif
+
int
_p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
{
diff --git a/src/lib9/date.c b/src/lib9/date.c
index 22ec6721..8ece0c68 100644
--- a/src/lib9/date.c
+++ b/src/lib9/date.c
@@ -1,18 +1,24 @@
#include <stdlib.h> /* setenv etc. */
#include <u.h>
+#define NOPLAN9DEFINES
#include <libc.h>
+#include <time.h>
-#undef gmtime
-#undef localtime
-#undef asctime
-#undef ctime
-#undef cputime
-#undef times
-#undef tm2sec
-#undef nsec
+#define _HAVETIMEGM 1
+#define _HAVETMZONE 1
+#define _HAVETMTZOFF 1
-#include <time.h>
+#if defined(__linux__)
+# undef _HAVETMZONE
+# undef _HAVETMTZOFF
+
+#elif defined(__sun__)
+# undef _HAVETIMEGM
+# undef _HAVETMZONE
+# undef _HAVETMTZOFF
+
+#endif
static Tm bigtm;
@@ -80,15 +86,17 @@ timegm(struct tm *tm)
{
time_t ret;
char *tz;
+ char *s;
tz = getenv("TZ");
- setenv("TZ", "", 1);
+ putenv("TZ=");
tzset();
ret = mktime(tm);
- if(tz)
- setenv("TZ", tz, 1);
- else
- unsetenv("TZ");
+ if(tz){
+ s = smprint("TZ=%s", tz);
+ if(s)
+ putenv(s);
+ }
return ret;
}
#endif
diff --git a/src/lib9/dirfwstat.c b/src/lib9/dirfwstat.c
index c7cf64d6..7144e7cd 100644
--- a/src/lib9/dirfwstat.c
+++ b/src/lib9/dirfwstat.c
@@ -1,22 +1,30 @@
#include <u.h>
-#define NOPLAN9DEFINES
#include <libc.h>
-
#include <sys/time.h>
-#if !defined(_HAVEFUTIMES) && defined(_HAVEFUTIMESAT)
+#if defined(__FreeBSD__) || defined(__APPLE__)
+/* do nothing -- futimes exists and is fine */
+
+#elif defined(__sun__)
+/* use futimesat */
static int
futimes(int fd, struct timeval *tv)
{
return futimesat(fd, 0, tv);
}
-#elif !defined(_HAVEFUTIMES)
+
+#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
@@ -25,6 +33,7 @@ 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;
diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
index ab9ec7f5..1e479fe4 100644
--- a/src/lib9/dirread.c
+++ b/src/lib9/dirread.c
@@ -6,19 +6,39 @@
extern int _p9dir(struct stat*, char*, Dir*, char**, char*);
-/* almost everyone has getdirentries, just use that */
+#if defined(__linux__)
static int
-mygetdents(int fd, char *buf, int n)
+mygetdents(int fd, struct dirent *buf, int n)
+{
+ ssize_t nn;
+ off_t off;
+
+ off = p9seek(fd, 0, 1);
+ nn = getdirentries(fd, (void*)buf, n, &off);
+ if(nn > 0)
+ p9seek(fd, off, 0);
+ return nn;
+}
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+static int
+mygetdents(int fd, struct dirent *buf, int n)
{
ssize_t nn;
long off;
off = p9seek(fd, 0, 1);
- nn = getdirentries(fd, buf, n, &off);
+ nn = getdirentries(fd, (void*)buf, n, &off);
if(nn > 0)
p9seek(fd, off, 0);
return nn;
}
+#elif defined(__sun__)
+static int
+mygetdents(int fd, struct dirent *buf, int n)
+{
+ return getdents(fd, (void*)buf, n);
+}
+#endif
static int
countde(char *p, int n)
diff --git a/src/lib9/dirwstat.c b/src/lib9/dirwstat.c
index d003ac83..6f351965 100644
--- a/src/lib9/dirwstat.c
+++ b/src/lib9/dirwstat.c
@@ -1,7 +1,6 @@
#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>
-
#include <sys/time.h>
#include <utime.h>