A few patches from Erik Hovland, turning strncpy() into safe_strncpy() and
[oweals/busybox.git] / archival / gzip.c
index 41ed3a2c7c0fabbb6731a66966d969c51c88aaae..91b2948917f5658b6ecce5411b5ae3f86711cfd2 100644 (file)
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-/* These defines are very important for BusyBox.  Without these,
- * huge chunks of ram are pre-allocated making the BusyBox bss
- * size Freaking Huge(tm), which is a bad thing.*/
 #define SMALL_MEM
-#define DYN_ALLOC
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -87,17 +83,11 @@ typedef unsigned long ulg;
 #  endif
 #endif
 
-#ifdef DYN_ALLOC
 #  define DECLARE(type, array, size)  static type * array
 #  define ALLOC(type, array, size) { \
-      array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
+      array = (type*)xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)); \
    }
 #  define FREE(array) {free(array), array=NULL;}
-#else
-#  define DECLARE(type, array, size)  static type array[size]
-#  define ALLOC(type, array, size)
-#  define FREE(array)
-#endif
 
 #define tab_suffix window
 #define tab_prefix prev        /* hash link (see deflate.c) */
@@ -334,7 +324,7 @@ static void write_buf(int fd, void *buf, unsigned cnt)
        unsigned n;
 
        while ((n = write(fd, buf, cnt)) != cnt) {
-               if (n == (unsigned) (-1)) bb_error_msg_and_die("can't write");
+               if (n == (unsigned) (-1)) bb_error_msg_and_die(bb_msg_write_error);
                cnt -= n;
                buf = (void *) ((char *) buf + n);
        }
@@ -1228,8 +1218,8 @@ int gzip_main(int argc, char **argv)
                                inFileNum = STDIN_FILENO;
                                outFileNum = STDOUT_FILENO;
                        } else {
-                               inFileNum = open(argv[i], O_RDONLY);
-                               if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0)
+                               inFileNum = bb_xopen3(argv[i], O_RDONLY, 0);
+                               if (fstat(inFileNum, &statBuf) < 0)
                                        bb_perror_msg_and_die("%s", argv[i]);
                                time_stamp = statBuf.st_ctime;
                                ifile_size = statBuf.st_size;