]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - lib/sh/zmapfd.c
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / lib / sh / zmapfd.c
index e720892111c6f76915faaea1f4bed62871ecb94d..f9e9ed71e6cd24a6e9cdb6b832781e0a6e79586d 100644 (file)
@@ -1,6 +1,6 @@
 /* zmapfd - read contents of file descriptor into a newly-allocated buffer */
 
-/* Copyright (C) 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2006-2020 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 extern int errno;
 #endif
 
-extern ssize_t zread __P((int, char *, size_t));
+#ifndef ZBUFSIZ
+#  define ZBUFSIZ 4096
+#endif
+
+extern ssize_t zread PARAMS((int, char *, size_t));
 
 /* Dump contents of file descriptor FD to *OSTR.  FN is the filename for
    error messages (not used right now). */
@@ -48,12 +52,12 @@ zmapfd (fd, ostr, fn)
 {
   ssize_t nr;
   int rval;
-  char lbuf[128];
+  char lbuf[ZBUFSIZ];
   char *result;
   int rsize, rind;
 
   rval = 0;
-  result = (char *)xmalloc (rsize = 64);
+  result = (char *)xmalloc (rsize = ZBUFSIZ);
   rind = 0;
 
   while (1)
@@ -72,7 +76,7 @@ zmapfd (fd, ostr, fn)
          return -1;
        }
 
-      RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, 128);
+      RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, ZBUFSIZ);
       memcpy (result+rind, lbuf, nr);
       rind += nr;
     }