Adapted for ANSI C and our pseudo-Posix syscall interface.

This commit is contained in:
dtrg 2007-04-21 23:18:14 +00:00
parent b66d66b597
commit 1c83baa702
37 changed files with 222 additions and 279 deletions

View file

@ -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))

View file

@ -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

View file

@ -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_

View file

@ -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 <unistd.h>
/* Contains storage for the environ variable. */
char** environ;

View file

@ -3,11 +3,12 @@
*/
/* $Id$ */
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sgtty.h>
#include <fcntl.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);

View file

@ -3,11 +3,10 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
int _close(int d);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#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)

View file

@ -3,12 +3,10 @@
*/
/* $Id$ */
#include <sys/types.h>
#include <stdio.h>
#include "loc_incl.h"
int _write(int d, const char *buf, int nbytes);
off_t _lseek(int fildes, off_t offset, int whence);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#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;

View file

@ -3,11 +3,10 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
int _read(int d, char *buf, int nbytes);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#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) {

View file

@ -3,15 +3,11 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "loc_incl.h"
#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 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;
}

View file

@ -3,18 +3,15 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#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 <fcntl.h>
* 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;
}

View file

@ -3,26 +3,17 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include "loc_incl.h"
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#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);
}
}

View file

@ -3,17 +3,10 @@
*/
/* $Id$ */
#include <stdio.h>
#if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)
#error SEEK_* values are wrong
#endif
#include "loc_incl.h"
#include <sys/types.h>
off_t _lseek(int fildes, off_t offset, int whence);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#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);

View file

@ -3,18 +3,11 @@
*/
/* $Id$ */
#include <stdio.h>
#if (SEEK_CUR != 1) || (SEEK_SET != 0) || (SEEK_END != 2)
#error SEEK_* values are wrong
#endif
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "loc_incl.h"
#include <sys/types.h>
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;

View file

@ -3,11 +3,11 @@
*/
/* $Id$ */
#include <stdio.h>
int _unlink(const char *path);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int
remove(const char *filename) {
return _unlink(filename);
return unlink(filename);
}

View file

@ -3,8 +3,9 @@
*/
/* $Id$ */
#if !defined(_POSIX_SOURCE)
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int _link(const char *name1, const char *name2);

View file

@ -3,11 +3,11 @@
*/
/* $Id$ */
#include <stdio.h>
#include <string.h>
#include "loc_incl.h"
unsigned int _getpid(void);
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#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';
}

View file

@ -3,11 +3,11 @@
*/
/* $Id$ */
#include <stdio.h>
#include <string.h>
#include "loc_incl.h"
unsigned int _getpid(void);
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#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';
}

View file

@ -8,7 +8,7 @@
#include <errno.h>
double
atof(const char *nptr)
(atof)(const char *nptr)
{
double d;
int e = errno;

View file

@ -4,16 +4,15 @@
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define NEXITS 32
void (*__functab[NEXITS])(void);
int __funccnt = 0;
extern void _exit(int);
/* only flush output buffers when necessary */
int (*_clean)(void) = NULL;

View file

@ -4,14 +4,13 @@
*/
/* $Id$ */
#include <stdlib.h>
extern const char **_penvp;
#include <stdlib.h>
#include <unistd.h>
char *
getenv(const char *name)
{
register const char **v = _penvp;
register char **v = environ;
register const char *p, *q;
if (v == NULL || name == NULL)

View file

@ -23,11 +23,12 @@
#ifdef SYSTEM
#include <system.h>
#define SBRK sys_break
extern void *SBRK(int incr);
#else
#define SBRK _sbrk
#include <unistd.h>
#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);

View file

@ -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;

View file

@ -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

View file

@ -6,7 +6,7 @@
#include <time.h>
char *
ctime(const time_t *timer)
(ctime)(const time_t *timer)
{
return asctime(localtime(timer));
}

View file

@ -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() */

View file

@ -3,34 +3,22 @@
*/
/* $Id$ */
#if defined(__BSD4_2)
#include <time.h>
/*
* Structure returned by gettimeofday(2) system call,
* and used in other calls.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <ack/config.h>
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

View file

@ -13,23 +13,61 @@
#include <em_abs.h>
#include <m2_traps.h>
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()

View file

@ -16,9 +16,12 @@
*
*/
#include <em_abs.h>
#include <pc_err.h>
#include <pc_file.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <em_abs.h>
#include <pc_err.h>
#include <pc_file.h>
/* 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);

View file

@ -18,14 +18,15 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <stdlib.h>
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
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;
}

View file

@ -18,8 +18,10 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <stdlib.h>
#include <errno.h>
#include <pc_file.h>
#include <pc_err.h>
extern struct file *_curfil;
extern _trp();

View file

@ -18,14 +18,13 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
#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 ;

View file

@ -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;
}
}

View file

@ -18,8 +18,10 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <stdlib.h>
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
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);

View file

@ -18,14 +18,13 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
#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);

View file

@ -18,7 +18,7 @@
/* function perrno:integer; extern; */
extern int errno;
#include <errno.h>
int perrno() {
return(errno);

View file

@ -18,8 +18,9 @@
/* function uread(fd:integer; var b:buf; n:integer):integer; */
extern int _read();
#include <stdlib.h>
#include <unistd.h>
int uread(fd,b,n) char *b; int fd,n; {
return(_read(fd,b,n));
return(read(fd,b,n));
}

View file

@ -18,8 +18,9 @@
/* function uwrite(fd:integer; var b:buf; n:integer):integer; */
extern int _write();
#include <stdlib.h>
#include <unistd.h>
int uwrite(fd,b,n) char *b; int fd,n; {
return(_write(fd,b,n));
return(write(fd,b,n));
}