Tweaks to build properly on Linux.

This commit is contained in:
rsc 2003-11-24 00:43:41 +00:00
parent 478ee9636f
commit d2c4ee9e48
9 changed files with 70 additions and 26 deletions

View file

@ -10,6 +10,13 @@
extern "C" { extern "C" {
#endif #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 <unistd.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -35,9 +42,10 @@ extern "C" {
#define _HAVETIMEGM 1 #define _HAVETIMEGM 1
#define _HAVETMZONE 1 #define _HAVETMZONE 1
#define _HAVETMTZOFF 1 #define _HAVETMTZOFF 1
#define _HAVETIMEZONEINT 1
#define _HAVEFUTIMESAT 1 #define _HAVEFUTIMESAT 1
#define _HAVEFUTIMES 1 #define _HAVEFUTIMES 1
#define _HAVEGETDENTS 1
#define _HAVEGETDIRENTRIES 1
typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
@ -48,6 +56,11 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
# undef _NEEDUINT # undef _NEEDUINT
# undef _NEEDULONG # undef _NEEDULONG
# endif # endif
# undef _HAVESTGEN
# undef _HAVETMZONE
# undef _HAVETMTZOFF
# undef _HAVEFUTIMESAT
# undef _HAVEGETDENTS
#endif #endif
#if defined(__sun__) #if defined(__sun__)
# include <sys/types.h> # include <sys/types.h>
@ -480,6 +493,7 @@ extern long time(long*);
#define getenv p9getenv #define getenv p9getenv
#define getwd p9getwd #define getwd p9getwd
#define longjmp p9longjmp #define longjmp p9longjmp
#undef setjmp
#define setjmp p9setjmp #define setjmp p9setjmp
#define notejmp p9notejmp #define notejmp p9notejmp
#define jmp_buf p9jmp_buf #define jmp_buf p9jmp_buf

View file

@ -81,23 +81,12 @@ main(int argc, char **argv)
int int
opentemp(char *template, int mode, long perm) opentemp(char *template, int mode, long perm)
{ {
int fd, i; int fd;
char *p;
p = strdup(template); fd = mkstemp(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);
}
if(fd < 0) if(fd < 0)
sysfatal("could not create temporary file"); sysfatal("could not create temporary file");
strcpy(template, p); fchmod(fd, perm);
free(p);
return fd; return fd;
} }

View file

@ -18,7 +18,9 @@ static struct {
SIGILL, "sys: trap: illegal instruction", SIGILL, "sys: trap: illegal instruction",
SIGTRAP, "sys: trace trap", SIGTRAP, "sys: trace trap",
SIGABRT, "sys: abort", SIGABRT, "sys: abort",
#ifdef SIGEMT
SIGEMT, "sys: emulate instruction executed", SIGEMT, "sys: emulate instruction executed",
#endif
SIGFPE, "sys: fp: trap", SIGFPE, "sys: fp: trap",
SIGKILL, "sys: kill", SIGKILL, "sys: kill",
SIGBUS, "sys: bus error", SIGBUS, "sys: bus error",

View file

@ -1,3 +1,5 @@
#include <stdlib.h> /* setenv etc. */
#include <u.h> #include <u.h>
#include <libc.h> #include <libc.h>
@ -72,11 +74,22 @@ p9localtime(long t)
return &bigtm; return &bigtm;
} }
#if !defined(_HAVETIMEGM) && defined(_HAVETIMEZONEINT) #if !defined(_HAVETIMEGM)
static long static time_t
timegm(struct tm *tm) 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 #endif

View file

@ -10,6 +10,13 @@ futimes(int fd, struct timeval *tv)
{ {
return futimesat(fd, 0, tv); return futimesat(fd, 0, tv);
} }
#elif !defined(_HAVEFUTIMES)
static int
futimes(int fd, struct timeval *tv)
{
werrstr("futimes not available");
return -1;
}
#endif #endif
int int

View file

@ -11,6 +11,21 @@
extern int _p9dir(struct stat*, char*, Dir*, char**, char*); 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 static int
countde(char *p, int n) countde(char *p, int n)
{ {

View file

@ -3,19 +3,18 @@
#include <libc.h> #include <libc.h>
#include <sys/time.h> #include <sys/time.h>
#include <utime.h>
int int
dirwstat(char *file, Dir *dir) dirwstat(char *file, Dir *dir)
{ {
struct timeval tv[2]; struct utimbuf ub;
/* BUG handle more */ /* BUG handle more */
if(dir->mtime == ~0ULL) if(dir->mtime == ~0ULL)
return 0; return 0;
tv[0].tv_sec = dir->mtime; ub.actime = dir->mtime;
tv[0].tv_usec = 0; ub.modtime = dir->mtime;
tv[1].tv_sec = dir->mtime; return utime(file, &ub);
tv[1].tv_usec = 0;
return utimes(file, tv);
} }

View file

@ -14,7 +14,9 @@ static int sigs[] = {
SIGILL, SIGILL,
SIGTRAP, SIGTRAP,
SIGABRT, SIGABRT,
#ifdef SIGEMT
SIGEMT, SIGEMT,
#endif
SIGFPE, SIGFPE,
SIGBUS, SIGBUS,
SIGSEGV, SIGSEGV,
@ -30,6 +32,9 @@ static int sigs[] = {
SIGVTALRM, SIGVTALRM,
SIGUSR1, SIGUSR1,
SIGUSR2, SIGUSR2,
#ifdef SIGINFO
SIGINFO,
#endif
}; };
static void (*notifyf)(void*, char*); static void (*notifyf)(void*, char*);

View file

@ -1,9 +1,9 @@
#include <signal.h>
#include <u.h> #include <u.h>
#define _NO9DEFINES_ #define _NO9DEFINES_
#include <libc.h> #include <libc.h>
#include <signal.h>
extern int _p9strsig(char*); extern int _p9strsig(char*);