From 90819543f6a07ce4a5b389a53c7c6f6d97b2d995 Mon Sep 17 00:00:00 2001 From: eck Date: Mon, 22 Jan 1990 11:13:26 +0000 Subject: [PATCH] changed system-calls to avoid namespace pollution --- lang/cem/libcc.ansi/stdio/doscan.c | 14 +++++----- lang/cem/libcc.ansi/stdio/fclose.c | 4 +-- lang/cem/libcc.ansi/stdio/fflush.c | 40 +++++++++++++++++----------- lang/cem/libcc.ansi/stdio/fillbuf.c | 4 +-- lang/cem/libcc.ansi/stdio/flushbuf.c | 24 ++++++++--------- lang/cem/libcc.ansi/stdio/fopen.c | 12 ++++----- lang/cem/libcc.ansi/stdio/freopen.c | 12 ++++----- lang/cem/libcc.ansi/stdio/fseek.c | 7 +++-- lang/cem/libcc.ansi/stdio/ftell.c | 4 +-- lang/cem/libcc.ansi/stdio/isatty.c | 8 +++--- lang/cem/libcc.ansi/stdio/loc_incl.h | 1 + lang/cem/libcc.ansi/stdio/remove.c | 4 +-- lang/cem/libcc.ansi/stdio/rename.c | 4 +-- lang/cem/libcc.ansi/stdio/setvbuf.c | 4 +-- lang/cem/libcc.ansi/stdio/tmpfile.c | 4 +-- lang/cem/libcc.ansi/stdio/tmpnam.c | 4 +-- 16 files changed, 80 insertions(+), 70 deletions(-) diff --git a/lang/cem/libcc.ansi/stdio/doscan.c b/lang/cem/libcc.ansi/stdio/doscan.c index 169b6e02d..8ec2690fd 100644 --- a/lang/cem/libcc.ansi/stdio/doscan.c +++ b/lang/cem/libcc.ansi/stdio/doscan.c @@ -240,12 +240,14 @@ _doscan(register FILE *stream, const char *format, va_list ap) case 'n': if (ic != EOF) ungetc(ic, stream); nrchars--; - if (flags & FL_SHORT) - *va_arg(ap, short *) = (short) nrchars; - else if (flags & FL_LONG) - *va_arg(ap, long *) = (long) nrchars; - else - *va_arg(ap, int *) = (int) nrchars; + if (!(flags & FL_NOASSIGN)) { + if (flags & FL_SHORT) + *va_arg(ap, short *) = (short) nrchars; + else if (flags & FL_LONG) + *va_arg(ap, long *) = (long) nrchars; + else + *va_arg(ap, int *) = (int) nrchars; + } break; case 'b': /* binary */ case 'd': /* decimal */ diff --git a/lang/cem/libcc.ansi/stdio/fclose.c b/lang/cem/libcc.ansi/stdio/fclose.c index c22c3dd00..56bd0ac4a 100644 --- a/lang/cem/libcc.ansi/stdio/fclose.c +++ b/lang/cem/libcc.ansi/stdio/fclose.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -int close(int d); +int _close(int d); int fclose(FILE *fp) @@ -22,7 +22,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 275a8a6bb..b738c8ef9 100644 --- a/lang/cem/libcc.ansi/stdio/fflush.c +++ b/lang/cem/libcc.ansi/stdio/fflush.c @@ -6,7 +6,7 @@ #include #include "loc_incl.h" -int write(int d, const char *buf, int nbytes); +int _write(int d, const char *buf, int nbytes); int fflush(FILE *stream) @@ -21,38 +21,46 @@ fflush(FILE *stream) } if (!stream->_buf - || io_testflag(stream, _IONBF) - || !io_testflag(stream, _IOWRITE) - || !io_testflag(stream, _IOWRITING)) + || (!io_testflag(_IOREADING) + && !io_testflag(_IOWRITING))) return 0; + if (io_testflag(stream, _IOREADING)) { + (void) fseek(stream, 0L, SEEK_CUR); + return 0; + } else if (io_testflag(stream, _IONBF)) return 0; if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */ stream->_flags &= ~_IOWRITING; - /* - if (io_testflag(stream, _IOLBF)) - count = -stream->_count; - else count = stream->_bufsiz - stream->_count; - */ count = stream->_ptr - stream->_buf; stream->_ptr = stream->_buf; if ( count <= 0 ) return 0; - c1 = write(stream->_fd, (char *)stream->_buf, count); + if (io_testflag(stream, _IOAPPEND)) { + if (lseek(fileno(stream), 0L, SEEK_END) == -1) { + stream->_flags |= _IOERR; + return EOF; + } + } + c1 = _write(stream->_fd, (char *)stream->_buf, count); stream->_count = 0; - /* - if(stream != stderr) - fprintf(stderr,"written %d bytes :\"%.*s\"\n" - , c1, c1, stream->_buf); - */ - if ( count == c1 ) return 0; stream->_flags |= _IOERR; return EOF; } + +void +__cleanup(void) +{ + register int i; + + for(i= 0; i < FOPEN_MAX; i++) + if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING)) + (void) fflush(__iotab[i]); +} diff --git a/lang/cem/libcc.ansi/stdio/fillbuf.c b/lang/cem/libcc.ansi/stdio/fillbuf.c index 3f1d7356c..c6b811ec0 100644 --- a/lang/cem/libcc.ansi/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/stdio/fillbuf.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -int read(int d, char *buf, int nbytes); +int _read(int d, char *buf, int nbytes); int __fillbuf(register FILE *stream) @@ -47,7 +47,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 8baa4e060..9670ece09 100644 --- a/lang/cem/libcc.ansi/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/stdio/flushbuf.c @@ -9,15 +9,15 @@ #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 int (*_fflush)(FILE *stream); +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); int __flushbuf(int c, FILE * stream) { - _fflush = fflush; + _clean = __cleanup; if (fileno(stream) < 0) return EOF; if (!io_testflag(stream, _IOWRITE)) return EOF; if (io_testflag(stream, _IOREADING) && !feof(stream)) return EOF; @@ -26,7 +26,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; @@ -55,12 +55,12 @@ __flushbuf(int c, FILE * stream) stream->_count = 0; if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, 2) == -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; } @@ -69,12 +69,12 @@ __flushbuf(int c, FILE * stream) *stream->_ptr++ = c; if (c == '\n' || stream->_count == -stream->_bufsiz) { if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, 2) == -1) { + if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } } - if (write(fileno(stream), (char *)stream->_buf, + if (_write(fileno(stream), (char *)stream->_buf, -stream->_count) != -stream->_count) { stream->_flags |= _IOERR; return EOF; @@ -91,12 +91,12 @@ __flushbuf(int c, FILE * stream) if (count > 0) { if (io_testflag(stream, _IOAPPEND)) { - if (lseek(fileno(stream), 0L, 2) == -1) { + if (_lseek(fileno(stream), 0L, SEEK_END) == -1) { stream->_flags |= _IOERR; return EOF; } } - if (write(fileno(stream), (char *)stream->_buf, count) + if (_write(fileno(stream), (char *)stream->_buf, count) != count) { *(stream->_buf) = c; stream->_flags |= _IOERR; diff --git a/lang/cem/libcc.ansi/stdio/fopen.c b/lang/cem/libcc.ansi/stdio/fopen.c index 9c5a274df..bd1c1ef1b 100644 --- a/lang/cem/libcc.ansi/stdio/fopen.c +++ b/lang/cem/libcc.ansi/stdio/fopen.c @@ -35,10 +35,10 @@ #define O_TRUNC 0x020 #define O_APPEND 0x040 -int open(const char *path, int flags); -int creat(const char *path, int mode); +int _open(const char *path, int flags); +int _creat(const char *path, int mode); -int close(int d); +int _close(int d); FILE * fopen(const char *name, const char *mode) @@ -88,14 +88,14 @@ 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) && (flags & _IOWRITE))) - fd = creat(name, PMODE); + fd = _creat(name, PMODE); 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 ed5d16759..92111191e 100644 --- a/lang/cem/libcc.ansi/stdio/freopen.c +++ b/lang/cem/libcc.ansi/stdio/freopen.c @@ -20,9 +20,9 @@ #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); +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 +32,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': @@ -67,9 +67,9 @@ freopen(const char *name, const char *mode, FILE *stream) } if ((rwflags & O_TRUNC) - || (((fd = open(name, rwmode)) < 0) + || (((fd = _open(name, rwmode)) < 0) && (flags & _IOWRITE))) - fd = creat(name, PMODE); + fd = _creat(name, PMODE); if (fd < 0) { for( i = 0; i < FOPEN_MAX; i++) { diff --git a/lang/cem/libcc.ansi/stdio/fseek.c b/lang/cem/libcc.ansi/stdio/fseek.c index ea2649fd3..e386f75cc 100644 --- a/lang/cem/libcc.ansi/stdio/fseek.c +++ b/lang/cem/libcc.ansi/stdio/fseek.c @@ -13,7 +13,7 @@ #include -off_t lseek(int fildes, off_t offset, int whence); +off_t _lseek(int fildes, off_t offset, int whence); int fseek(FILE *stream, long int offset, int whence) @@ -29,14 +29,13 @@ fseek(FILE *stream, long int offset, int whence) && stream->_buf && !io_testflag(stream,_IONBF)) adjust = stream->_count; - pos = lseek(fileno(stream), offset - adjust, whence); stream->_count = 0; } else if (io_testflag(stream,_IOWRITING)) { fflush(stream); - pos = lseek(fileno(stream), offset, whence); } else /* neither reading nor writing. The buffer must be empty */ - pos = lseek(fileno(stream), offset, whence); + /* EMPTY */ ; + 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 eb77ba3e1..741c69945 100644 --- a/lang/cem/libcc.ansi/stdio/ftell.c +++ b/lang/cem/libcc.ansi/stdio/ftell.c @@ -13,7 +13,7 @@ #include -off_t lseek(int fildes, off_t offset, int whence); +off_t _lseek(int fildes, off_t offset, int whence); long ftell(FILE *stream) { @@ -28,7 +28,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/isatty.c b/lang/cem/libcc.ansi/stdio/isatty.c index 440226680..25b2501c2 100644 --- a/lang/cem/libcc.ansi/stdio/isatty.c +++ b/lang/cem/libcc.ansi/stdio/isatty.c @@ -1,11 +1,11 @@ /* - * isatty - check if a file descriptor is associated with a terminal + * _isatty - check if a file descriptor is associated with a terminal */ /* $Header$ */ -int gtty(int d, char *buf); +int _gtty(int d, char *buf); -int isatty(int d) +int _isatty(int d) { char buf[128]; /* not a sgttyb struct; it might not be large enough; @@ -13,5 +13,5 @@ int isatty(int d) where gtty is an ioctl(..., TCGETA, ...) */ - return gtty(d, buf) >= 0; + return _gtty(d, buf) >= 0; } diff --git a/lang/cem/libcc.ansi/stdio/loc_incl.h b/lang/cem/libcc.ansi/stdio/loc_incl.h index 4ac85e253..a1934d63f 100644 --- a/lang/cem/libcc.ansi/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/stdio/loc_incl.h @@ -12,6 +12,7 @@ int _doprnt(const char *format, va_list ap, FILE *stream); int _doscan(FILE * stream, const char *format, va_list ap); char *_i_compute(unsigned long val, int base, char *s, int nrdigits); +void __cleanup(void); FILE *popen(const char *command, const char *type); FILE *fdopen(int fd, const char *mode); diff --git a/lang/cem/libcc.ansi/stdio/remove.c b/lang/cem/libcc.ansi/stdio/remove.c index 3c05d8623..72c5780ea 100644 --- a/lang/cem/libcc.ansi/stdio/remove.c +++ b/lang/cem/libcc.ansi/stdio/remove.c @@ -5,9 +5,9 @@ #include -int unlink(const char *path); +int _unlink(const char *path); 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 5c8678173..c4da5a71e 100644 --- a/lang/cem/libcc.ansi/stdio/rename.c +++ b/lang/cem/libcc.ansi/stdio/rename.c @@ -5,11 +5,11 @@ #include -int link(const char *name1, const char *name2); +int _link(const char *name1, const char *name2); int rename(const char *old, const char *new) { - if (!link(old, new)) + if (!_link(old, new)) return remove(old); else return -1; } diff --git a/lang/cem/libcc.ansi/stdio/setvbuf.c b/lang/cem/libcc.ansi/stdio/setvbuf.c index 1cf30276a..34ef83b8e 100644 --- a/lang/cem/libcc.ansi/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/stdio/setvbuf.c @@ -7,14 +7,14 @@ #include #include "loc_incl.h" -extern int (*_fflush)(FILE *stream); +extern void (*_clean)(void); int setvbuf(register FILE *stream, char *buf, int mode, size_t size) { int retval = 0; - _fflush = fflush; + _clean = __cleanup; if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF) return EOF; diff --git a/lang/cem/libcc.ansi/stdio/tmpfile.c b/lang/cem/libcc.ansi/stdio/tmpfile.c index e375bcc37..b53f16a53 100644 --- a/lang/cem/libcc.ansi/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/stdio/tmpfile.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -unsigned int getpid(void); +unsigned int _getpid(void); 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 2df293fc4..f6f9ddb49 100644 --- a/lang/cem/libcc.ansi/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/stdio/tmpnam.c @@ -7,7 +7,7 @@ #include #include "loc_incl.h" -unsigned int getpid(void); +unsigned int _getpid(void); 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'; } -- 2.34.1