changed system-calls to avoid namespace pollution
This commit is contained in:
parent
67f0c95888
commit
90819543f6
16 changed files with 80 additions and 70 deletions
|
@ -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_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 */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdlib.h>
|
||||
#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)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <stdio.h>
|
||||
#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]);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdlib.h>
|
||||
#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) {
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
int unlink(const char *path);
|
||||
int _unlink(const char *path);
|
||||
|
||||
int
|
||||
remove(const char *filename) {
|
||||
return unlink(filename);
|
||||
return _unlink(filename);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
#include <stdlib.h>
|
||||
#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;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string.h>
|
||||
#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';
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string.h>
|
||||
#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';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue