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 */
#include <stdlib.h>
#include "loc_incl.h"
-int close(int d);
+int _close(int d);
int
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)
#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)
}
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]);
+}
#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)
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) {
#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;
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;
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;
}
*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;
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;
#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)
* 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;
}
#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)
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':
}
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++) {
#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)
&& 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);
#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)
{
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;
/*
- * 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;
where gtty is an ioctl(..., TCGETA, ...)
*/
- return gtty(d, buf) >= 0;
+ return _gtty(d, buf) >= 0;
}
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);
#include <stdio.h>
-int unlink(const char *path);
+int _unlink(const char *path);
int
remove(const char *filename) {
- return unlink(filename);
+ return _unlink(filename);
}
#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;
}
#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;
#include <string.h>
#include "loc_incl.h"
-unsigned int getpid(void);
+unsigned int _getpid(void);
FILE *
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';
}
#include <string.h>
#include "loc_incl.h"
-unsigned int getpid(void);
+unsigned int _getpid(void);
char *
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';
}