OSDN Git Service

* src/header.c (get_header): use the extend header, user/group name.
[lha/lha.git] / src / header.c
index bcef81e..21995e0 100644 (file)
@@ -22,7 +22,7 @@ char *optional_archive_delim = NULL;
 char *optional_system_delim = NULL;
 int optional_filename_case = NONE;
 
-#if __CYGWIN__
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__hpux)
 /* Cygwin, HP-UX and other UNIX are able to use SJIS as native code. */
 int default_system_kanji_code = CODE_SJIS;
 #else
@@ -280,8 +280,8 @@ filename_conv(name, len, size,
                        name[i] = toupper(name[i]);
             continue;
         }
-        if (case_to == TO_LOWER && islower(name[i])) {
-                       name[i] = toupper(name[i]);
+        if (case_to == TO_LOWER && isupper(name[i])) {
+                       name[i] = tolower(name[i]);
             continue;
         }
        }
@@ -374,12 +374,12 @@ gettz()
 /* ------------------------------------------------------------------------ */
 #if !defined(HAVE_TZSET) && !defined(HAVE_FTIME)       /* maybe defined(HAVE_GETTIMEOFDAY) */
 {
-#ifdef HAVE_TM_GMTOFF
+#ifdef HAVE_STRUCT_TM_TM_GMTOFF
        time_t tt;
 
        time(&tt);
        return -localtime(&tt)->tm_gmtoff;
-#else /* HAVE_TM_GMTOFF */
+#else /* HAVE_STRUCT_TM_TM_GMTOFF */
        struct timeval  tp;
        struct timezone tzp;
        gettimeofday(&tp, &tzp);/* specific to 4.3BSD */
@@ -388,7 +388,7 @@ gettz()
         * 60L : 0));
         */
        return (tzp.tz_minuteswest * 60L);
-#endif /* HAVE_TM_GMTOFF */
+#endif /* HAVE_STRUCT_TM_TM_GMTOFF */
 }
 #endif
 #endif                         /* defined(HAVE_FTIME) || defined(HAVE_GETTIMEOFDAY) ||
@@ -658,7 +658,7 @@ get_header(fp, hdr)
                                for (i = 0; i < header_size - 3; i++)
                                        hdr->name[i] = (char) get_byte();
                                hdr->name[header_size - 3] = '\0';
-                               name_length = header_size - 3; /* modified by Koji Arai */
+                               name_length = header_size - 3;
                                break;
                        case 2:
                                /*
@@ -698,13 +698,17 @@ get_header(fp, hdr)
                                /*
                                 * UNIX group name
                                 */
-                               setup_get(get_ptr + header_size - 3);
+                for (i = 0; i < header_size - 3; i++)
+                    hdr->group[i] = get_byte();
+                hdr->group[i] = '\0';
                                break;
                        case 0x53:
                                /*
                                 * UNIX user name
                                 */
-                               setup_get(get_ptr + header_size - 3);
+                for (i = 0; i < header_size - 3; i++)
+                    hdr->user[i] = get_byte();
+                hdr->user[i] = '\0';
                                break;
                        case 0x54:
                                /*
@@ -847,6 +851,28 @@ init_header(name, v_stat, hdr)
        hdr->unix_uid = v_stat->st_uid;
        hdr->unix_gid = v_stat->st_gid;
 
+#if HAVE_GETPWUID
+    {
+        struct passwd *ent = getpwuid(hdr->unix_uid);
+
+        if (ent) {
+            strncpy(hdr->user, ent->pw_name, sizeof(hdr->user));
+            if (hdr->user[sizeof(hdr->user)-1])
+                hdr->user[sizeof(hdr->user)-1] = 0;
+        }
+    }
+#endif
+#if HAVE_GETGRGID
+    {
+        struct group *ent = getgrgid(hdr->unix_gid);
+
+        if (ent) {
+            strncpy(hdr->group, ent->gr_name, sizeof(hdr->group));
+            if (hdr->group[sizeof(hdr->group)-1])
+                hdr->group[sizeof(hdr->group)-1] = 0;
+        }
+    }
+#endif
        if (is_directory(v_stat)) {
                bcopy(LZHDIRS_METHOD, hdr->method, METHOD_TYPE_STRAGE);
                hdr->attribute = GENERIC_DIRECTORY_ATTRIBUTE;
@@ -986,6 +1012,20 @@ write_header(nafp, hdr)
                        put_word(hdr->unix_gid);
                        put_word(hdr->unix_uid);
 
+            {
+                int i, len = strlen(hdr->group);
+                put_word(len + 3);
+                put_byte(0x52);        /* group name */
+                for (i = 0; i < len; i++)
+                    put_byte(hdr->group[i]);
+
+                len = strlen(hdr->user);
+                put_word(len + 3);
+                put_byte(0x53);        /* user name */
+                for (i = 0; i < len; i++)
+                    put_byte(hdr->user[i]);
+            }
+
                        if (p = (char *) strrchr(hdr->name, DELIM2)) {
                                int             i;
 
@@ -1081,3 +1121,4 @@ sjis2euc(int *p1, int *p2)
 /* tab-width:4 */
 /* compile-command:"gcc -c header.c" */
 /* End: */
+/* vi: set tabstop=4: */