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;
}
}
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)
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);
+ if (mkdir(path) < 0) { /* try again */
+ 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
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;
}
char *name;
LzHeader *hdr;
{
- time_t utimebuf[2];
+ struct utimbuf utimebuf;
/* adjust file stamp */
- utimebuf[0] = utimebuf[1] = hdr->unix_last_modified_stamp;
+ utimebuf.actime = utimebuf.modtime = hdr->unix_last_modified_stamp;
if ((hdr->unix_mode & UNIX_FILE_TYPEMASK) != UNIX_FILE_SYMLINK)
- utime(name, utimebuf);
+ utime(name, &utimebuf);
if (hdr->extend_type == EXTEND_UNIX
|| hdr->extend_type == EXTEND_OS68K
chmod(name, hdr->unix_mode);
#endif
if (!getuid()){
+ uid_t uid = hdr->unix_uid;
+ gid_t gid = hdr->unix_gid;
+
+#if HAVE_GETPWNAM && HAVE_GETGRNAM
+ if (hdr->user[0]) {
+ struct passwd *ent = getpwnam(hdr->user);
+ if (ent) uid = ent->pw_uid;
+ }
+ if (hdr->group[0]) {
+ struct group *ent = getgrnam(hdr->group);
+ if (ent) gid = ent->gr_gid;
+ }
+#endif
+
#if HAVE_LCHOWN
if ((hdr->unix_mode & UNIX_FILE_TYPEMASK) == UNIX_FILE_SYMLINK)
- lchown(name, hdr->unix_uid, hdr->unix_gid);
+ lchown(name, uid, gid);
else
#endif /* HAVE_LCHWON */
- chown(name, hdr->unix_uid, hdr->unix_gid);
+ chown(name, uid, gid);
}
- errno = 0;
}
}
{
FILE *fp; /* output file */
struct stat stbuf;
- char name[257];
+ char name[FILENAME_LENGTH];
int crc;
int method;
boolean save_quiet, save_verbose, up_flag;
}
if (extract_directory)
- sprintf(name, "%s/%s", extract_directory, q);
+ xsnprintf(name, sizeof(name), "%s/%s", extract_directory, q);
else
strcpy(name, q);
/* 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)
+ if (memcmp(hdr->method, methods[method], 5) == 0)
break;
}
#if 0
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)
+ if (memcmp(hdr->method, methods[method], 5) == 0)
break;
}
#endif
reading_filename = archive_name;
- writting_filename = name;
+ writing_filename = name;
if (output_to_stdout || verify_mode) {
if (noexec) {
printf("%s %s\n", verify_mode ? "VERIFY" : "EXTRACT", name);
verbose = TRUE;
}
+#if __MINGW32__
+ {
+ int old_mode;
+ fflush(stdout);
+ old_mode = setmode(fileno(stdout), O_BINARY);
+#endif
+
crc = decode_lzhuf
(afp, stdout, hdr->original_size, hdr->packed_size, name, method);
+#if __MINGW32__
+ fflush(stdout);
+ setmode(fileno(stdout), old_mode);
+ }
+#endif
quiet = save_quiet;
verbose = save_verbose;
}
#endif
unlink(name);
- errno = 0;
remove_extracting_file_when_interrupt = TRUE;
if ((fp = open_with_make_path(name)) != NULL) {
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
|| method == LZHDIRS_METHOD_NUM) {
- /* ¢¬¤³¤ì¤Ç¡¢Symblic Link ¤Ï¡¢Âç¾æÉפ«¡© */
+ /* ¢¬¤³¤ì¤Ç¡¢Symbolic Link ¤Ï¡¢Âç¾æÉפ«¡© */
if (!ignore_directory && !verify_mode) {
if (noexec) {
if (quiet != TRUE)
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 */
}
}
else {
- error("Unknown information", name);
+ error("Unknown information: \"%s\"", name);
}
if (!output_to_stdout)
/* 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);
if (need_file(hdr.name)) {
pos = ftell(afp);
extract_one(afp, &hdr);
- fseek(afp, pos + hdr.packed_size, SEEK_SET);
+ /* when error occurred in extract_one(), should adjust
+ point of file stream */
+ if (afp != stdin)
+ fseek(afp, pos + hdr.packed_size, SEEK_SET);
+ else {
+ /* FIXME: assume that the extract_one() has read
+ packed_size bytes from stdin. */
+ long i = 0;
+ while (i--) fgetc(afp);
+ }
} else {
if (afp != stdin)
fseek(afp, hdr.packed_size, SEEK_CUR);
/* mode:c */
/* tab-width:4 */
/* End: */
+/* vi: set tabstop=4: */