summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/_G_config.h14
-rw-r--r--libio/filedoalloc.c4
-rw-r--r--libio/fileops.c4
-rw-r--r--libio/genops.c10
-rw-r--r--libio/libio.h3
-rw-r--r--libio/libioP.h51
-rw-r--r--libio/memstream.c4
-rw-r--r--libio/strops.c2
-rw-r--r--libio/vasprintf.c11
9 files changed, 82 insertions, 21 deletions
diff --git a/libio/_G_config.h b/libio/_G_config.h
index 34d77e2b80..5fa7300bf7 100644
--- a/libio/_G_config.h
+++ b/libio/_G_config.h
@@ -16,6 +16,13 @@
 #define	_G_pid_t	__pid_t
 #define	_G_uid_t	__uid_t
 
+typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
+typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
+typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
+typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
+
+#define _G_HAVE_BOOL 1
+
 
 /* These library features are always available in the GNU C library.  */
 #define _G_HAVE_ATEXIT 1
@@ -25,6 +32,7 @@
 #define _G_va_list __gnuc_va_list
 
 #define _G_HAVE_PRINTF_FP 1
+#define _G_HAVE_MMAP 1
 
 /* This is defined by <statbuf.h> if `st_blksize' exists.  */
 #define _G_HAVE_ST_BLKSIZE defined (_STATBUF_ST_BLKSIZE)
@@ -37,4 +45,10 @@
 #define _G_VTABLE_LABEL_HAS_LENGTH 1
 
 
+#if defined (__cplusplus) || defined (__STDC__)
+#define _G_ARGS(ARGLIST) ARGLIST
+#else
+#define _G_ARGS(ARGLIST) ()
+#endif
+
 #endif	/* _G_config.h */
diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c
index eee489b825..f36bfb3e32 100644
--- a/libio/filedoalloc.c
+++ b/libio/filedoalloc.c
@@ -98,9 +98,7 @@ DEFUN(_IO_file_doallocate, (fp),
       size = _IO_BUFSIZ;
 #endif
     }
-  p = ALLOC_BUF(size);
-  if (p == NULL)
-    return EOF;
+  ALLOC_BUF(p, size, EOF);
   _IO_setb(fp, p, p+size, 1);
   if (couldbetty && __isatty (fp->_fileno))
     fp->_flags |= _IO_LINE_BUF;
diff --git a/libio/fileops.c b/libio/fileops.c
index b5026e167a..3294befbd2 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -547,7 +547,7 @@ DEFUN(_IO_file_read, (fp, buf, size),
   for (;;)
     {
       _IO_ssize_t count = _IO_read(fp->_fileno, buf, size);
-#ifdef EINTR
+#if 0 && defined EINTR
       if (count == -1 && errno == EINTR)
 	continue;
 #endif
@@ -586,7 +586,7 @@ DEFUN(_IO_file_write, (f, data, n),
       _IO_ssize_t count = _IO_write(f->_fileno, data, to_do);
       if (count == EOF)
 	{
-#ifdef EINTR
+#if 0 && defined EINTR
 	  if (errno == EINTR)
 	    continue;
 	  else
diff --git a/libio/genops.c b/libio/genops.c
index 3a58cd2eaf..52b8fc312a 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -278,7 +278,7 @@ DEFUN(_IO_setb, (f, b, eb, a),
       _IO_FILE *f AND char *b AND char *eb AND int a)
 {
   if (f->_IO_buf_base && !(f->_flags & _IO_USER_BUF))
-    FREE_BUF(f->_IO_buf_base);
+    FREE_BUF(f->_IO_buf_base, _IO_blen (f));
   f->_IO_buf_base = b;
   f->_IO_buf_end = eb;
   if (a)
@@ -438,9 +438,9 @@ int
 DEFUN(_IO_default_doallocate, (fp),
       _IO_FILE *fp)
 {
-  char *buf = ALLOC_BUF(_IO_BUFSIZ);
-  if (buf == NULL)
-    return EOF;
+  char *buf;
+
+  ALLOC_BUF(buf, _IO_BUFSIZ, EOF);
   _IO_setb(fp, buf, buf+_IO_BUFSIZ, 1);
   return 1;
 }
@@ -487,7 +487,7 @@ DEFUN(_IO_default_finish, (fp),
   struct _IO_marker *mark;
   if (fp->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
     {
-      FREE_BUF(fp->_IO_buf_base);
+      FREE_BUF(fp->_IO_buf_base, _IO_blen (fp));
       fp->_IO_buf_base = fp->_IO_buf_end = NULL;
     }
 
diff --git a/libio/libio.h b/libio/libio.h
index acc34c0d7a..49f1d8ccd4 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -83,7 +83,8 @@ the executable file might be covered by the GNU General Public License. */
 #define EOF (-1)
 #endif
 #ifndef NULL
-#ifdef __GNUG__
+#if defined __GNUG__ && \
+    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
 #define NULL (__null)
 #else
 #if !defined(__cplusplus)
diff --git a/libio/libioP.h b/libio/libioP.h
index 008f9b7edf..c9a639ab9a 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -396,7 +396,8 @@ extern void (*_IO_cleanup_registration_needed) __P ((void));
 #define EOF (-1)
 #endif
 #ifndef NULL
-#ifdef __GNUG__
+#if defined __GNUG__ && \
+    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
 #define NULL (__null)
 #else
 #if !defined(__cplusplus)
@@ -407,8 +408,52 @@ extern void (*_IO_cleanup_registration_needed) __P ((void));
 #endif
 #endif
 
-#define FREE_BUF(_B) free(_B)
-#define ALLOC_BUF(_S) (char*)malloc(_S)
+#if _G_HAVE_MMAP
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+
+#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
+#undef _G_HAVE_MMAP
+#define _G_HAVE_MMAP 0
+#endif
+
+#endif /* _G_HAVE_MMAP */
+
+#if _G_HAVE_MMAP
+
+#define ROUND_TO_PAGE(_S) \
+       (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
+
+#define FREE_BUF(_B, _S) \
+       munmap ((_B), ROUND_TO_PAGE (_S))
+#define ALLOC_BUF(_B, _S, _R) \
+       do {								      \
+	  (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S),			      \
+				PROT_READ | PROT_WRITE,			      \
+				MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);	      \
+	  if ((_B) == (char *) -1)					      \
+	    return (_R);						      \
+       } while (0)
+
+#else /* _G_HAVE_MMAP */
+
+#define FREE_BUF(_B, _S) \
+       free(_B)
+#define ALLOC_BUF(_B, _S, _R) \
+       do {								      \
+	  (_B) = (char*)malloc(_S);					      \
+	  if ((_B) == NULL)						      \
+	    return (_R);						      \
+       } while (0)
+
+#endif /* _G_HAVE_MMAP */
 
 #ifndef OS_FSTAT
 #define OS_FSTAT fstat
diff --git a/libio/memstream.c b/libio/memstream.c
index ddcce676cb..e3c34d0b34 100644
--- a/libio/memstream.c
+++ b/libio/memstream.c
@@ -80,7 +80,9 @@ open_memstream (bufloc, sizeloc)
   new_f->fp._sf._sbf._f._lock = &new_f->lock;
 #endif
 
-  buf = ALLOC_BUF (_IO_BUFSIZ);
+  buf = malloc (_IO_BUFSIZ);
+  if (buf == NULL)
+    return NULL;
   _IO_init (&new_f->fp._sf._sbf._f, 0);
   _IO_JUMPS (&new_f->fp._sf._sbf._f) = &_IO_mem_jumps;
   _IO_str_init_static (&new_f->fp._sf._sbf._f, buf, _IO_BUFSIZ, buf);
diff --git a/libio/strops.c b/libio/strops.c
index 8a6c56d055..281141eba7 100644
--- a/libio/strops.c
+++ b/libio/strops.c
@@ -124,7 +124,7 @@ DEFUN(_IO_str_overflow, (fp, c),
       fp->_IO_read_ptr = fp->_IO_read_end;
     }
   pos =  fp->_IO_write_ptr - fp->_IO_write_base;
-  if (pos >= _IO_blen(fp) + flush_only)
+  if (pos >= (_IO_size_t) (_IO_blen(fp) + flush_only))
     {
       if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */
 	return EOF;
diff --git a/libio/vasprintf.c b/libio/vasprintf.c
index f8dba80c38..02289407f4 100644
--- a/libio/vasprintf.c
+++ b/libio/vasprintf.c
@@ -42,7 +42,7 @@ _IO_vasprintf (result_ptr, format, args)
   _IO_lock_t lock;
 #endif
   int ret;
-  string = ALLOC_BUF(init_string_size);
+  string = malloc (init_string_size);
   if (string == NULL)
     return -1;
 #ifdef _IO_MTSAFE_IO
@@ -52,13 +52,14 @@ _IO_vasprintf (result_ptr, format, args)
   _IO_JUMPS((_IO_FILE*)&sf) = &_IO_str_jumps;
   _IO_str_init_static ((_IO_FILE*)&sf, string, init_string_size, string);
   sf._sbf._f._flags &= ~_IO_USER_BUF;
-  sf._s._allocate_buffer = (_IO_alloc_type)malloc;
-  sf._s._free_buffer = (_IO_free_type)free;
+  sf._s._allocate_buffer = (_IO_alloc_type) malloc;
+  sf._s._free_buffer = (_IO_free_type) free;
   ret = _IO_vfprintf((_IO_FILE*)&sf, format, args);
   if (ret < 0)
     return ret;
-  *result_ptr = (char*)realloc(sf._sbf._f._IO_buf_base,
-			       (sf._sbf._f._IO_write_ptr - sf._sbf._f._IO_write_base) +1);
+  *result_ptr = (char *) realloc (sf._sbf._f._IO_buf_base,
+				  (sf._sbf._f._IO_write_ptr
+				   - sf._sbf._f._IO_write_base) +1);
   if (*result_ptr == NULL)
     *result_ptr = sf._sbf._f._IO_buf_base;
   (*result_ptr)[sf._sbf._f._IO_write_ptr-sf._sbf._f._IO_write_base] = '\0';