changed system-calls to avoid namespace pollution

This commit is contained in:
eck 1990-01-22 11:44:21 +00:00
parent c6d87355db
commit c1b2a43ef5
11 changed files with 68 additions and 72 deletions

View file

@ -16,7 +16,7 @@ typedef void *pointer; /* (void *) if you have it */
#define NULL 0
#endif
int close(int d);
int _close(int d);
int
closedir(register DIR *dirp) /* stream from opendir */
@ -32,5 +32,5 @@ closedir(register DIR *dirp) /* stream from opendir */
fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
free( (pointer)dirp->dd_buf );
free( (pointer)dirp );
return close( fd );
return _close( fd );
}

View file

@ -7,8 +7,6 @@
#include <stdlib.h>
#include "../stdio/loc_incl.h"
int lseek(int d, int offset, int whence);
FILE *
fdopen(int fd, const char *mode)
{

View file

@ -97,8 +97,8 @@ extern int read();
extern int _getdents(); /* actual system call */
#endif
extern int fstat(int fd, struct stat *buf);
extern off_t lseek(int d, int offset, int whence);
extern int _fstat(int fd, struct stat *buf);
extern off_t _lseek(int d, int offset, int whence);
#ifndef DIRBLKSIZ
#define DIRBLKSIZ 4096 /* directory file read buffer size */
@ -209,7 +209,7 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
return -1;
}
if ( fstat( fildes, &statb ) != 0 )
if ( _fstat( fildes, &statb ) != 0 )
return -1; /* errno set by fstat() */
if ( !S_ISDIR( statb.st_mode ) )
@ -218,7 +218,7 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
return -1;
}
if ( (offset = lseek( fildes, (off_t)0, SEEK_CUR )) < 0 )
if ( (offset = _lseek( fildes, (off_t)0, SEEK_CUR )) < 0 )
return -1; /* errno set by lseek() */
#ifdef BFS /* no telling what remote hosts do */

View file

@ -19,9 +19,9 @@ typedef int off_t; /* see lseek(2) */
typedef long off_t;
#endif
off_t lseek(int d, off_t offset, int whence);
int read(int d, char *buf, int nbytes);
int close(int d);
off_t _lseek(int d, off_t offset, int whence);
int _read(int d, char *buf, int nbytes);
int _close(int d);
#define RBUFSIZE 1024
static char _gr_file[] = "/etc/group";
@ -37,7 +37,7 @@ int
setgrent(void)
{
if (_gfd >= 0)
lseek(_gfd, 0L, 0);
_lseek(_gfd, 0L, 0);
else
_gfd = open(_gr_file, O_RDONLY);
@ -49,7 +49,7 @@ int
endgrent(void)
{
if (_gfd >= 0)
close(_gfd);
_close(_gfd);
_gfd = -1;
_bufcnt = 0;
@ -65,7 +65,7 @@ getline(void)
_buf = _grbuf;
do {
if (--_bufcnt <= 0){
if ((_bufcnt = read(_gfd, _buffer, RBUFSIZE)) <= 0)
if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0)
return 0;
else
_pnt = _buffer;

View file

@ -8,13 +8,13 @@
#include <sgtty.h>
#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);
int close(int d);
int _open(const char *path, int flags);
int _write(int d, const char *buf, int nbytes);
int _read(int d, char *buf, int nbytes);
int _close(int d);
int stty(int, struct sgttyb *);
int gtty(int, struct sgttyb *);
int _stty(int, struct sgttyb *);
int _gtty(int, struct sgttyb *);
char *
getpass(const char *prompt)
@ -25,20 +25,20 @@ getpass(const char *prompt)
int fd;
void (*savesig)(int);
if ((fd = open("/dev/tty", O_RDONLY)) < 0) fd = 0;
if ((fd = _open("/dev/tty", O_RDONLY)) < 0) fd = 0;
savesig = signal(SIGINT, SIG_IGN);
write(2, prompt, strlen(prompt));
gtty(fd, &tty);
_write(2, prompt, strlen(prompt));
_gtty(fd, &tty);
ttysave = tty;
tty.sg_flags &= ~ECHO;
stty(fd, &tty);
i = read(fd, pwdbuf, 9);
_stty(fd, &tty);
i = _read(fd, pwdbuf, 9);
while (pwdbuf[i - 1] != '\n')
read(fd, &pwdbuf[i - 1], 1);
_read(fd, &pwdbuf[i - 1], 1);
pwdbuf[i - 1] = '\0';
stty(fd, &ttysave);
write(2, "\n", 1);
if (fd != 0) close(fd);
_stty(fd, &ttysave);
_write(2, "\n", 1);
if (fd != 0) _close(fd);
signal(SIGINT, savesig);
return(pwdbuf);
}

View file

@ -11,15 +11,11 @@
#include <sys/stat.h>
#include <dirent.h>
#ifdef BSD_SYSV
#define open _open /* avoid emulation overhead */
#endif
typedef void *pointer; /* (void *) if you have it */
extern int open(const char *path, int flags, int mode);
extern int close(int d);
extern int fstat(int fd, struct stat *buf);
extern int _open(const char *path, int flags, int mode);
extern int _close(int d);
extern int _fstat(int fd, struct stat *buf);
#ifndef NULL
#define NULL 0
@ -40,12 +36,12 @@ opendir(const char *dirname) /* name of directory */
register int fd; /* file descriptor for read */
struct stat sbuf; /* result of fstat() */
if ( (fd = open( dirname, O_RDONLY, 0 )) < 0 )
if ( (fd = _open( dirname, O_RDONLY, 0 )) < 0 )
return NULL; /* errno set by open() */
if ( fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) )
if ( _fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) )
{
(void)close( fd );
(void)_close( fd );
errno = ENOTDIR;
return NULL; /* not a directory */
}
@ -59,7 +55,7 @@ opendir(const char *dirname) /* name of directory */
if ( dirp != NULL )
free( (pointer)dirp );
(void)close( fd );
(void)_close( fd );
errno = serrno;
return NULL; /* not enough memory */
}

View file

@ -19,12 +19,12 @@ typedef int wait_arg;
#endif /* __BSD4_2 */
#include "../stdio/loc_incl.h"
int close(int d);
int dup2(int oldd, int newd); /* not present in System 5 */
int execl(const char *name, ... );
int fork(void);
int pipe(int fildes[2]);
int wait(wait_arg *status);
int _close(int d);
int _dup2(int oldd, int newd); /* not present in System 5 */
int _execl(const char *name, ... );
int _fork(void);
int _pipe(int fildes[2]);
int _wait(wait_arg *status);
void _exit(int status);
static int pids[20];
@ -37,25 +37,25 @@ popen(const char *command, const char *type)
int pid;
if (Xtype == 2 ||
pipe(piped) < 0 ||
(pid = fork()) < 0) return 0;
_pipe(piped) < 0 ||
(pid = _fork()) < 0) return 0;
if (pid == 0) {
/* child */
register int *p;
for (p = pids; p < &pids[ FOPEN_MAX]; p++) {
if (*p) close(p - pids);
if (*p) _close(p - pids);
}
close(piped[Xtype]);
dup2(piped[!Xtype], !Xtype);
close(piped[!Xtype]);
execl("/bin/sh", "sh", "-c", command, (char *) 0);
_close(piped[Xtype]);
_dup2(piped[!Xtype], !Xtype);
_close(piped[!Xtype]);
_execl("/bin/sh", "sh", "-c", command, (char *) 0);
_exit(127); /* like system() ??? */
}
pids[piped[Xtype]] = pid;
close(piped[!Xtype]);
_close(piped[!Xtype]);
return fdopen(piped[Xtype], type);
}
@ -75,7 +75,7 @@ pclose(FILE *stream)
void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN);
fclose(stream);
while ((wret = wait(&status)) != -1) {
while ((wret = _wait(&status)) != -1) {
if (wret == pids[fd]) break;
}
if (wret == -1) ret_val = -1;
@ -86,21 +86,23 @@ pclose(FILE *stream)
}
#if defined(__USG)
int
dup2(int oldd, int newd)
int _dup(int fildes);
static int
_dup2(int oldd, int newd)
{
int i = 0, fd, tmp;
int fdbuf[_NFILES];
/* ignore the error on the close() */
tmp = errno; (void) close(newd); errno = tmp;
while ((fd = dup(oldd)) != newd) {
tmp = errno; (void) _close(newd); errno = tmp;
while ((fd = _dup(oldd)) != newd) {
if (fd == -1) break;
fdbuf[i++] = fd;
}
tmp = errno;
while (--i >= 0) {
close(fdbuf[i]);
_close(fdbuf[i]);
}
errno = tmp;
return -(fd == -1);

View file

@ -13,7 +13,7 @@
#include <sys/types.h>
#include <dirent.h>
extern off_t lseek(int d, int offset, int whence);
extern off_t _lseek(int d, int offset, int whence);
#ifndef NULL
#define NULL 0
@ -33,5 +33,5 @@ rewinddir(register DIR *dirp)
}
dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
(void)lseek( dirp->dd_fd, (off_t)0, SEEK_SET ); /* may set errno */
(void)_lseek( dirp->dd_fd, (off_t)0, SEEK_SET ); /* may set errno */
}

View file

@ -15,7 +15,7 @@
#include <sys/types.h>
#include <dirent.h>
extern off_t lseek(int d, int offset, int whence);
extern off_t _lseek(int d, int offset, int whence);
#ifndef NULL
#define NULL 0
@ -97,7 +97,7 @@ seekdir(register DIR *dirp, register off_t loc)
dirp->dd_loc = dirp->dd_size = 0;
if ( lseek( dirp->dd_fd, (off_t)0, SEEK_SET )
if ( _lseek( dirp->dd_fd, (off_t)0, SEEK_SET )
!= 0
)
return; /* errno already set (EBADF) */

View file

@ -6,8 +6,8 @@
#include <signal.h>
#include <setjmp.h>
int alarm(int n);
void pause(void);
int _alarm(int n);
void _pause(void);
static jmp_buf setjmpbuf;
@ -27,10 +27,10 @@ sleep(int n)
if (n <= 0) return;
if (setjmp(setjmpbuf)) {
signal(SIGALRM, oldsig);
alarm(oldalarm);
_alarm(oldalarm);
return;
}
oldalarm = alarm(5000); /* Who cares how long, as long
oldalarm = _alarm(5000); /* Who cares how long, as long
* as it is long enough
*/
if (oldalarm > n) oldalarm -= n;
@ -39,9 +39,9 @@ sleep(int n)
oldalarm = 1;
}
oldsig = signal(SIGALRM, alfun);
alarm(n);
_alarm(n);
for (;;) {
/* allow for other handlers ... */
pause();
_pause();
}
}

View file

@ -12,7 +12,7 @@
#include <sys/types.h>
#include <dirent.h>
extern off_t lseek(int d, int offset, int whence);
extern off_t _lseek(int d, int offset, int whence);
#ifndef SEEK_CUR
#define SEEK_CUR 1
@ -30,5 +30,5 @@ telldir(register DIR *dirp) /* return offset of next entry */
if ( dirp->dd_loc < dirp->dd_size ) /* valid index */
return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
else /* beginning of next directory block */
return lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
return _lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
}