tTweaks to build properly on Linux. - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d2c4ee9e488f6c94865cc2f4c874d025bc2ae0d2
 (DIR) parent 478ee9636fcfe3509d0a901d1250524a5c41d3a8
 (HTM) Author: rsc <devnull@localhost>
       Date:   Mon, 24 Nov 2003 00:43:41 +0000
       
       Tweaks to build properly on Linux.
       
       Diffstat:
         M include/lib9.h                      |      16 +++++++++++++++-
         M src/cmd/idiff.c                     |      19 ++++---------------
         M src/lib9/await.c                    |       2 ++
         M src/lib9/date.c                     |      19 ++++++++++++++++---
         M src/lib9/dirfwstat.c                |       7 +++++++
         M src/lib9/dirread.c                  |      15 +++++++++++++++
         M src/lib9/dirwstat.c                 |      11 +++++------
         M src/lib9/notify.c                   |       5 +++++
         M src/lib9/postnote.c                 |       4 ++--
       
       9 files changed, 71 insertions(+), 27 deletions(-)
       ---
 (DIR) diff --git a/include/lib9.h b/include/lib9.h
       t@@ -10,6 +10,13 @@
        extern "C" {
        #endif                                                                          
        
       +#define _BSD_SOURCE 1
       +#define _SVID_SOURCE 1
       +#define _XOPEN_SOURCE 1000
       +#define _XOPEN_SOURCE_EXTENDED 1
       +#define _LARGEFILE64_SOURCE 1
       +#define _FILE_OFFSET_BITS 64
       +
        #include <unistd.h>
        #include <string.h>
        #include <stdlib.h>
       t@@ -35,9 +42,10 @@ extern "C" {
        #define _HAVETIMEGM 1
        #define _HAVETMZONE 1
        #define _HAVETMTZOFF 1
       -#define _HAVETIMEZONEINT 1
        #define _HAVEFUTIMESAT 1
        #define _HAVEFUTIMES 1
       +#define _HAVEGETDENTS 1
       +#define _HAVEGETDIRENTRIES 1
        
        typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
        
       t@@ -48,6 +56,11 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
        #                undef _NEEDUINT
        #                undef _NEEDULONG
        #        endif
       +#        undef _HAVESTGEN
       +#        undef _HAVETMZONE
       +#        undef _HAVETMTZOFF
       +#        undef _HAVEFUTIMESAT
       +#        undef _HAVEGETDENTS
        #endif
        #if defined(__sun__)
        #        include <sys/types.h>
       t@@ -480,6 +493,7 @@ extern        long        time(long*);
        #define getenv                p9getenv
        #define        getwd                p9getwd
        #define        longjmp                p9longjmp
       +#undef  setjmp
        #define setjmp                p9setjmp
        #define notejmp                p9notejmp
        #define jmp_buf                p9jmp_buf
 (DIR) diff --git a/src/cmd/idiff.c b/src/cmd/idiff.c
       t@@ -81,23 +81,12 @@ main(int argc, char **argv)
        int
        opentemp(char *template, int mode, long perm)
        {
       -        int fd, i;
       -        char *p;        
       -
       -        p = strdup(template);
       -        if(p == nil)
       -                sysfatal("strdup out of memory");
       -        fd = -1;
       -        for(i=0; i<10; i++){
       -                mktemp(p);
       -                if(access(p, 0) < 0 && (fd=create(p, mode, perm)) >= 0)
       -                        break;
       -                strcpy(p, template);
       -        }
       +        int fd;
       +
       +        fd = mkstemp(template);
                if(fd < 0)
                        sysfatal("could not create temporary file");
       -        strcpy(template, p);
       -        free(p);
       +        fchmod(fd, perm);
        
                return fd;
        }
 (DIR) diff --git a/src/lib9/await.c b/src/lib9/await.c
       t@@ -18,7 +18,9 @@ static struct {
                SIGILL,                "sys: trap: illegal instruction",
                SIGTRAP,                "sys: trace trap",
                SIGABRT,                "sys: abort",
       +#ifdef SIGEMT
                SIGEMT,                "sys: emulate instruction executed",
       +#endif
                SIGFPE,                "sys: fp: trap",
                SIGKILL,                "sys: kill",
                SIGBUS,                "sys: bus error",
 (DIR) diff --git a/src/lib9/date.c b/src/lib9/date.c
       t@@ -1,3 +1,5 @@
       +#include <stdlib.h> /* setenv etc. */
       +
        #include <u.h>
        #include <libc.h>
        
       t@@ -72,11 +74,22 @@ p9localtime(long t)
                return &bigtm;
        }
        
       -#if !defined(_HAVETIMEGM) && defined(_HAVETIMEZONEINT)
       -static long
       +#if !defined(_HAVETIMEGM)
       +static time_t
        timegm(struct tm *tm)
        {
       -        return mktime(tm)-timezone;
       +        time_t ret;
       +        char *tz;
       +
       +        tz = getenv("TZ");
       +        setenv("TZ", "", 1);
       +        tzset();
       +        ret = mktime(tm);
       +        if(tz)
       +                setenv("TZ", tz, 1);
       +        else
       +                unsetenv("TZ");
       +        return ret;
        }
        #endif
        
 (DIR) diff --git a/src/lib9/dirfwstat.c b/src/lib9/dirfwstat.c
       t@@ -10,6 +10,13 @@ futimes(int fd, struct timeval *tv)
        {
                return futimesat(fd, 0, tv);
        }
       +#elif !defined(_HAVEFUTIMES)
       +static int
       +futimes(int fd, struct timeval *tv)
       +{
       +        werrstr("futimes not available");
       +        return -1;
       +}
        #endif
        
        int
 (DIR) diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
       t@@ -11,6 +11,21 @@
        
        extern int _p9dir(struct stat*, char*, Dir*, char**, char*);
        
       +#if !defined(_HAVEGETDENTS) && defined(_HAVEGETDIRENTRIES)
       +static int
       +getdents(int fd, char *buf, int n)
       +{
       +        ssize_t nn;
       +        off_t off;
       +
       +        off = seek(fd, 0, 1);
       +        nn = getdirentries(fd, buf, n, &off);
       +        if(nn > 0)
       +                seek(fd, off, 0);
       +        return nn;
       +}
       +#endif
       +
        static int
        countde(char *p, int n)
        {
 (DIR) diff --git a/src/lib9/dirwstat.c b/src/lib9/dirwstat.c
       t@@ -3,19 +3,18 @@
        #include <libc.h>
        
        #include <sys/time.h>
       +#include <utime.h>
        
        int
        dirwstat(char *file, Dir *dir)
        {
       -        struct timeval tv[2];
       +        struct utimbuf ub;
        
                /* BUG handle more */
                if(dir->mtime == ~0ULL)
                        return 0;
        
       -        tv[0].tv_sec = dir->mtime;
       -        tv[0].tv_usec = 0;
       -        tv[1].tv_sec = dir->mtime;
       -        tv[1].tv_usec = 0;
       -        return utimes(file, tv);
       +        ub.actime = dir->mtime;
       +        ub.modtime = dir->mtime;
       +        return utime(file, &ub);
        }
 (DIR) diff --git a/src/lib9/notify.c b/src/lib9/notify.c
       t@@ -14,7 +14,9 @@ static int sigs[] = {
                SIGILL,
                SIGTRAP,
                SIGABRT,
       +#ifdef SIGEMT
                SIGEMT,
       +#endif
                SIGFPE,
                SIGBUS,
                SIGSEGV,
       t@@ -30,6 +32,9 @@ static int sigs[] = {
                SIGVTALRM,
                SIGUSR1,
                SIGUSR2,
       +#ifdef SIGINFO
       +        SIGINFO,
       +#endif
        };
        
        static void (*notifyf)(void*, char*);
 (DIR) diff --git a/src/lib9/postnote.c b/src/lib9/postnote.c
       t@@ -1,9 +1,9 @@
       -#include <signal.h>
       -
        #include <u.h>
        #define _NO9DEFINES_
        #include <libc.h>
        
       +#include <signal.h>
       +
        
        extern int _p9strsig(char*);