OSDN Git Service

* src/lharc.c: use xstrdup() instead of strdup().
[lha/lha.git] / src / lharc.c
index adae506..1693344 100644 (file)
@@ -197,11 +197,9 @@ main(argc, argv)
        init_variable();                /* Added N.Watazaki */
 
        ac = argc;
-       av = (char **)malloc( sizeof(char*)*argc );
-       if (av == NULL) fatal_error("not enough memory\n");
+       av = (char **)xmalloc( sizeof(char*)*argc );
        for (i=0; i<argc; i++) {
-         if ((av[i] = strdup( argv[i] )) == NULL)
-               fatal_error("not enough memory\n");
+        av[i] = xstrdup( argv[i] );
        }
 
        if (ac < 2)
@@ -393,8 +391,7 @@ work:
        /* target file name */
        if (get_filename_from_stdin) {
                cmd_filec = 0;
-               if ((xfilev = (char **) malloc(sizeof(char *) * xfilec)) == NULL)
-                       fatal_error("Virtual memory exhausted\n");
+               xfilev = (char **)xmalloc(sizeof(char *) * xfilec);
                while (fgets(inpbuf, sizeof(inpbuf), stdin)) {
                    /* delete \n if it exist */
                        i=0; p=inpbuf;
@@ -416,8 +413,7 @@ work:
                        }
                        if (strlen(inpbuf) < 1)
                                continue;
-                       if ((xfilev[cmd_filec++] = (char *) strdup(inpbuf)) == NULL)
-                               fatal_error("Virtual memory exhausted\n");
+                       xfilev[cmd_filec++] = xstrdup(inpbuf);
                }
                xfilev[cmd_filec] = NULL;
                cmd_filev = xfilev;
@@ -549,7 +545,9 @@ interrupt(signo)
                unlink(writting_filename);
        }
        signal(SIGINT, SIG_DFL);
+#ifdef SIGHUP
        signal(SIGHUP, SIG_DFL);
+#endif
        kill(getpid(), signo);
 }
 
@@ -616,6 +614,18 @@ xrealloc(old, size)
        return p;
 }
 
+char *
+xstrdup(str)
+       char *str;
+{
+    int len = strlen(str);
+       char *p = (char *)xmalloc(str + 1);
+       if (!p)
+               fatal_error("Not enough memory");
+    strcpy(p, str);
+       return p;
+}
+
 /* ------------------------------------------------------------------------ */
 /*                                                             STRING POOL                                                                     */
 /* ------------------------------------------------------------------------ */