From 1c83baa7021eb0ae35753067431664f256155f18 Mon Sep 17 00:00:00 2001 From: dtrg Date: Sat, 21 Apr 2007 23:18:14 +0000 Subject: [PATCH] Adapted for ANSI C and our pseudo-Posix syscall interface. --- h/em_abs.h | 6 +++ h/pc_err.h | 7 +++ lang/cem/libcc.ansi/head_ac.e | 30 +----------- lang/cem/libcc.ansi/misc/environ.c | 20 ++------ lang/cem/libcc.ansi/misc/getpass.c | 3 +- lang/cem/libcc.ansi/stdio/fclose.c | 11 ++--- lang/cem/libcc.ansi/stdio/fflush.c | 16 +++---- lang/cem/libcc.ansi/stdio/fillbuf.c | 11 ++--- lang/cem/libcc.ansi/stdio/flushbuf.c | 24 ++++------ lang/cem/libcc.ansi/stdio/fopen.c | 42 +++++++--------- lang/cem/libcc.ansi/stdio/freopen.c | 29 ++++------- lang/cem/libcc.ansi/stdio/fseek.c | 17 ++----- lang/cem/libcc.ansi/stdio/ftell.c | 15 ++---- lang/cem/libcc.ansi/stdio/remove.c | 8 ++-- lang/cem/libcc.ansi/stdio/rename.c | 5 +- lang/cem/libcc.ansi/stdio/tmpfile.c | 12 ++--- lang/cem/libcc.ansi/stdio/tmpnam.c | 12 ++--- lang/cem/libcc.ansi/stdlib/atof.c | 2 +- lang/cem/libcc.ansi/stdlib/exit.c | 7 ++- lang/cem/libcc.ansi/stdlib/getenv.c | 7 ++- lang/cem/libcc.ansi/stdlib/malloc/mal.c | 5 +- lang/cem/libcc.ansi/stdlib/mblen.c | 2 +- lang/cem/libcc.ansi/time/clock.c | 5 -- lang/cem/libcc.ansi/time/ctime.c | 2 +- lang/cem/libcc.ansi/time/misc.c | 12 +---- lang/cem/libcc.ansi/time/time.c | 26 +++------- lang/m2/libm2/init.c | 64 ++++++++++++++++++++----- lang/pc/libpc/catch.c | 13 ++--- lang/pc/libpc/cls.c | 9 ++-- lang/pc/libpc/efl.c | 6 ++- lang/pc/libpc/incpt.c | 13 +++-- lang/pc/libpc/ini.c | 7 --- lang/pc/libpc/opn.c | 28 +++++------ lang/pc/libpc/outcpt.c | 13 +++-- lang/pc/libpc/perrno.c | 2 +- lang/pc/libpc/uread.c | 5 +- lang/pc/libpc/uwrite.c | 5 +- 37 files changed, 222 insertions(+), 279 deletions(-) diff --git a/h/em_abs.h b/h/em_abs.h index c810d7b34..da36fb416 100644 --- a/h/em_abs.h +++ b/h/em_abs.h @@ -6,6 +6,12 @@ #define LINO_AD 0 #define FILN_AD 4 +/* ERANGE conflicts with a symbol in the ANSI C library. */ + +#ifdef ERANGE +#undef ERANGE +#endif + #define LINO (*(int *)(_hol0()+LINO_AD)) #define FILN (*(char **)(_hol0()+FILN_AD)) diff --git a/h/pc_err.h b/h/pc_err.h index aa4520931..63566f6fc 100644 --- a/h/pc_err.h +++ b/h/pc_err.h @@ -3,6 +3,13 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ + +/* EBADF conflicts with the ANSI C definition. */ + +#ifdef EBADF +#undef EBADF +#endif + #define EARGC 64 #define EEXP 65 #define ELOG 66 diff --git a/lang/cem/libcc.ansi/head_ac.e b/lang/cem/libcc.ansi/head_ac.e index 66c4eb681..9a9d55228 100644 --- a/lang/cem/libcc.ansi/head_ac.e +++ b/lang/cem/libcc.ansi/head_ac.e @@ -21,9 +21,6 @@ exa environ exa _end - exa _penvp -_penvp - bss _EM_PSIZE,0,0 exp $_m_a_i_n pro $_m_a_i_n,0 @@ -31,31 +28,8 @@ _penvp sim ; ignored lal _EM_WSIZE+_EM_PSIZE loi _EM_PSIZE - lae _penvp - sti _EM_PSIZE -/* Now test if environ is our own environ, or some user defined environ. - * First test if environ < _end. This is done for separate I&D systems. - */ - lae environ - lae _end - cmp - zge *1 -/* Now environ < end, which means that we can derefence it without trouble - * on separate I&D systems. - */ - lae environ - loi 2 - loc 2 - loc _EM_WSIZE - cii - loc 21331 /* == 0x5353 */ - bne *1 -/* environ contains the magic value. Assume it's our own environ */ - lae _penvp - loi _EM_PSIZE lae environ sti _EM_PSIZE -1 #if __unix && ! (__em22 || __em24 || __em44) lpi $_ctch_ sig @@ -87,9 +61,9 @@ _penvp bra *3 1 loc 8 - cal $_getpid + cal $getpid lfr _EM_WSIZE - cal $_kill + cal $kill asp 2*_EM_WSIZE 3 lpi $_ctch_ diff --git a/lang/cem/libcc.ansi/misc/environ.c b/lang/cem/libcc.ansi/misc/environ.c index e36578b5d..fe4a90e2b 100644 --- a/lang/cem/libcc.ansi/misc/environ.c +++ b/lang/cem/libcc.ansi/misc/environ.c @@ -2,19 +2,9 @@ * environ.c - define the variable environ */ /* $Id$ */ -/* - * This file defines the variable environ and initializes it with a magic - * value. The C run-time start-off routine tests whether the variable - * environ is initialized with this value. If it is not, it is assumed - * that it is defined by the user. Only two bytes are tested, since we - * don't know the endian-ness and alignment restrictions of the machine. - * This means that the low-order two-bytes should be equal to the - * high-order two-bytes on machines with four-byte pointers. In fact, all - * the bytes in the pointer are the same, just in case. - */ -#if _EM_PSIZE==2 -char **environ = (char **) 0x5353; -#else -char **environ = (char **) 0x53535353; -#endif +#include + +/* Contains storage for the environ variable. */ + +char** environ; diff --git a/lang/cem/libcc.ansi/misc/getpass.c b/lang/cem/libcc.ansi/misc/getpass.c index 74e42ab5b..ec209f37f 100644 --- a/lang/cem/libcc.ansi/misc/getpass.c +++ b/lang/cem/libcc.ansi/misc/getpass.c @@ -3,11 +3,12 @@ */ /* $Id$ */ +#include #include #include #include +#include -#define O_RDONLY 0 int _open(const char *path, int flags); int _write(int d, const char *buf, int nbytes); int _read(int d, char *buf, int nbytes); diff --git a/lang/cem/libcc.ansi/stdio/fclose.c b/lang/cem/libcc.ansi/stdio/fclose.c index 4fc6d89f1..0003535a7 100644 --- a/lang/cem/libcc.ansi/stdio/fclose.c +++ b/lang/cem/libcc.ansi/stdio/fclose.c @@ -3,11 +3,10 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" - -int _close(int d); +#include +#include +#include +#include "loc_incl.h" int fclose(FILE *fp) @@ -22,7 +21,7 @@ fclose(FILE *fp) if (i >= FOPEN_MAX) return EOF; if (fflush(fp)) retval = EOF; - if (_close(fileno(fp))) retval = EOF; + if (close(fileno(fp))) retval = EOF; if ( io_testflag(fp,_IOMYBUF) && fp->_buf ) free((void *)fp->_buf); if (fp != stdin && fp != stdout && fp != stderr) diff --git a/lang/cem/libcc.ansi/stdio/fflush.c b/lang/cem/libcc.ansi/stdio/fflush.c index 54bfa656e..573764fd4 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -3,12 +3,10 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" - -int _write(int d, const char *buf, int nbytes); -off_t _lseek(int fildes, off_t offset, int whence); +#include +#include +#include +#include "loc_incl.h" int fflush(FILE *stream) @@ -32,7 +30,7 @@ fflush(FILE *stream) if (stream->_buf && !io_testflag(stream,_IONBF)) adjust = stream->_count; stream->_count = 0; - _lseek(fileno(stream), (off_t) adjust, SEEK_CUR); + lseek(fileno(stream), (off_t) adjust, SEEK_CUR); if (io_testflag(stream, _IOWRITE)) stream->_flags &= ~(_IOREADING | _IOWRITING); stream->_ptr = stream->_buf; @@ -49,12 +47,12 @@ fflush(FILE *stream) return 0; if (io_testflag(stream, _IOAPPEND)) { - if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } } - c1 = _write(stream->_fd, (char *)stream->_buf, count); + c1 = write(stream->_fd, (char *)stream->_buf, count); stream->_count = 0; diff --git a/lang/cem/libcc.ansi/stdio/fillbuf.c b/lang/cem/libcc.ansi/stdio/fillbuf.c index 39641589a..02abebc7c 100644 --- a/lang/cem/libcc.ansi/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/stdio/fillbuf.c @@ -3,11 +3,10 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" - -int _read(int d, char *buf, int nbytes); +#include +#include +#include +#include "loc_incl.h" int __fillbuf(register FILE *stream) @@ -53,7 +52,7 @@ __fillbuf(register FILE *stream) stream->_bufsiz = 1; } stream->_ptr = stream->_buf; - stream->_count = _read(stream->_fd, (char *)stream->_buf, stream->_bufsiz); + stream->_count = read(stream->_fd, (char *)stream->_buf, stream->_bufsiz); if (stream->_count <= 0){ if (stream->_count == 0) { diff --git a/lang/cem/libcc.ansi/stdio/flushbuf.c b/lang/cem/libcc.ansi/stdio/flushbuf.c index fbc5f0589..22340e2e3 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -3,15 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include "loc_incl.h" -#include - -off_t _lseek(int fildes, off_t offset, int whence); -int _write(int d, const char *buf, int nbytes); -int _isatty(int d); extern void (*_clean)(void); static int @@ -22,7 +18,7 @@ do_write(int d, char *buf, int nbytes) /* POSIX actually allows write() to return a positive value less than nbytes, so loop ... */ - while ((c = _write(d, buf, nbytes)) > 0 && c < nbytes) { + while ((c = write(d, buf, nbytes)) > 0 && c < nbytes) { nbytes -= c; buf += c; } @@ -41,7 +37,7 @@ __flushbuf(int c, FILE * stream) stream->_flags |= _IOWRITING; if (!io_testflag(stream, _IONBF)) { if (!stream->_buf) { - if (stream == stdout && _isatty(fileno(stdout))) { + if (stream == stdout && isatty(fileno(stdout))) { if (!(stream->_buf = (unsigned char *) malloc(BUFSIZ))) { stream->_flags |= _IONBF; @@ -71,12 +67,12 @@ __flushbuf(int c, FILE * stream) stream->_count = 0; if (io_testflag(stream, _IOAPPEND)) { - if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } } - if (_write(fileno(stream), &c1, 1) != 1) { + if (write(fileno(stream), &c1, 1) != 1) { stream->_flags |= _IOERR; return EOF; } @@ -91,7 +87,7 @@ __flushbuf(int c, FILE * stream) stream->_count = 0; if (io_testflag(stream, _IOAPPEND)) { - if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } @@ -110,7 +106,7 @@ __flushbuf(int c, FILE * stream) if (count > 0) { if (io_testflag(stream, _IOAPPEND)) { - if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } diff --git a/lang/cem/libcc.ansi/stdio/fopen.c b/lang/cem/libcc.ansi/stdio/fopen.c index 929be78ed..a0bd9f40c 100644 --- a/lang/cem/libcc.ansi/stdio/fopen.c +++ b/lang/cem/libcc.ansi/stdio/fopen.c @@ -3,18 +3,15 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include +#include +#include "loc_incl.h" #define PMODE 0666 -/* The next 3 defines are true in all UNIX systems known to me. - */ -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 - /* Since the O_CREAT flag is not available on all systems, we can't get it * from the standard library. Furthermore, even if we know that * contains such a flag, it's not sure whether it can be used, since we @@ -26,18 +23,13 @@ * Another problem is O_APPEND, for which the same holds. When "a" * open-mode is used, an lseek() to the end is done before every write() * system-call. - * - * The O_CREAT, O_TRUNC and O_APPEND given here, are only for convenience. - * They are not passed to open(), so the values don't have to match a value - * from the real world. It is enough when they are unique. + * + * FIXME dtrg: I'm not sure this is relevant any more. Implementing O_CREAT + * and O_APPEND ought to be the job of the syscall library, no? Besides, the + * code requires valid definitions. + * + * Remember to fix freopen.c if changing this. */ -#define O_CREAT 0x010 -#define O_TRUNC 0x020 -#define O_APPEND 0x040 - -int _open(const char *path, int flags); -int _creat(const char *path, int mode); -int _close(int d); FILE * fopen(const char *name, const char *mode) @@ -89,11 +81,11 @@ fopen(const char *name, const char *mode) * the file is opened for writing and the open() failed. */ if ((rwflags & O_TRUNC) - || (((fd = _open(name, rwmode)) < 0) + || (((fd = open(name, rwmode)) < 0) && (rwflags & O_CREAT))) { - if (((fd = _creat(name, PMODE)) > 0) && flags | _IOREAD) { - (void) _close(fd); - fd = _open(name, rwmode); + if (((fd = creat(name, PMODE)) > 0) && flags | _IOREAD) { + (void) close(fd); + fd = open(name, rwmode); } } @@ -101,7 +93,7 @@ fopen(const char *name, const char *mode) if (fd < 0) return (FILE *)NULL; if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) { - _close(fd); + close(fd); return (FILE *)NULL; } diff --git a/lang/cem/libcc.ansi/stdio/freopen.c b/lang/cem/libcc.ansi/stdio/freopen.c index fae00d4f3..b51acba83 100644 --- a/lang/cem/libcc.ansi/stdio/freopen.c +++ b/lang/cem/libcc.ansi/stdio/freopen.c @@ -3,26 +3,17 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" +#include +#include +#include +#include +#include "loc_incl.h" #define PMODE 0666 /* Do not "optimize" this file to use the open with O_CREAT if the file * does not exist. The reason is given in fopen.c. */ -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 - -#define O_CREAT 0x010 -#define O_TRUNC 0x020 -#define O_APPEND 0x040 - -int _open(const char *path, int flags); -int _creat(const char *path, int mode); -int _close(int d); FILE * freopen(const char *name, const char *mode, FILE *stream) @@ -32,7 +23,7 @@ freopen(const char *name, const char *mode, FILE *stream) int fd, flags = stream->_flags & (_IONBF | _IOFBF | _IOLBF | _IOMYBUF); (void) fflush(stream); /* ignore errors */ - (void) _close(fileno(stream)); + (void) close(fileno(stream)); switch(*mode++) { case 'r': @@ -69,11 +60,11 @@ freopen(const char *name, const char *mode, FILE *stream) } if ((rwflags & O_TRUNC) - || (((fd = _open(name, rwmode)) < 0) + || (((fd = open(name, rwmode)) < 0) && (rwflags & O_CREAT))) { - if (((fd = _creat(name, PMODE)) < 0) && flags | _IOREAD) { - (void) _close(fd); - fd = _open(name, rwmode); + if (((fd = creat(name, PMODE)) < 0) && flags | _IOREAD) { + (void) close(fd); + fd = open(name, rwmode); } } diff --git a/lang/cem/libcc.ansi/stdio/fseek.c b/lang/cem/libcc.ansi/stdio/fseek.c index afaa35621..83d7640a3 100644 --- a/lang/cem/libcc.ansi/stdio/fseek.c +++ b/lang/cem/libcc.ansi/stdio/fseek.c @@ -3,17 +3,10 @@ */ /* $Id$ */ -#include - -#if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0) -#error SEEK_* values are wrong -#endif - -#include "loc_incl.h" - -#include - -off_t _lseek(int fildes, off_t offset, int whence); +#include +#include +#include +#include "loc_incl.h" int fseek(FILE *stream, long int offset, int whence) @@ -35,7 +28,7 @@ fseek(FILE *stream, long int offset, int whence) } else /* neither reading nor writing. The buffer must be empty */ /* EMPTY */ ; - pos = _lseek(fileno(stream), offset - adjust, whence); + pos = lseek(fileno(stream), offset - adjust, whence); if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE)) stream->_flags &= ~(_IOREADING | _IOWRITING); diff --git a/lang/cem/libcc.ansi/stdio/ftell.c b/lang/cem/libcc.ansi/stdio/ftell.c index 5c234308e..54c266c38 100644 --- a/lang/cem/libcc.ansi/stdio/ftell.c +++ b/lang/cem/libcc.ansi/stdio/ftell.c @@ -3,18 +3,11 @@ */ /* $Id$ */ -#include - -#if (SEEK_CUR != 1) || (SEEK_SET != 0) || (SEEK_END != 2) -#error SEEK_* values are wrong -#endif - +#include +#include +#include #include "loc_incl.h" -#include - -off_t _lseek(int fildes, off_t offset, int whence); - long ftell(FILE *stream) { long result; @@ -28,7 +21,7 @@ long ftell(FILE *stream) adjust = stream->_ptr - stream->_buf; else adjust = 0; - result = _lseek(fileno(stream), 0, SEEK_CUR); + result = lseek(fileno(stream), 0, SEEK_CUR); if ( result == -1 ) return result; diff --git a/lang/cem/libcc.ansi/stdio/remove.c b/lang/cem/libcc.ansi/stdio/remove.c index 179cdb990..204c4a25d 100644 --- a/lang/cem/libcc.ansi/stdio/remove.c +++ b/lang/cem/libcc.ansi/stdio/remove.c @@ -3,11 +3,11 @@ */ /* $Id$ */ -#include - -int _unlink(const char *path); +#include +#include +#include int remove(const char *filename) { - return _unlink(filename); + return unlink(filename); } diff --git a/lang/cem/libcc.ansi/stdio/rename.c b/lang/cem/libcc.ansi/stdio/rename.c index 82d0ff34c..08c5ae85d 100644 --- a/lang/cem/libcc.ansi/stdio/rename.c +++ b/lang/cem/libcc.ansi/stdio/rename.c @@ -3,8 +3,9 @@ */ /* $Id$ */ -#if !defined(_POSIX_SOURCE) -#include +#include +#include +#include int _link(const char *name1, const char *name2); diff --git a/lang/cem/libcc.ansi/stdio/tmpfile.c b/lang/cem/libcc.ansi/stdio/tmpfile.c index b4282a808..19c91593d 100644 --- a/lang/cem/libcc.ansi/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/stdio/tmpfile.c @@ -3,11 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" - -unsigned int _getpid(void); +#include +#include +#include +#include +#include "loc_incl.h" FILE * tmpfile(void) { @@ -17,7 +17,7 @@ tmpfile(void) { if (!name) { name = name_buffer + strlen(name_buffer); - name = _i_compute(_getpid(), 10, name, 5); + name = _i_compute(getpid(), 10, name, 5); *name = '\0'; } diff --git a/lang/cem/libcc.ansi/stdio/tmpnam.c b/lang/cem/libcc.ansi/stdio/tmpnam.c index 1b86be67b..9c6bc6be5 100644 --- a/lang/cem/libcc.ansi/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/stdio/tmpnam.c @@ -3,11 +3,11 @@ */ /* $Id$ */ -#include -#include -#include "loc_incl.h" - -unsigned int _getpid(void); +#include +#include +#include +#include +#include "loc_incl.h" char * tmpnam(char *s) { @@ -17,7 +17,7 @@ tmpnam(char *s) { if (!name) { name = name_buffer + strlen(name_buffer); - name = _i_compute(_getpid(), 10, name, 5); + name = _i_compute(getpid(), 10, name, 5); *name++ = '.'; *name = '\0'; } diff --git a/lang/cem/libcc.ansi/stdlib/atof.c b/lang/cem/libcc.ansi/stdlib/atof.c index 68e7bf7dd..834dc9242 100644 --- a/lang/cem/libcc.ansi/stdlib/atof.c +++ b/lang/cem/libcc.ansi/stdlib/atof.c @@ -8,7 +8,7 @@ #include double -atof(const char *nptr) +(atof)(const char *nptr) { double d; int e = errno; diff --git a/lang/cem/libcc.ansi/stdlib/exit.c b/lang/cem/libcc.ansi/stdlib/exit.c index 7a38fc503..16be42f4d 100644 --- a/lang/cem/libcc.ansi/stdlib/exit.c +++ b/lang/cem/libcc.ansi/stdlib/exit.c @@ -4,16 +4,15 @@ */ /* $Id$ */ -#include -#include +#include +#include +#include #define NEXITS 32 void (*__functab[NEXITS])(void); int __funccnt = 0; -extern void _exit(int); - /* only flush output buffers when necessary */ int (*_clean)(void) = NULL; diff --git a/lang/cem/libcc.ansi/stdlib/getenv.c b/lang/cem/libcc.ansi/stdlib/getenv.c index 3a7500170..01b887a1d 100644 --- a/lang/cem/libcc.ansi/stdlib/getenv.c +++ b/lang/cem/libcc.ansi/stdlib/getenv.c @@ -4,14 +4,13 @@ */ /* $Id$ */ -#include - -extern const char **_penvp; +#include +#include char * getenv(const char *name) { - register const char **v = _penvp; + register char **v = environ; register const char *p, *q; if (v == NULL || name == NULL) diff --git a/lang/cem/libcc.ansi/stdlib/malloc/mal.c b/lang/cem/libcc.ansi/stdlib/malloc/mal.c index d305d40a7..d523c9ad1 100644 --- a/lang/cem/libcc.ansi/stdlib/malloc/mal.c +++ b/lang/cem/libcc.ansi/stdlib/malloc/mal.c @@ -23,11 +23,12 @@ #ifdef SYSTEM #include #define SBRK sys_break +extern void *SBRK(int incr); #else -#define SBRK _sbrk +#include +#define SBRK sbrk #define ILL_BREAK (void *)(-1) /* funny failure value */ #endif -extern void *SBRK(int incr); #ifdef STORE #define MAX_STORE 32 private do_free(mallink *ml), sell_out(void); diff --git a/lang/cem/libcc.ansi/stdlib/mblen.c b/lang/cem/libcc.ansi/stdlib/mblen.c index c4f842cbb..f3c54a540 100644 --- a/lang/cem/libcc.ansi/stdlib/mblen.c +++ b/lang/cem/libcc.ansi/stdlib/mblen.c @@ -10,7 +10,7 @@ #define CHAR_SHIFT 8 int -mblen(const char *s, size_t n) +(mblen)(const char *s, size_t n) { if (s == (const char *)NULL) return 0; /* no state dependent codings */ if (n <= 0) return 0; diff --git a/lang/cem/libcc.ansi/time/clock.c b/lang/cem/libcc.ansi/time/clock.c index dc7f0e239..3c7f81d37 100644 --- a/lang/cem/libcc.ansi/time/clock.c +++ b/lang/cem/libcc.ansi/time/clock.c @@ -7,11 +7,6 @@ #if defined(__BSD4_2) -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; - #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1 diff --git a/lang/cem/libcc.ansi/time/ctime.c b/lang/cem/libcc.ansi/time/ctime.c index 30e113a8c..f7e81b41f 100644 --- a/lang/cem/libcc.ansi/time/ctime.c +++ b/lang/cem/libcc.ansi/time/ctime.c @@ -6,7 +6,7 @@ #include char * -ctime(const time_t *timer) +(ctime)(const time_t *timer) { return asctime(localtime(timer)); } diff --git a/lang/cem/libcc.ansi/time/misc.c b/lang/cem/libcc.ansi/time/misc.c index d61860d61..00da98fa4 100644 --- a/lang/cem/libcc.ansi/time/misc.c +++ b/lang/cem/libcc.ansi/time/misc.c @@ -10,17 +10,7 @@ #if defined(__BSD4_2) -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -int _gettimeofday(struct timeval *tp, struct timezone *tzp); +extern int _gettimeofday(struct timeval *tp, struct timezone *tzp); #elif !defined(_POSIX_SOURCE) && !defined(__USG) #if !defined(_MINIX) /* MINIX has no ftime() */ diff --git a/lang/cem/libcc.ansi/time/time.c b/lang/cem/libcc.ansi/time/time.c index 5cc01f0aa..f4def4c98 100644 --- a/lang/cem/libcc.ansi/time/time.c +++ b/lang/cem/libcc.ansi/time/time.c @@ -3,34 +3,22 @@ */ /* $Id$ */ -#if defined(__BSD4_2) -#include -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; +#include +#include +#include +#include -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -int _gettimeofday(struct timeval *tp, struct timezone *tzp); +#ifndef ACKCONF_TIME_IS_A_SYSCALL time_t time(time_t *timer) { struct timeval tv; struct timezone tz; - _gettimeofday(&tv, &tz); + gettimeofday(&tv, &tz); if (timer) *timer = tv.tv_sec; return tv.tv_sec; } -#else -/* Assume time() is a system call */ /* ??? */ + #endif diff --git a/lang/m2/libm2/init.c b/lang/m2/libm2/init.c index bf966fae9..c9fe9fbf4 100644 --- a/lang/m2/libm2/init.c +++ b/lang/m2/libm2/init.c @@ -13,23 +13,61 @@ #include #include +static const char signals_list[] = { +#ifdef SIGHUP + SIGHUP, +#endif +#ifdef SIGINT + SIGINT, +#endif +#ifdef SIGQUIT + SIGQUIT, +#endif +#ifdef SIGTRAP + SIGTRAP, +#endif +#ifdef SIGIOT + SIGIOT, +#endif +#ifdef SIGEMT + SIGEMT, +#endif +#ifdef SIGFPE + SIGFPE, +#endif +#ifdef SIGBUS + SIGBUS, +#endif +#ifdef SIGSEGV + SIGSEGV, +#endif +#ifdef SIGPIPE + SIGPIPE, +#endif +#ifdef SIGALRM + SIGALRM, +#endif +#ifdef SIGTERM + SIGTERM, +#endif + -1 +}; + /* map unix signals onto EM traps */ -init() +void init(void) { - sigtrp(M2_UNIXSIG, SIGHUP); - sigtrp(M2_UNIXSIG, SIGINT); - sigtrp(M2_UNIXSIG, SIGQUIT); + const char* p = signals_list; + do { + int i = *p++; + if (i == -1) + break; + sigtrp(M2_UNIXSIG, i); + } while (1); + sigtrp(EILLINS, SIGILL); - sigtrp(M2_UNIXSIG, SIGTRAP); - sigtrp(M2_UNIXSIG, SIGIOT); - sigtrp(M2_UNIXSIG, SIGEMT); - sigtrp(M2_UNIXSIG, SIGFPE); - sigtrp(M2_UNIXSIG, SIGBUS); - sigtrp(M2_UNIXSIG, SIGSEGV); +#ifdef SIGSYS sigtrp(EBADMON, SIGSYS); - sigtrp(M2_UNIXSIG, SIGPIPE); - sigtrp(M2_UNIXSIG, SIGALRM); - sigtrp(M2_UNIXSIG, SIGTERM); +#endif } #if defined(__em22) || defined(__em24) || defined(__em44) killbss() diff --git a/lang/pc/libpc/catch.c b/lang/pc/libpc/catch.c index 5396b4cac..4be454d0b 100644 --- a/lang/pc/libpc/catch.c +++ b/lang/pc/libpc/catch.c @@ -16,9 +16,12 @@ * */ -#include -#include -#include +#include +#include +#include +#include +#include +#include /* to make it easier to patch ... */ extern struct file *_curfil; @@ -85,8 +88,6 @@ extern char **_penvp; extern char *_hol0(); extern _trp(); -extern _exit(); -extern int _write(); _catch(erno) unsigned erno; { register struct errm *ep = &errors[0]; @@ -145,7 +146,7 @@ _catch(erno) unsigned erno; { p = q; while (*p) p++; - if (_write(2,q,(int)(p-q)) < 0) + if (write(2,q,(int)(p-q)) < 0) ; } _exit(erno+1); diff --git a/lang/pc/libpc/cls.c b/lang/pc/libpc/cls.c index 905f8c5b9..2dea744c1 100644 --- a/lang/pc/libpc/cls.c +++ b/lang/pc/libpc/cls.c @@ -18,14 +18,15 @@ /* Author: J.W. Stevenson */ -#include -#include +#include +#include +#include +#include extern struct file *_curfil; extern _trp(); extern _flush(); extern _outcpt(); -extern int _close(); _xcls(f) struct file *f; { @@ -61,7 +62,7 @@ _cls(f) struct file *f; { return; #endif _xcls(f); - if (_close(f->ufd) != 0) + if (close(f->ufd) != 0) _trp(ECLOSE); f->flags = 0; } diff --git a/lang/pc/libpc/efl.c b/lang/pc/libpc/efl.c index cb4223b66..313ac0ffc 100644 --- a/lang/pc/libpc/efl.c +++ b/lang/pc/libpc/efl.c @@ -18,8 +18,10 @@ /* Author: J.W. Stevenson */ -#include -#include +#include +#include +#include +#include extern struct file *_curfil; extern _trp(); diff --git a/lang/pc/libpc/incpt.c b/lang/pc/libpc/incpt.c index 95aaf9864..67df941e8 100644 --- a/lang/pc/libpc/incpt.c +++ b/lang/pc/libpc/incpt.c @@ -18,14 +18,13 @@ /* Author: J.W. Stevenson */ -#include -#include +#include +#include +#include +#include +#include -#define EINTR 4 - -extern int errno; extern _trp(); -extern int _read(); _incpt(f) struct file *f; { @@ -40,7 +39,7 @@ _incpt(f) struct file *f; { if (f->count == 0) { f->ptr = f->bufadr; for(;;) { - f->count=_read(f->ufd,f->bufadr,f->buflen); + f->count=read(f->ufd,f->bufadr,f->buflen); if ( f->count<0 ) { if (errno != EINTR) _trp(EREAD) ; continue ; diff --git a/lang/pc/libpc/ini.c b/lang/pc/libpc/ini.c index bf25cbbf3..358224690 100644 --- a/lang/pc/libpc/ini.c +++ b/lang/pc/libpc/ini.c @@ -23,9 +23,6 @@ extern (*_sig())(); extern _catch(); -#ifndef CPM -extern int _gtty(); -#endif struct file **_extfl; int _extflc; /* number of external files */ @@ -63,11 +60,7 @@ _ini(args,c,p,mainlb) char *args,*mainlb; int c; struct file **p; { f->fname = "OUTPUT"; f->ufd = 1; f->size = 1; -#ifdef CPM f->count = 1; -#else - f->count = (_gtty(1,buf) >= 0 ? 1 : PC_BUFLEN); -#endif f->buflen = f->count; } } diff --git a/lang/pc/libpc/opn.c b/lang/pc/libpc/opn.c index 83b9ba49f..e28e3edb9 100644 --- a/lang/pc/libpc/opn.c +++ b/lang/pc/libpc/opn.c @@ -18,8 +18,10 @@ /* Author: J.W. Stevenson */ -#include -#include +#include +#include +#include +#include extern struct file **_extfl; extern int _extflc; @@ -31,33 +33,27 @@ extern char **_penvp; extern _cls(); extern _xcls(); extern _trp(); -extern int _getpid(); -extern int _creat(); -extern int _open(); -extern int _close(); -extern int _unlink(); -extern long _lseek(); static int tmpfil() { static char namebuf[] = "/tmp/plf.xxxxx"; int i; char *p,*q; - i = _getpid(); + i = getpid(); p = namebuf; q = p + 13; do *q++ = (i & 07) + '0'; while (i >>= 3); *q = '\0'; - if ((i = _creat(p,0644)) < 0) - if ((i = _creat(p += 4,0644)) < 0) - if ((i = _creat(p += 5,0644)) < 0) + if ((i = creat(p,0644)) < 0) + if ((i = creat(p += 4,0644)) < 0) + if ((i = creat(p += 5,0644)) < 0) goto error; - if (_close(i) != 0) + if (close(i) != 0) goto error; - if ((i = _open(p,2)) < 0) + if ((i = open(p,2)) < 0) goto error; - if (_unlink(p) != 0) + if (remove(p) != 0) error: _trp(EREWR); return(i); } @@ -77,7 +73,7 @@ static int initfl(descr,sz,f) int descr; int sz; struct file *f; { f->fname = "LOCAL"; if ((descr & WRBIT) == 0 && (f->flags & 0377) == MAGIC) { _xcls(f); - if (_lseek(f->ufd,(long)0,0) == -1) + if (lseek(f->ufd,(long)0,0) == -1) _trp(ERESET); } else { _cls(f); diff --git a/lang/pc/libpc/outcpt.c b/lang/pc/libpc/outcpt.c index cc49f4beb..0d01f8034 100644 --- a/lang/pc/libpc/outcpt.c +++ b/lang/pc/libpc/outcpt.c @@ -18,14 +18,13 @@ /* Author: J.W. Stevenson */ -#include -#include +#include +#include +#include +#include +#include -#define EINTR 4 - -extern int errno; extern _trp(); -extern int _write(); _flush(f) struct file *f; { int i,n; @@ -35,7 +34,7 @@ _flush(f) struct file *f; { if (n <= 0) return; f->count = f->buflen; - if ((i = _write(f->ufd,f->bufadr,n)) < 0 && errno == EINTR) + if ((i = write(f->ufd,f->bufadr,n)) < 0 && errno == EINTR) return; if (i != n) _trp(EWRITE); diff --git a/lang/pc/libpc/perrno.c b/lang/pc/libpc/perrno.c index 186528ab5..ee1fde5f9 100644 --- a/lang/pc/libpc/perrno.c +++ b/lang/pc/libpc/perrno.c @@ -18,7 +18,7 @@ /* function perrno:integer; extern; */ -extern int errno; +#include int perrno() { return(errno); diff --git a/lang/pc/libpc/uread.c b/lang/pc/libpc/uread.c index 9089fdae1..77d3a91a2 100644 --- a/lang/pc/libpc/uread.c +++ b/lang/pc/libpc/uread.c @@ -18,8 +18,9 @@ /* function uread(fd:integer; var b:buf; n:integer):integer; */ -extern int _read(); +#include +#include int uread(fd,b,n) char *b; int fd,n; { - return(_read(fd,b,n)); + return(read(fd,b,n)); } diff --git a/lang/pc/libpc/uwrite.c b/lang/pc/libpc/uwrite.c index e9d17b361..8156f1b63 100644 --- a/lang/pc/libpc/uwrite.c +++ b/lang/pc/libpc/uwrite.c @@ -18,8 +18,9 @@ /* function uwrite(fd:integer; var b:buf; n:integer):integer; */ -extern int _write(); +#include +#include int uwrite(fd,b,n) char *b; int fd,n; { - return(_write(fd,b,n)); + return(write(fd,b,n)); }