changed system-calls to avoid namespace pollution
This commit is contained in:
parent
c6d87355db
commit
c1b2a43ef5
11 changed files with 68 additions and 72 deletions
|
@ -16,7 +16,7 @@ typedef void *pointer; /* (void *) if you have it */
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int close(int d);
|
int _close(int d);
|
||||||
|
|
||||||
int
|
int
|
||||||
closedir(register DIR *dirp) /* stream from opendir */
|
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 */
|
fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
|
||||||
free( (pointer)dirp->dd_buf );
|
free( (pointer)dirp->dd_buf );
|
||||||
free( (pointer)dirp );
|
free( (pointer)dirp );
|
||||||
return close( fd );
|
return _close( fd );
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../stdio/loc_incl.h"
|
#include "../stdio/loc_incl.h"
|
||||||
|
|
||||||
int lseek(int d, int offset, int whence);
|
|
||||||
|
|
||||||
FILE *
|
FILE *
|
||||||
fdopen(int fd, const char *mode)
|
fdopen(int fd, const char *mode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -97,8 +97,8 @@ extern int read();
|
||||||
extern int _getdents(); /* actual system call */
|
extern int _getdents(); /* actual system call */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int fstat(int fd, struct stat *buf);
|
extern int _fstat(int fd, struct stat *buf);
|
||||||
extern off_t lseek(int d, int offset, int whence);
|
extern off_t _lseek(int d, int offset, int whence);
|
||||||
|
|
||||||
#ifndef DIRBLKSIZ
|
#ifndef DIRBLKSIZ
|
||||||
#define DIRBLKSIZ 4096 /* directory file read buffer size */
|
#define DIRBLKSIZ 4096 /* directory file read buffer size */
|
||||||
|
@ -209,7 +209,7 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fstat( fildes, &statb ) != 0 )
|
if ( _fstat( fildes, &statb ) != 0 )
|
||||||
return -1; /* errno set by fstat() */
|
return -1; /* errno set by fstat() */
|
||||||
|
|
||||||
if ( !S_ISDIR( statb.st_mode ) )
|
if ( !S_ISDIR( statb.st_mode ) )
|
||||||
|
@ -218,7 +218,7 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
|
||||||
return -1;
|
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() */
|
return -1; /* errno set by lseek() */
|
||||||
|
|
||||||
#ifdef BFS /* no telling what remote hosts do */
|
#ifdef BFS /* no telling what remote hosts do */
|
||||||
|
|
|
@ -19,9 +19,9 @@ typedef int off_t; /* see lseek(2) */
|
||||||
typedef long off_t;
|
typedef long off_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
off_t lseek(int d, off_t offset, int whence);
|
off_t _lseek(int d, off_t offset, int whence);
|
||||||
int read(int d, char *buf, int nbytes);
|
int _read(int d, char *buf, int nbytes);
|
||||||
int close(int d);
|
int _close(int d);
|
||||||
|
|
||||||
#define RBUFSIZE 1024
|
#define RBUFSIZE 1024
|
||||||
static char _gr_file[] = "/etc/group";
|
static char _gr_file[] = "/etc/group";
|
||||||
|
@ -37,7 +37,7 @@ int
|
||||||
setgrent(void)
|
setgrent(void)
|
||||||
{
|
{
|
||||||
if (_gfd >= 0)
|
if (_gfd >= 0)
|
||||||
lseek(_gfd, 0L, 0);
|
_lseek(_gfd, 0L, 0);
|
||||||
else
|
else
|
||||||
_gfd = open(_gr_file, O_RDONLY);
|
_gfd = open(_gr_file, O_RDONLY);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ int
|
||||||
endgrent(void)
|
endgrent(void)
|
||||||
{
|
{
|
||||||
if (_gfd >= 0)
|
if (_gfd >= 0)
|
||||||
close(_gfd);
|
_close(_gfd);
|
||||||
|
|
||||||
_gfd = -1;
|
_gfd = -1;
|
||||||
_bufcnt = 0;
|
_bufcnt = 0;
|
||||||
|
@ -65,7 +65,7 @@ getline(void)
|
||||||
_buf = _grbuf;
|
_buf = _grbuf;
|
||||||
do {
|
do {
|
||||||
if (--_bufcnt <= 0){
|
if (--_bufcnt <= 0){
|
||||||
if ((_bufcnt = read(_gfd, _buffer, RBUFSIZE)) <= 0)
|
if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
_pnt = _buffer;
|
_pnt = _buffer;
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
#include <sgtty.h>
|
#include <sgtty.h>
|
||||||
|
|
||||||
#define O_RDONLY 0
|
#define O_RDONLY 0
|
||||||
int open(const char *path, int flags);
|
int _open(const char *path, int flags);
|
||||||
int write(int d, const char *buf, int nbytes);
|
int _write(int d, const char *buf, int nbytes);
|
||||||
int read(int d, char *buf, int nbytes);
|
int _read(int d, char *buf, int nbytes);
|
||||||
int close(int d);
|
int _close(int d);
|
||||||
|
|
||||||
int stty(int, struct sgttyb *);
|
int _stty(int, struct sgttyb *);
|
||||||
int gtty(int, struct sgttyb *);
|
int _gtty(int, struct sgttyb *);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
getpass(const char *prompt)
|
getpass(const char *prompt)
|
||||||
|
@ -25,20 +25,20 @@ getpass(const char *prompt)
|
||||||
int fd;
|
int fd;
|
||||||
void (*savesig)(int);
|
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);
|
savesig = signal(SIGINT, SIG_IGN);
|
||||||
write(2, prompt, strlen(prompt));
|
_write(2, prompt, strlen(prompt));
|
||||||
gtty(fd, &tty);
|
_gtty(fd, &tty);
|
||||||
ttysave = tty;
|
ttysave = tty;
|
||||||
tty.sg_flags &= ~ECHO;
|
tty.sg_flags &= ~ECHO;
|
||||||
stty(fd, &tty);
|
_stty(fd, &tty);
|
||||||
i = read(fd, pwdbuf, 9);
|
i = _read(fd, pwdbuf, 9);
|
||||||
while (pwdbuf[i - 1] != '\n')
|
while (pwdbuf[i - 1] != '\n')
|
||||||
read(fd, &pwdbuf[i - 1], 1);
|
_read(fd, &pwdbuf[i - 1], 1);
|
||||||
pwdbuf[i - 1] = '\0';
|
pwdbuf[i - 1] = '\0';
|
||||||
stty(fd, &ttysave);
|
_stty(fd, &ttysave);
|
||||||
write(2, "\n", 1);
|
_write(2, "\n", 1);
|
||||||
if (fd != 0) close(fd);
|
if (fd != 0) _close(fd);
|
||||||
signal(SIGINT, savesig);
|
signal(SIGINT, savesig);
|
||||||
return(pwdbuf);
|
return(pwdbuf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,11 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
#ifdef BSD_SYSV
|
|
||||||
#define open _open /* avoid emulation overhead */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void *pointer; /* (void *) if you have it */
|
typedef void *pointer; /* (void *) if you have it */
|
||||||
|
|
||||||
extern int open(const char *path, int flags, int mode);
|
extern int _open(const char *path, int flags, int mode);
|
||||||
extern int close(int d);
|
extern int _close(int d);
|
||||||
extern int fstat(int fd, struct stat *buf);
|
extern int _fstat(int fd, struct stat *buf);
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
@ -40,12 +36,12 @@ opendir(const char *dirname) /* name of directory */
|
||||||
register int fd; /* file descriptor for read */
|
register int fd; /* file descriptor for read */
|
||||||
struct stat sbuf; /* result of fstat() */
|
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() */
|
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;
|
errno = ENOTDIR;
|
||||||
return NULL; /* not a directory */
|
return NULL; /* not a directory */
|
||||||
}
|
}
|
||||||
|
@ -59,7 +55,7 @@ opendir(const char *dirname) /* name of directory */
|
||||||
if ( dirp != NULL )
|
if ( dirp != NULL )
|
||||||
free( (pointer)dirp );
|
free( (pointer)dirp );
|
||||||
|
|
||||||
(void)close( fd );
|
(void)_close( fd );
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
return NULL; /* not enough memory */
|
return NULL; /* not enough memory */
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ typedef int wait_arg;
|
||||||
#endif /* __BSD4_2 */
|
#endif /* __BSD4_2 */
|
||||||
#include "../stdio/loc_incl.h"
|
#include "../stdio/loc_incl.h"
|
||||||
|
|
||||||
int close(int d);
|
int _close(int d);
|
||||||
int dup2(int oldd, int newd); /* not present in System 5 */
|
int _dup2(int oldd, int newd); /* not present in System 5 */
|
||||||
int execl(const char *name, ... );
|
int _execl(const char *name, ... );
|
||||||
int fork(void);
|
int _fork(void);
|
||||||
int pipe(int fildes[2]);
|
int _pipe(int fildes[2]);
|
||||||
int wait(wait_arg *status);
|
int _wait(wait_arg *status);
|
||||||
void _exit(int status);
|
void _exit(int status);
|
||||||
|
|
||||||
static int pids[20];
|
static int pids[20];
|
||||||
|
@ -37,25 +37,25 @@ popen(const char *command, const char *type)
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
if (Xtype == 2 ||
|
if (Xtype == 2 ||
|
||||||
pipe(piped) < 0 ||
|
_pipe(piped) < 0 ||
|
||||||
(pid = fork()) < 0) return 0;
|
(pid = _fork()) < 0) return 0;
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* child */
|
/* child */
|
||||||
register int *p;
|
register int *p;
|
||||||
|
|
||||||
for (p = pids; p < &pids[ FOPEN_MAX]; p++) {
|
for (p = pids; p < &pids[ FOPEN_MAX]; p++) {
|
||||||
if (*p) close(p - pids);
|
if (*p) _close(p - pids);
|
||||||
}
|
}
|
||||||
close(piped[Xtype]);
|
_close(piped[Xtype]);
|
||||||
dup2(piped[!Xtype], !Xtype);
|
_dup2(piped[!Xtype], !Xtype);
|
||||||
close(piped[!Xtype]);
|
_close(piped[!Xtype]);
|
||||||
execl("/bin/sh", "sh", "-c", command, (char *) 0);
|
_execl("/bin/sh", "sh", "-c", command, (char *) 0);
|
||||||
_exit(127); /* like system() ??? */
|
_exit(127); /* like system() ??? */
|
||||||
}
|
}
|
||||||
|
|
||||||
pids[piped[Xtype]] = pid;
|
pids[piped[Xtype]] = pid;
|
||||||
close(piped[!Xtype]);
|
_close(piped[!Xtype]);
|
||||||
return fdopen(piped[Xtype], type);
|
return fdopen(piped[Xtype], type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ pclose(FILE *stream)
|
||||||
void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN);
|
void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN);
|
||||||
|
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
while ((wret = wait(&status)) != -1) {
|
while ((wret = _wait(&status)) != -1) {
|
||||||
if (wret == pids[fd]) break;
|
if (wret == pids[fd]) break;
|
||||||
}
|
}
|
||||||
if (wret == -1) ret_val = -1;
|
if (wret == -1) ret_val = -1;
|
||||||
|
@ -86,21 +86,23 @@ pclose(FILE *stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__USG)
|
#if defined(__USG)
|
||||||
int
|
int _dup(int fildes);
|
||||||
dup2(int oldd, int newd)
|
|
||||||
|
static int
|
||||||
|
_dup2(int oldd, int newd)
|
||||||
{
|
{
|
||||||
int i = 0, fd, tmp;
|
int i = 0, fd, tmp;
|
||||||
int fdbuf[_NFILES];
|
int fdbuf[_NFILES];
|
||||||
|
|
||||||
/* ignore the error on the close() */
|
/* ignore the error on the close() */
|
||||||
tmp = errno; (void) close(newd); errno = tmp;
|
tmp = errno; (void) _close(newd); errno = tmp;
|
||||||
while ((fd = dup(oldd)) != newd) {
|
while ((fd = _dup(oldd)) != newd) {
|
||||||
if (fd == -1) break;
|
if (fd == -1) break;
|
||||||
fdbuf[i++] = fd;
|
fdbuf[i++] = fd;
|
||||||
}
|
}
|
||||||
tmp = errno;
|
tmp = errno;
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
close(fdbuf[i]);
|
_close(fdbuf[i]);
|
||||||
}
|
}
|
||||||
errno = tmp;
|
errno = tmp;
|
||||||
return -(fd == -1);
|
return -(fd == -1);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.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
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
@ -33,5 +33,5 @@ rewinddir(register DIR *dirp)
|
||||||
}
|
}
|
||||||
|
|
||||||
dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
|
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 */
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.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
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
@ -97,7 +97,7 @@ seekdir(register DIR *dirp, register off_t loc)
|
||||||
|
|
||||||
dirp->dd_loc = dirp->dd_size = 0;
|
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
|
!= 0
|
||||||
)
|
)
|
||||||
return; /* errno already set (EBADF) */
|
return; /* errno already set (EBADF) */
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
int alarm(int n);
|
int _alarm(int n);
|
||||||
void pause(void);
|
void _pause(void);
|
||||||
|
|
||||||
static jmp_buf setjmpbuf;
|
static jmp_buf setjmpbuf;
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ sleep(int n)
|
||||||
if (n <= 0) return;
|
if (n <= 0) return;
|
||||||
if (setjmp(setjmpbuf)) {
|
if (setjmp(setjmpbuf)) {
|
||||||
signal(SIGALRM, oldsig);
|
signal(SIGALRM, oldsig);
|
||||||
alarm(oldalarm);
|
_alarm(oldalarm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
oldalarm = alarm(5000); /* Who cares how long, as long
|
oldalarm = _alarm(5000); /* Who cares how long, as long
|
||||||
* as it is long enough
|
* as it is long enough
|
||||||
*/
|
*/
|
||||||
if (oldalarm > n) oldalarm -= n;
|
if (oldalarm > n) oldalarm -= n;
|
||||||
|
@ -39,9 +39,9 @@ sleep(int n)
|
||||||
oldalarm = 1;
|
oldalarm = 1;
|
||||||
}
|
}
|
||||||
oldsig = signal(SIGALRM, alfun);
|
oldsig = signal(SIGALRM, alfun);
|
||||||
alarm(n);
|
_alarm(n);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* allow for other handlers ... */
|
/* allow for other handlers ... */
|
||||||
pause();
|
_pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.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
|
#ifndef SEEK_CUR
|
||||||
#define SEEK_CUR 1
|
#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 */
|
if ( dirp->dd_loc < dirp->dd_size ) /* valid index */
|
||||||
return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
|
return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
|
||||||
else /* beginning of next directory block */
|
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 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue