OSDN Git Service

* src/lharc.c (message): use variable argument list with stdarg.
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 16 Jun 2002 17:23:09 +0000 (17:23 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 16 Jun 2002 17:23:09 +0000 (17:23 +0000)
(warning): ditto.
(error): ditto.
(write_error): removed.
(read_error): removed.
(build_temporary_name): use xsnprintf().
(open_old_archive): ditto.
(expanded_archive_name): move in the function (open_old_archive()) as static.

* src/crcio.c (putcode): changed for fatal_error().
(putbits): changed for fatal_error().
(fwrite_crc): ditto.
(putc_euc): should return EOF when putc() cause error.
(fwrite_txt): changed for putc_euc().

* src/header.c (get_header): changed for fatal_error(), warning() and error().
(init_header): use xsnprintf().
(write_header): fixed wrong usage of fwrite().

* src/lha.h: updated declarations.

* src/lhadd.c (append_it): changed for error().

* src/lhext.c (inquire_extract): ditto.

* src/lhlist.c (cmd_list): ditto.

* src/maketbl.c (make_table): ditto.

* src/util.c (copyfile): changed for fatal_error().
(xsnprintf): newly added to adopt to various snprintf().

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@196 6a8cc165-1e22-0410-a132-eb4e3f353aba

src/crcio.c
src/header.c
src/lha.h
src/lhadd.c
src/lharc.c
src/lhext.c
src/lhlist.c
src/maketbl.c
src/util.c

index e0c520d..c2b77aa 100644 (file)
@@ -109,9 +109,7 @@ putcode(n, x)                       /* Write rightmost n bits of x */
                x <<= bitcount;
                if (compsize < origsize) {
                        if (fwrite(&subbitbuf, 1, 1, outfile) == 0) {
-                               /* fileerror(WTERR, outfile); */
-                           fatal_error("Write error in crcio.c(putcode)\n");
-                               /* exit(errno); */
+                           fatal_error("Write error in crcio.c(putcode)");
                        }
                        compsize++;
                }
@@ -137,9 +135,7 @@ putbits(n, x)                       /* Write rightmost n bits of x */
                x <<= bitcount;
                if (compsize < origsize) {
                        if (fwrite(&subbitbuf, 1, 1, outfile) == 0) {
-                               /* fileerror(WTERR, outfile); */
-                           fatal_error("Write error in crcio.c(putbits)\n");
-                               /* exit(errno); */
+                           fatal_error("Write error in crcio.c(putbits)");
                        }
                        compsize++;
                }
@@ -182,11 +178,11 @@ fwrite_crc(p, n, fp)
        if (fp) {
                if (text_mode) {
                        if (fwrite_txt(p, n, fp))
-                               fatal_error("File write error\n");
+                               fatal_error("File write error");
                }
                else {
                        if (fwrite(p, 1, n, fp) < n)
-                               fatal_error("File write error\n");
+                               fatal_error("File write error");
                }
        }
 }
@@ -224,7 +220,7 @@ init_putbits( /* void */ )
 
 /* ------------------------------------------------------------------------ */
 #ifdef EUC
-void
+int
 putc_euc(c, fd)
        int             c;
        FILE           *fd;
@@ -233,13 +229,11 @@ putc_euc(c, fd)
 
        if (putc_euc_cache == EOF) {
                if (!euc_mode || c < 0x81 || c > 0xFC) {
-                       putc(c, fd);
-                       return;
+                       return putc(c, fd);
                }
                if (c >= 0xA0 && c < 0xE0) {
-                       putc(0x8E, fd); /* single shift */
-                       putc(c, fd);
-                       return;
+                       if (putc(0x8E, fd) == EOF) return EOF;  /* single shift */
+                       return putc(c, fd);
                }
                putc_euc_cache = c;     /* save first byte */
                return;
@@ -258,8 +252,8 @@ putc_euc(c, fd)
                c -= 0x1F;
                d = (d - 0x81) * 2 + 0x21;
        }
-       putc(0x80 | d, fd);
-       putc(0x80 | c, fd);
+       if (putc(0x80 | d, fd) == EOF) return EOF;
+       return putc(0x80 | c, fd);
 }
 #endif
 
@@ -273,9 +267,11 @@ fwrite_txt(p, n, fp)
        while (--n >= 0) {
                if (*p != '\015' && *p != '\032') {
 #ifdef EUC
-                       putc_euc(*p, fp);
+                       if (putc_euc(*p, fp) == EOF)
+                break;
 #else
-                       putc(*p, fp);
+                       if (putc(*p, fp) == EOF)
+                break;
 #endif
                }
 
index d297702..5a92dd9 100644 (file)
@@ -547,7 +547,7 @@ get_header(fp, hdr)
        }
 
        if (hdr->header_level >= 3) {
-               fatal_error("Unknown level header");
+               fatal_error("Unknown level header (level %d)", hdr->header_level);
                return FALSE;
        }
 
@@ -568,7 +568,7 @@ get_header(fp, hdr)
 
        if ((hdr->header_level = get_byte()) != 2) {
                if (calc_sum(data + I_METHOD, header_size) != checksum)
-                       warning("Checksum error (LHarc file?)", "");
+                       warning("Checksum error (LHarc file?)");
                name_length = get_byte();
                for (i = 0; i < name_length; i++)
                        hdr->name[i] = (char) get_byte();
@@ -591,8 +591,8 @@ get_header(fp, hdr)
                                hdr->extend_type = EXTEND_GENERIC;
                                hdr->has_crc = FALSE;
                        } else {
-                               fatal_error("Unkonwn header (lha file?)");
-                               return FALSE;
+                               error("Unkonwn header (lha file?)");
+                exit(1);
                        }
                } else {
                        hdr->has_crc = TRUE;
@@ -887,14 +887,15 @@ init_header(name, v_stat, hdr)
 
 #ifdef S_IFLNK 
        if (is_symlink(v_stat)) {
-               char    lkname[257];
+               char    lkname[256];    /* FIXME: no enough space */
                int             len;    
                bcopy(LZHDIRS_METHOD, hdr->method, METHOD_TYPE_STRAGE);
                hdr->attribute = GENERIC_DIRECTORY_ATTRIBUTE;
                hdr->original_size = 0;
-               len = readlink(name, lkname, 256);
-               lkname[len] = (char)'\0';
-               sprintf(hdr->name, "%s|%s", hdr->name, lkname);
+               len = readlink(name, lkname, sizeof(lkname));
+               if (xsnprintf(hdr->name, sizeof(hdr->name),
+                      "%s|%.*s", hdr->name, len, lkname) == -1)
+            error("file name is too long (%s -> %.*s)", hdr->name, len, lkname);
        }
 #endif
 
@@ -1080,7 +1081,7 @@ write_header(nafp, hdr)
                put_word(hcrc);
        }
 
-       if (fwrite(data, sizeof(char), header_size + 2, nafp) == 0)
+       if (fwrite(data, header_size + 2, 1, nafp) == 0)
                fatal_error("Cannot write to temporary file");
 
     filename_conv(hdr->name, strlen(hdr->name), sizeof(hdr->name),
index 86f8f79..b065c19 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -151,7 +151,6 @@ EXTERN char         **cmd_filev;
 EXTERN int      cmd_filec;
 
 EXTERN char            *archive_name;
-EXTERN char     expanded_archive_name[FILENAME_LENGTH];
 EXTERN char     temporary_name[FILENAME_LENGTH];
 EXTERN char     backup_archive_name[FILENAME_LENGTH];
 
@@ -217,10 +216,10 @@ extern int                patmatch();
 
 extern void            interrupt();
 
-extern void            message();
-extern void            warning();
-extern void            error();
-extern void            fatal_error();
+extern void            message(char *fmt, ...);
+extern void            warning(char *fmt, ...);
+extern void            error(char *fmt, ...);
+extern void            fatal_error(char *fmt, ...);
 
 extern boolean need_file();
 extern int             inquire();
@@ -339,6 +338,10 @@ extern int      encode_stored_crc();
 void euc2sjis(int *p1, int *p2);
 void sjis2euc(int *p1, int *p2);
 
+/* from util.c */
+int xsnprintf(char *dest, size_t size, char *fmt, ...);
+
+
 /* Local Variables: */
 /* mode:c */
 /* tab-width:4 */
index a8a1503..d0aed87 100644 (file)
@@ -92,7 +92,7 @@ append_it(name, oafp, nafp)
        boolean         directory, symlink;
 
        if (GETSTAT(name, &stbuf) < 0) {
-               error("Cannot access", name);   /* See cleaning_files, Why? */
+               error("Cannot access file \"%s\"", name);       /* See cleaning_files, Why? */
                return oafp;
        }
        
@@ -244,9 +244,9 @@ delete(oafp, nafp)
                        fseek(oafp, ahdr.packed_size, SEEK_CUR);
                        if (noexec || !quiet)
                                if (b2 != NULL)
-                                       printf("delete %s -> %s\n", b1, b2);
+                                       message("delete %s -> %s", b1, b2);
                                else
-                                       printf("delete %s\n", b1);
+                                       message("delete %s", b1);
                }
                else {          /* copy */
                        if (noexec) {
@@ -278,11 +278,11 @@ build_temporary_file()
     remove_temporary_at_error = TRUE;
     temporary_fd = build_temporary_name();
     if (temporary_fd == -1)
-        fatal_error(temporary_name);
+        fatal_error("Cannot open temporary file \"%s\"", temporary_name);
 
     afp = fdopen(temporary_fd, WRITE_BINARY);
     if (afp == NULL)
-        fatal_error(temporary_name);
+        fatal_error("Cannot open temporary file \"%s\"", temporary_name);
 
     return afp;
 }
@@ -305,7 +305,7 @@ build_backup_file()
             if (unlink(backup_archive_name) < 0 ||
                 rename(archive_name, backup_archive_name) < 0)
 #endif
-                       fatal_error(archive_name);
+            fatal_error("Cannot make backup file \"%s\"", archive_name);
         }
                recover_archive_when_interrupt = TRUE;
                signal(SIGINT, interrupt);
@@ -321,7 +321,7 @@ report_archive_name_if_different()
 {
        if (!quiet && new_archive_name == new_archive_name_buffer) {
                /* warning at old archive is SFX */
-               fprintf(stderr, "New archive file is \"%s\"\n", new_archive_name);
+               message("New archive file is \"%s\"", new_archive_name);
        }
 }
 
@@ -391,7 +391,7 @@ remove_one(name)
        char          **filev;
 
        if (GETSTAT(name, &stbuf) < 0) {
-               warning("Cannot access", name);
+               warning("Cannot access \"%s\": %s", name, strerror(errno));
        }
        else if (is_directory(&stbuf)) {
                if (find_files(name, &filec, &filev)) {
@@ -399,22 +399,22 @@ remove_one(name)
                        free_files(filec, filev);
                }
                else
-                       warning("Cannot open directory", name);
+                       warning("Cannot open directory \"%s\"", name);
 
                if (noexec)
-                       printf("REMOVE DIRECTORY %s\n", name);
+                       message("REMOVE DIRECTORY %s", name);
                else if (rmdir(name) < 0)
-                       warning("Cannot remove directory", name);
+                       warning("Cannot remove directory \"%s\"", name);
                else if (verbose)
-                       printf("Removed %s.\n", name);
+                       message("Removed %s.", name);
        }
        else if (is_regularfile(&stbuf)) {
                if (noexec)
-                       printf("REMOVE FILE %s.\n", name);
+                       message("REMOVE FILE %s.", name);
                else if (unlink(name) < 0)
-                       warning("Cannot remove", name);
+                       warning("Cannot remove \"%s\"", name);
                else if (verbose)
-                       printf("Removed %s.\n", name);
+                       message("Removed %s.", name);
        }
 #ifdef S_IFLNK
        else if (is_symlink(&stbuf)) {
@@ -423,11 +423,11 @@ remove_one(name)
                else if (unlink(name) < 0)
                        warning("Cannot remove", name);
                else if (verbose)
-                       printf("Removed %s.\n", name);
+                       message("Removed %s.", name);
        }
 #endif
        else {
-               error("Cannot remove (not a file or directory)", name);
+               error("Cannot remove file \"%s\" (not a file or directory)", name);
        }
 }
 
@@ -457,8 +457,8 @@ cmd_add()
 
        /* exit if no operation */
        if (!update_if_newer && cmd_filec == 0) {
-               error("No files given in argument, do nothing.", "");
-               return;
+               error("No files given in argument, do nothing.");
+        exit(1);
        }
 
        /* open old archive if exist */
@@ -467,10 +467,14 @@ cmd_add()
        else
                old_archive_exist = TRUE;
 
-       if (update_if_newer && cmd_filec == 0 && !oafp)
-               fatal_error(archive_name);      /* exit if cannot execute
-                                                * automatic update */
-       errno = 0;
+       if (update_if_newer && cmd_filec == 0) {
+        warning("No files given in argument");
+        if (!oafp) {
+            error("archive file \"%s\" does not exists.",
+                  archive_name);
+            exit(1);
+        }
+    }
 
        if (new_archive && old_archive_exist) {
                fclose(oafp);
@@ -556,13 +560,12 @@ cmd_delete()
 
        /* open old archive if exist */
        if ((oafp = open_old_archive()) == NULL)
-               fatal_error(archive_name);
-       errno = 0;
+               fatal_error("Cannot open archive file \"%s\"", archive_name);
 
        /* exit if no operation */
        if (cmd_filec == 0) {
                fclose(oafp);
-               warning("No files given in argument, do nothing.", "");
+               warning("No files given in argument, do nothing.");
                return;
        }
 
@@ -595,7 +598,7 @@ cmd_delete()
        /* 1999.5.24 t.oka */
        if(!noexec && new_archive_size <= 1){
                unlink(temporary_name);
-               fprintf(stderr, "New archive file \"%s\" is not created because it would be empty.\n", new_archive_name);
+               warning("New archive file \"%s\" is not created because it would be empty.", new_archive_name);
                return;
        }
 
index 9f7eb50..42626f8 100644 (file)
@@ -44,6 +44,8 @@
 
 #include "lha.h"
 
+#include <stdarg.h>
+
 /* ------------------------------------------------------------------------ */
 /*                                                             PROGRAM                                                                         */
 /* ------------------------------------------------------------------------ */
@@ -55,7 +57,6 @@ char          **cmd_filev;
 int             cmd_filec;
 
 char           *archive_name;
-char            expanded_archive_name[FILENAME_LENGTH];
 char            temporary_name[FILENAME_LENGTH];
 char            backup_archive_name[FILENAME_LENGTH];
 #endif
@@ -344,7 +345,7 @@ main(argc, argv)
                                break;
 #endif
                        default:
-                               fprintf(stderr, "LHa: error option o%c\n", *p);
+                               error("invalid compression method 'o%c'", *p);
                                exit(1);
                        }
                        break;
@@ -371,7 +372,7 @@ main(argc, argv)
                        header_level = HEADER_LEVEL2;
                        break;
                default:
-                       fprintf(stderr, "LHa: Unknown option '%c'.\n", p[-1]);
+                       error("Unknown option '%c'.", p[-1]);
                        exit(1);
                }
        }
@@ -465,50 +466,75 @@ print_version()
        fprintf(stderr, "%s\n", LHA_VERSION);
 }
 
-/* ------------------------------------------------------------------------ */
-static void
-message_1(title, subject, name)
-       char           *title, *subject, *name;
+void
+message(char *fmt, ...)
 {
-       fprintf(stderr, "LHa: %s%s ", title, subject);
-       fflush(stderr);
+    int errno_sv = errno;
+    va_list v;
 
-       if (errno == 0)
-               fprintf(stderr, "%s\n", name);
-       else
-               perror(name);
-}
+       fprintf(stderr, "LHa: ");
 
-/* ------------------------------------------------------------------------ */
-void
-message(subject, name)
-       char           *subject, *name;
-{
-       message_1("", subject, name);
+    va_start(v, fmt);
+    vfprintf(stderr, fmt, v);
+    va_end(v);
+
+    fputs("\n", stderr);
+
+    errno =  errno_sv;
 }
 
 /* ------------------------------------------------------------------------ */
 void
-warning(subject, name)
-       char           *subject, *name;
+warning(char *fmt, ...)
 {
-       message_1("Warning: ", subject, name);
+    int errno_sv = errno;
+    va_list v;
+
+       fprintf(stderr, "LHa: Warning: ");
+
+    va_start(v, fmt);
+    vfprintf(stderr, fmt, v);
+    va_end(v);
+
+    fputs("\n", stderr);
+
+    errno =  errno_sv;
 }
 
 /* ------------------------------------------------------------------------ */
 void
-error(subject, msg)
-       char           *subject, *msg;
+error(char *fmt, ...)
 {
-       message_1("Error: ", subject, msg);
+    int errno_sv = errno;
+    va_list v;
+
+       fprintf(stderr, "LHa: Error: ");
+
+    va_start(v, fmt);
+    vfprintf(stderr, fmt, v);
+    va_end(v);
+
+    fputs("\n", stderr);
+
+    errno =  errno_sv;
 }
 
-/* ------------------------------------------------------------------------ */
 void
-fatal_error(msg)
-       char           *msg;
+fatal_error(char *fmt, ...)
 {
-    message_1("Fatal error:", "", msg);
+    int errno_sv = errno;
+    va_list v;
+
+       fprintf(stderr, "LHa: Fatal error: ");
+
+    va_start(v, fmt);
+    vfprintf(stderr, fmt, v);
+    va_end(v);
+
+       if (errno)
+        fprintf(stderr, ": %s\n", strerror(errno_sv));
+    else
+        fputs("\n", stderr);
 
     if (remove_temporary_at_error) {
         if (temporary_fd != -1)
@@ -521,25 +547,10 @@ fatal_error(msg)
 
 /* ------------------------------------------------------------------------ */
 void
-write_error()
-{
-       fatal_error(writting_filename);
-}
-
-/* ------------------------------------------------------------------------ */
-void
-read_error()
-{
-       fatal_error(reading_filename);
-}
-
-/* ------------------------------------------------------------------------ */
-void
 interrupt(signo)
        int             signo;
 {
-       errno = 0;
-       message("Interrupted\n", "");
+       message("Interrupted");
 
        if (temporary_fd != -1)
                close(temporary_fd);
@@ -547,8 +558,7 @@ interrupt(signo)
        if (recover_archive_when_interrupt)
                rename(backup_archive_name, archive_name);
        if (remove_extracting_file_when_interrupt) {
-               errno = 0;
-               message("Removing", writting_filename);
+               message("Removing: %s", writting_filename);
                unlink(writting_filename);
        }
        signal(SIGINT, SIG_DFL);
@@ -751,8 +761,7 @@ cleaning_files(v_filec, v_filev)
        for (i = 0; i < filec; i++)
                if (GETSTAT(filev[i], &stbuf) < 0) {
                        flags[i] = 0x04;
-                       fprintf(stderr,
-                        "LHa: Cannot access \"%s\", ignored.\n", filev[i]);
+                       warning("Cannot access \"%s\", ignored.", filev[i]);
                }
                else {
                        if (is_regularfile(&stbuf))
@@ -765,11 +774,9 @@ cleaning_files(v_filec, v_filev)
 #endif                 
                        else {
                                flags[i] = 0x04;
-                               fprintf(stderr,
-                                       "LHa: Cannot archive \"%s\", ignored.\n", filev[i]);
+                               warning("Cannot archive \"%s\", ignored.", filev[i]);
                        }
                }
-       errno = 0;
 
        for (i = 0; i < filec; i++) {
                p = filev[i];
@@ -920,7 +927,8 @@ build_temporary_name()
                strcpy(temporary_name, TMP_FILENAME_TEMPLATE);
        }
        else {
-               sprintf(temporary_name, "%s/lhXXXXXX", extract_directory);
+               xsnprintf(temporary_name, sizeof(temporary_name),
+                  "%s/lhXXXXXX", extract_directory);
        }
 #else
        char           *p, *s;
@@ -1023,7 +1031,7 @@ xfopen(name, mode)
        FILE           *fp;
 
        if ((fp = fopen(name, mode)) == NULL)
-               fatal_error(name);
+               fatal_error("Cannot open file \"%s\"", name);
 
        return fp;
 }
@@ -1059,6 +1067,7 @@ open_old_archive()
 {
        FILE           *fp;
        char           *p;
+    static char expanded_archive_name[FILENAME_LENGTH];
 
        if (!strcmp(archive_name, "-")) {
                if (cmd == CMD_EXTRACT || cmd == CMD_LIST) {
@@ -1084,7 +1093,8 @@ open_old_archive()
 
        if (open_old_archive_1(archive_name, &fp))
                return fp;
-       sprintf(expanded_archive_name, "%s.lzh", archive_name);
+       xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
+              "%s.lzh", archive_name);
        if (open_old_archive_1(expanded_archive_name, &fp)) {
                archive_name = expanded_archive_name;
                return fp;
@@ -1093,7 +1103,8 @@ open_old_archive()
         * if ( (errno&0xffff)!=E_PNNF ) { archive_name =
         * expanded_archive_name; return NULL; }
         */
-       sprintf(expanded_archive_name, "%s.lzs", archive_name);
+       xsnprintf(expanded_archive_name, sizeof(expanded_archive_name),
+              "%s.lzs", archive_name);
        if (open_old_archive_1(expanded_archive_name, &fp)) {
                archive_name = expanded_archive_name;
                return fp;
index 1047b96..efa6da7 100644 (file)
@@ -35,7 +35,7 @@ inquire_extract(name)
        skip_flg = FALSE;
        if (stat(name, &stbuf) >= 0) {
                if (!is_regularfile(&stbuf)) {
-                       error("Already exist (not a file)", name);
+                       error("\"%s\" already exists (not a file)", name);
                        return FALSE;
                }
 
@@ -90,20 +90,19 @@ make_parent_path(name)
                }
 
        if (p == path) {
-               message("Why?", "ROOT");
+               message("invalid path name \"%s\"", name);
                return FALSE;   /* no more parent. */
        }
 
        if (GETSTAT(path, &stbuf) >= 0) {
                if (is_directory(&stbuf))
                        return TRUE;
-               error("Not a directory", path);
+               error("Not a directory \"%s\"", path);
                return FALSE;
        }
-       errno = 0;
 
        if (verbose)
-               printf("Making directory \"%s\".\n", path);
+               message("Making directory \"%s\".", path);
 
 #if defined __MINGW32__
     if (mkdir(path) >= 0)
@@ -112,18 +111,17 @@ make_parent_path(name)
        if (mkdir(path, 0777) >= 0)     /* try */
                return TRUE;    /* successful done. */
 #endif
-       errno = 0;
 
        if (!make_parent_path(path))
                return FALSE;
 
 #if defined __MINGW32__
     if (mkdir(path) < 0)
-               message("Cannot make directory", path);
+               error("Cannot make directory", path);
         return FALSE;
 #else
        if (mkdir(path, 0777) < 0) {    /* try again */
-               message("Cannot make directory", path);
+               error("Cannot make directory", path);
                return FALSE;
        }
 #endif
@@ -139,11 +137,9 @@ open_with_make_path(name)
        FILE           *fp;
 
        if ((fp = fopen(name, WRITE_BINARY)) == NULL) {
-               errno = 0;
                if (!make_parent_path(name) ||
                    (fp = fopen(name, WRITE_BINARY)) == NULL)
-                       error("Cannot extract", name);
-               errno = 0;
+                       error("Cannot extract a file \"%s\"", name);
        }
        return fp;
 }
@@ -193,7 +189,6 @@ adjust_info(name, hdr)
 #endif /* HAVE_LCHWON */
                                chown(name, uid, gid);
                }
-               errno = 0;
        }
 }
 
@@ -232,7 +227,7 @@ extract_one(afp, hdr)
        }
 
        if (extract_directory)
-               sprintf(name, "%s/%s", extract_directory, q);
+               xsnprintf(name, sizeof(name), "%s/%s", extract_directory, q);
        else
                strcpy(name, q);
 
@@ -241,7 +236,8 @@ extract_one(afp, hdr)
        /* 1999.4.30 t.okamoto */
        for (method = 0;; method++) {
                if (methods[method] == NULL) {
-                       error("Unknown method skiped ...", name);
+                       error("Unknown method \"%.*s\"; \"%s\" will be skiped ...",
+                  5, hdr->method, name);
                        return;
                }
                if (bcmp(hdr->method, methods[method], 5) == 0)
@@ -253,8 +249,8 @@ extract_one(afp, hdr)
 #if 0
                for (method = 0;; method++) {
                        if (methods[method] == NULL) {
-                               error("Unknown method skiped ...", name);
-                               return;
+                error("Unknown method \"%.*s\"; \"%s\" will be skiped ...",
+                      5, hdr->method, name);
                        }
                        if (bcmp(hdr->method, methods[method], 5) == 0)
                                break;
@@ -335,7 +331,6 @@ extract_one(afp, hdr)
 #endif
 
                        unlink(name);
-                       errno = 0;
                        remove_extracting_file_when_interrupt = TRUE;
 
                        if ((fp = open_with_make_path(name)) != NULL) {
@@ -352,9 +347,8 @@ extract_one(afp, hdr)
                                return;
                }
 
-               errno = 0;
                if (hdr->has_crc && crc != hdr->crc)
-                       error("CRC error", name);
+                       error("CRC error: \"%s\"", name);
        }
        else if ((hdr->unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_DIRECTORY
                         || (hdr->unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_SYMLINK
@@ -394,15 +388,15 @@ extract_one(afp, hdr)
                                l_code = symlink(bb2, bb1);
                                if (l_code < 0) {
                                        if (quiet != TRUE)
-                                               warning("Can't make Symbolic Link : ");
+                                               warning("Can't make Symbolic Link \"%s\" -> \"%s\"",
+                                bb1, bb2);
                                }
                                if (quiet != TRUE) {
-                                       printf("Symbolic Link %s -> %s\n", bb1, bb2);
+                                       message("Symbolic Link %s -> %s", bb1, bb2);
                                }
                                strcpy(name, bb1);      /* Symbolic's name set */
 #else
-                               sprintf(buf, "%s -> %s", bb1, bb2);
-                               warning("Can't make Symbolic Link", buf);
+                               warning("Can't make Symbolic Link %s -> %s", bb1, bb2);
                                return;
 #endif
                        } else { /* make directory */
@@ -412,7 +406,7 @@ extract_one(afp, hdr)
                }
        }
        else {
-               error("Unknown information", name);
+               error("Unknown information: \"%s\"", name);
        }
 
        if (!output_to_stdout)
@@ -431,7 +425,7 @@ cmd_extract()
 
        /* open archive file */
        if ((afp = open_old_archive()) == NULL)
-               fatal_error(archive_name);
+               fatal_error("Cannot open archive file \"%s\"", archive_name);
 
        if (archive_is_msdos_sfx1(archive_name))
                skip_msdos_sfx1_code(afp);
index 43237df..6a5aad3 100644 (file)
@@ -321,7 +321,7 @@ cmd_list()
 
        /* open archive file */
        if ((afp = open_old_archive()) == NULL) {
-               error(archive_name, "");
+               error("Cannot open archive \"%s\"", archive_name);
                exit(1);
        }
        if (archive_is_msdos_sfx1(archive_name))
index e9b16fc..8939282 100644 (file)
@@ -42,7 +42,7 @@ make_table(nchar, bitlen, tablebits, table)
                total += weight[i] * count[i];
        }
        if ((total & 0xffff) != 0)
-               error("make_table()", "Bad table (5)\n");
+               error("make_table(): Bad table (5)");
 
        /* shift data for make table. */
        m = 16 - tablebits;
index 3d6efbc..53aef00 100644 (file)
@@ -42,25 +42,25 @@ copyfile(f1, f2, size, crc_flg)     /* return: size of source file */
                        if (xsize == 0)
                                break;
                        if (ferror(f1)) {
-                               fatal_error("file read error\n");
+                               fatal_error("file read error");
                        }
                }
                else {
                        xsize = (size > BUFFERSIZE) ? BUFFERSIZE : size;
                        if (fread(buf, 1, xsize, f1) != xsize) {
-                               fatal_error("file read error\n");
+                               fatal_error("file read error");
                        }
                }
                /* write */
                if (f2) {
                        if (crc_flg == 2 && text_mode) {
                                if (fwrite_txt(buf, xsize, f2)) {
-                                       fatal_error("file write error\n");
+                                       fatal_error("file write error");
                                }
                        }
                        else {
                                if (fwrite(buf, 1, xsize, f2) != xsize) {
-                                       fatal_error("file write error\n");
+                                       fatal_error("file write error");
                                }
                        }
                }
@@ -367,6 +367,28 @@ memset(s, c, n)
 }
 #endif
 
+#include <stdarg.h>
+int
+xsnprintf(char *dest, size_t size, char *fmt, ...)
+{
+    int len;
+    va_list v;
+
+    va_start(v, fmt);
+    len = vsnprintf(dest, size, fmt, v);
+    va_end(v);
+
+    if (len == -1)
+        return -1;
+
+    if (len >= size) {
+        dest[size-1] = 0;
+        return -1;
+    }
+
+    return 0;
+}
+
 /* Local Variables: */
 /* mode:c */
 /* tab-width:4 */