|
@@ -6,15 +6,19 @@
|
|
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
-
|
|
+#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/types.h>
|
|
#include <malloc.h>
|
|
#include <malloc.h>
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
|
|
+#include <string.h>
|
|
|
|
|
|
#undef STUB_FWRITE
|
|
#undef STUB_FWRITE
|
|
|
|
|
|
|
|
+void __io_init_vars(void);
|
|
|
|
+
|
|
extern FILE *__IO_list;
|
|
extern FILE *__IO_list;
|
|
|
|
|
|
#define FIXED_BUFFERS 2
|
|
#define FIXED_BUFFERS 2
|
|
@@ -80,10 +84,7 @@ FILE stderr[1] =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-#define STATIC
|
|
+void __stdio_close_all(void)
|
|
-
|
|
|
|
-STATIC int
|
|
|
|
-__stdio_close_all()
|
|
|
|
{
|
|
{
|
|
FILE *fp;
|
|
FILE *fp;
|
|
fflush(stdout);
|
|
fflush(stdout);
|
|
@@ -103,8 +104,7 @@ static int first_time = 0;
|
|
struct fixed_buffer _fixed_buffers[2];
|
|
struct fixed_buffer _fixed_buffers[2];
|
|
|
|
|
|
|
|
|
|
-STATIC void
|
|
+void __io_init_vars(void)
|
|
-__io_init_vars()
|
|
|
|
{
|
|
{
|
|
if( first_time ) return;
|
|
if( first_time ) return;
|
|
first_time = 1;
|
|
first_time = 1;
|
|
@@ -206,7 +206,9 @@ FILE *fp;
|
|
if (fp->mode & __MODE_WRITING)
|
|
if (fp->mode & __MODE_WRITING)
|
|
fflush(fp);
|
|
fflush(fp);
|
|
|
|
|
|
|
|
+#if __MODE_IOTRAN
|
|
try_again:
|
|
try_again:
|
|
|
|
+#endif
|
|
|
|
|
|
if ((fp->mode & (__MODE_READ | __MODE_EOF | __MODE_ERR)) != __MODE_READ)
|
|
if ((fp->mode & (__MODE_READ | __MODE_EOF | __MODE_ERR)) != __MODE_READ)
|
|
return EOF;
|
|
return EOF;
|
|
@@ -319,7 +321,7 @@ FILE *fp;
|
|
char *
|
|
char *
|
|
fgets(s, count, f)
|
|
fgets(s, count, f)
|
|
char *s;
|
|
char *s;
|
|
-size_t count;
|
|
+int count;
|
|
FILE *f;
|
|
FILE *f;
|
|
{
|
|
{
|
|
char *ret;
|
|
char *ret;
|
|
@@ -368,7 +370,7 @@ char *str;
|
|
#ifdef L_fputs
|
|
#ifdef L_fputs
|
|
int
|
|
int
|
|
fputs(str, fp)
|
|
fputs(str, fp)
|
|
-char *str;
|
|
+const char *str;
|
|
FILE *fp;
|
|
FILE *fp;
|
|
{
|
|
{
|
|
register int n = 0;
|
|
register int n = 0;
|
|
@@ -385,7 +387,7 @@ FILE *fp;
|
|
#ifdef L_puts
|
|
#ifdef L_puts
|
|
int
|
|
int
|
|
puts(str)
|
|
puts(str)
|
|
-char *str;
|
|
+const char *str;
|
|
{
|
|
{
|
|
register int n;
|
|
register int n;
|
|
|
|
|
|
@@ -405,12 +407,12 @@ char *str;
|
|
* This ignores __MODE__IOTRAN; probably exactly what you want. (It _is_ what
|
|
* This ignores __MODE__IOTRAN; probably exactly what you want. (It _is_ what
|
|
* fgetc wants)
|
|
* fgetc wants)
|
|
*/
|
|
*/
|
|
-int
|
|
+size_t
|
|
fread(buf, size, nelm, fp)
|
|
fread(buf, size, nelm, fp)
|
|
-char *buf;
|
|
+void *buf;
|
|
-int size;
|
|
+size_t size;
|
|
-int nelm;
|
|
+size_t nelm;
|
|
-FILE *fp;
|
|
+FILE *fp;
|
|
{
|
|
{
|
|
int len, v;
|
|
int len, v;
|
|
unsigned bytes, got = 0;
|
|
unsigned bytes, got = 0;
|
|
@@ -467,12 +469,12 @@ FILE *fp;
|
|
*
|
|
*
|
|
* Again this ignores __MODE__IOTRAN.
|
|
* Again this ignores __MODE__IOTRAN.
|
|
*/
|
|
*/
|
|
-int
|
|
+size_t
|
|
fwrite(buf, size, nelm, fp)
|
|
fwrite(buf, size, nelm, fp)
|
|
-char *buf;
|
|
+const void *buf;
|
|
-int size;
|
|
+size_t size;
|
|
-int nelm;
|
|
+size_t nelm;
|
|
-FILE *fp;
|
|
+FILE *fp;
|
|
{
|
|
{
|
|
register int v;
|
|
register int v;
|
|
int len;
|
|
int len;
|
|
@@ -606,7 +608,6 @@ int ref;
|
|
long ftell(fp)
|
|
long ftell(fp)
|
|
FILE * fp;
|
|
FILE * fp;
|
|
{
|
|
{
|
|
- long rv;
|
|
|
|
if (fflush(fp) == EOF)
|
|
if (fflush(fp) == EOF)
|
|
return EOF;
|
|
return EOF;
|
|
return lseek(fp->fd, 0L, SEEK_CUR);
|
|
return lseek(fp->fd, 0L, SEEK_CUR);
|
|
@@ -620,10 +621,10 @@ FILE * fp;
|
|
*/
|
|
*/
|
|
FILE *
|
|
FILE *
|
|
__fopen(fname, fd, fp, mode)
|
|
__fopen(fname, fd, fp, mode)
|
|
-char *fname;
|
|
+const char *fname;
|
|
int fd;
|
|
int fd;
|
|
FILE *fp;
|
|
FILE *fp;
|
|
-char *mode;
|
|
+const char *mode;
|
|
{
|
|
{
|
|
int open_mode = 0;
|
|
int open_mode = 0;
|
|
#if __MODE_IOTRAN
|
|
#if __MODE_IOTRAN
|
|
@@ -875,8 +876,8 @@ size_t size;
|
|
|
|
|
|
if( mode == _IOFBF || mode == _IOLBF )
|
|
if( mode == _IOFBF || mode == _IOLBF )
|
|
{
|
|
{
|
|
- if( size <= 0 ) size = BUFSIZ;
|
|
+ if( size <= 0 ) { size = BUFSIZ; }
|
|
- if( buf == 0 )
|
|
+ if( buf == 0 ) {
|
|
if (size == BUFSIZ) {
|
|
if (size == BUFSIZ) {
|
|
int i;
|
|
int i;
|
|
for(i=0;i<FIXED_BUFFERS;i++)
|
|
for(i=0;i<FIXED_BUFFERS;i++)
|
|
@@ -887,8 +888,10 @@ size_t size;
|
|
}
|
|
}
|
|
if(i==FIXED_BUFFERS)
|
|
if(i==FIXED_BUFFERS)
|
|
buf = malloc(size);
|
|
buf = malloc(size);
|
|
- } else
|
|
+ } else {
|
|
buf = malloc(size);
|
|
buf = malloc(size);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if( buf == 0 ) return EOF;
|
|
if( buf == 0 ) return EOF;
|
|
|
|
|
|
fp->bufstart = buf;
|
|
fp->bufstart = buf;
|
|
@@ -896,6 +899,7 @@ size_t size;
|
|
fp->mode |= mode;
|
|
fp->mode |= mode;
|
|
}
|
|
}
|
|
fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart;
|
|
fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart;
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|