Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 620470 | Differences between
and this patch

Collapse All | Expand All

(-)unzip-6.0.orig/unix/unix.c (+102 lines)
Lines 30-35 Link Here
30
#define UNZIP_INTERNAL
30
#define UNZIP_INTERNAL
31
#include "unzip.h"
31
#include "unzip.h"
32
32
33
#include <iconv.h>
34
#include <langinfo.h>
35
33
#ifdef SCO_XENIX
36
#ifdef SCO_XENIX
34
#  define SYSNDIR
37
#  define SYSNDIR
35
#else  /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
38
#else  /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
Lines 1874-1876 Link Here
1874
    }
1877
    }
1875
}
1878
}
1876
#endif /* QLZIP */
1879
#endif /* QLZIP */
1880
1881
1882
typedef struct {
1883
    char *local_charset;
1884
    char *archive_charset;
1885
} CHARSET_MAP;
1886
1887
/* A mapping of local <-> archive charsets used by default to convert filenames
1888
 * of DOS/Windows Zip archives. Currently very basic. */
1889
static CHARSET_MAP dos_charset_map[] = {
1890
    { "ANSI_X3.4-1968", "CP850" },
1891
    { "ISO-8859-1", "CP850" },
1892
    { "CP1252", "CP850" },
1893
    { "UTF-8", "CP866" },
1894
    { "KOI8-R", "CP866" },
1895
    { "KOI8-U", "CP866" },
1896
    { "ISO-8859-5", "CP866" }
1897
};
1898
1899
char OEM_CP[MAX_CP_NAME] = "";
1900
char ISO_CP[MAX_CP_NAME] = "";
1901
1902
/* Try to guess the default value of OEM_CP based on the current locale.
1903
 * ISO_CP is left alone for now. */
1904
void init_conversion_charsets()
1905
{
1906
    const char *local_charset;
1907
    int i;
1908
1909
    /* Make a guess only if OEM_CP not already set. */ 
1910
    if(*OEM_CP == '\0') {
1911
    	local_charset = nl_langinfo(CODESET);
1912
    	for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
1913
    		if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
1914
    			strncpy(OEM_CP, dos_charset_map[i].archive_charset,
1915
    					sizeof(OEM_CP));
1916
    			break;
1917
    		}
1918
    }
1919
}
1920
1921
/* Convert a string from one encoding to the current locale using iconv().
1922
 * Be as non-intrusive as possible. If error is encountered during covertion
1923
 * just leave the string intact. */
1924
static void charset_to_intern(char *string, char *from_charset)
1925
{
1926
    iconv_t cd;
1927
    char *s,*d, *buf;
1928
    size_t slen, dlen, buflen;
1929
    const char *local_charset;
1930
1931
    if(*from_charset == '\0')
1932
    	return;
1933
1934
    buf = NULL;
1935
    local_charset = nl_langinfo(CODESET);
1936
1937
    if((cd = iconv_open(local_charset, from_charset)) == (iconv_t)-1)
1938
        return;
1939
1940
    slen = strlen(string);
1941
    s = string;
1942
1943
    /*  Make sure OUTBUFSIZ + 1 never ends up smaller than FILNAMSIZ
1944
     *  as this function also gets called with G.outbuf in fileio.c
1945
     */
1946
    buflen = FILNAMSIZ;
1947
    if (OUTBUFSIZ + 1 < FILNAMSIZ)
1948
    {
1949
        buflen = OUTBUFSIZ + 1;
1950
    }
1951
1952
    d = buf = malloc(buflen);
1953
    if(!d)
1954
    	goto cleanup;
1955
1956
    bzero(buf,buflen);
1957
    dlen = buflen - 1;
1958
1959
    if(iconv(cd, &s, &slen, &d, &dlen) == (size_t)-1)
1960
    	goto cleanup;
1961
    strncpy(string, buf, buflen);
1962
1963
    cleanup:
1964
    free(buf);
1965
    iconv_close(cd);
1966
}
1967
1968
/* Convert a string from OEM_CP to the current locale charset. */
1969
inline void oem_intern(char *string)
1970
{
1971
    charset_to_intern(string, OEM_CP);
1972
}
1973
1974
/* Convert a string from ISO_CP to the current locale charset. */
1975
inline void iso_intern(char *string)
1976
{
1977
    charset_to_intern(string, ISO_CP);
1978
}
(-)unzip-6.0.orig/unix/unxcfg.h (+26 lines)
Lines 228-231 Link Here
228
/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
228
/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
229
/*    and notfirstcall are used by do_wild().                          */
229
/*    and notfirstcall are used by do_wild().                          */
230
230
231
232
#define MAX_CP_NAME 25 
233
   
234
#ifdef SETLOCALE
235
#  undef SETLOCALE
236
#endif
237
#define SETLOCALE(category, locale) setlocale(category, locale)
238
#include <locale.h>
239
   
240
#ifdef _ISO_INTERN
241
#  undef _ISO_INTERN
242
#endif
243
#define _ISO_INTERN(str1) iso_intern(str1)
244
245
#ifdef _OEM_INTERN
246
#  undef _OEM_INTERN
247
#endif
248
#ifndef IZ_OEM2ISO_ARRAY
249
#  define IZ_OEM2ISO_ARRAY
250
#endif
251
#define _OEM_INTERN(str1) oem_intern(str1)
252
253
void iso_intern(char *);
254
void oem_intern(char *);
255
void init_conversion_charsets(void);
256
   
231
#endif /* !__unxcfg_h */
257
#endif /* !__unxcfg_h */
(-)unzip-6.0.orig/unzip.c (+88 lines)
Lines 327-337 Link Here
327
  -2  just filenames but allow -h/-t/-z  -l  long Unix \"ls -l\" format\n\
327
  -2  just filenames but allow -h/-t/-z  -l  long Unix \"ls -l\" format\n\
328
                                         -v  verbose, multi-page format\n";
328
                                         -v  verbose, multi-page format\n";
329
329
330
#ifndef UNIX
330
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
331
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
331
  -h  print header line       -t  print totals for listed files or for all\n\
332
  -h  print header line       -t  print totals for listed files or for all\n\
332
  -z  print zipfile comment   -T  print file times in sortable decimal format\
333
  -z  print zipfile comment   -T  print file times in sortable decimal format\
333
\n  -C  be case-insensitive   %s\
334
\n  -C  be case-insensitive   %s\
334
  -x  exclude filenames that follow from listing\n";
335
  -x  exclude filenames that follow from listing\n";
336
#else /* UNIX */
337
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
338
  -h  print header line       -t  print totals for listed files or for all\n\
339
  -z  print zipfile comment  %c-T%c print file times in sortable decimal format\
340
\n %c-C%c be case-insensitive   %s\
341
  -x  exclude filenames that follow from listing\n\
342
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives\n\
343
  -I CHARSET  specify a character encoding for UNIX and other archives\n";
344
#endif /* !UNIX */
335
#ifdef MORE
345
#ifdef MORE
336
   static ZCONST char Far ZipInfoUsageLine4[] =
346
   static ZCONST char Far ZipInfoUsageLine4[] =
337
     "  -M  page output through built-in \"more\"\n";
347
     "  -M  page output through built-in \"more\"\n";
Lines 664-669 Link Here
664
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields\n\
674
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields\n\
665
  -C  match filenames case-insensitively     -L  make (some) names \
675
  -C  match filenames case-insensitively     -L  make (some) names \
666
lowercase\n %-42s  -V  retain VMS version numbers\n%s";
676
lowercase\n %-42s  -V  retain VMS version numbers\n%s";
677
#elif (defined UNIX)
678
static ZCONST char Far UnzipUsageLine4[] = "\
679
modifiers:\n\
680
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)\n\
681
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files\n\
682
  -j  junk paths (do not make directories)   -aa treat ALL files as text\n\
683
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields\n\
684
  -C  match filenames case-insensitively     -L  make (some) names \
685
lowercase\n %-42s  -V  retain VMS version numbers\n%s\
686
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives\n\
687
  -I CHARSET  specify a character encoding for UNIX and other archives\n\n";
667
#else /* !VMS */
688
#else /* !VMS */
668
static ZCONST char Far UnzipUsageLine4[] = "\
689
static ZCONST char Far UnzipUsageLine4[] = "\
669
modifiers:\n\
690
modifiers:\n\
Lines 802-807 Link Here
802
#endif /* UNICODE_SUPPORT */
823
#endif /* UNICODE_SUPPORT */
803
824
804
825
826
#ifdef UNIX
827
    init_conversion_charsets();
828
#endif
829
805
#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))
830
#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))
806
    extern void DebugMalloc(void);
831
    extern void DebugMalloc(void);
807
832
Lines 1335-1340 Link Here
1335
    argc = *pargc;
1360
    argc = *pargc;
1336
    argv = *pargv;
1361
    argv = *pargv;
1337
1362
1363
#ifdef UNIX
1364
    extern char OEM_CP[MAX_CP_NAME];
1365
    extern char ISO_CP[MAX_CP_NAME];
1366
#endif
1367
    
1338
    while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
1368
    while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
1339
        s = *argv + 1;
1369
        s = *argv + 1;
1340
        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
1370
        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
Lines 1516-1521 Link Here
1516
                    }
1546
                    }
1517
                    break;
1547
                    break;
1518
#endif  /* MACOS */
1548
#endif  /* MACOS */
1549
#ifdef UNIX
1550
    			case ('I'):
1551
                    if (negative) {
1552
                        Info(slide, 0x401, ((char *)slide,
1553
                          "error:  encodings can't be negated"));
1554
                        return(PK_PARAM);
1555
    				} else {
1556
    					if(*s) { /* Handle the -Icharset case */
1557
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
1558
    						if(*s == '-') { 
1559
    	                        Info(slide, 0x401, ((char *)slide,
1560
        		                  "error:  a valid character encoding should follow the -I argument"));
1561
    	                        return(PK_PARAM); 
1562
    						}
1563
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
1564
    					} else { /* -I charset */
1565
    						++argv;
1566
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
1567
    	                        Info(slide, 0x401, ((char *)slide,
1568
        		                  "error:  a valid character encoding should follow the -I argument"));
1569
    	                        return(PK_PARAM); 
1570
    						}
1571
    						s = *argv;
1572
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
1573
    					}
1574
    					while(*(++s)); /* No params straight after charset name */
1575
    				}
1576
    				break;
1577
#endif /* ?UNIX */
1519
                case ('j'):    /* junk pathnames/directory structure */
1578
                case ('j'):    /* junk pathnames/directory structure */
1520
                    if (negative)
1579
                    if (negative)
1521
                        uO.jflag = FALSE, negative = 0;
1580
                        uO.jflag = FALSE, negative = 0;
Lines 1591-1596 Link Here
1591
                    } else
1650
                    } else
1592
                        ++uO.overwrite_all;
1651
                        ++uO.overwrite_all;
1593
                    break;
1652
                    break;
1653
#ifdef UNIX
1654
    			case ('O'):
1655
                    if (negative) {
1656
                        Info(slide, 0x401, ((char *)slide,
1657
                          "error:  encodings can't be negated"));
1658
                        return(PK_PARAM);
1659
    				} else {
1660
    					if(*s) { /* Handle the -Ocharset case */
1661
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
1662
    						if(*s == '-') { 
1663
    	                        Info(slide, 0x401, ((char *)slide,
1664
        		                  "error:  a valid character encoding should follow the -I argument"));
1665
    	                        return(PK_PARAM); 
1666
    						}
1667
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
1668
    					} else { /* -O charset */
1669
    						++argv;
1670
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
1671
    	                        Info(slide, 0x401, ((char *)slide,
1672
        		                  "error:  a valid character encoding should follow the -O argument"));
1673
    	                        return(PK_PARAM); 
1674
    						}
1675
    						s = *argv;
1676
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
1677
    					}
1678
    					while(*(++s)); /* No params straight after charset name */
1679
    				}
1680
    				break;
1681
#endif /* ?UNIX */
1594
                case ('p'):    /* pipes:  extract to stdout, no messages */
1682
                case ('p'):    /* pipes:  extract to stdout, no messages */
1595
                    if (negative) {
1683
                    if (negative) {
1596
                        uO.cflag = FALSE;
1684
                        uO.cflag = FALSE;
(-)unzip-6.0.orig/unzpriv.h (-1 / +1 lines)
Lines 3008-3014 Link Here
3008
         !(((islochdr) || (isuxatt)) && \
3008
         !(((islochdr) || (isuxatt)) && \
3009
           ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
3009
           ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
3010
        (hostnum) == FS_HPFS_ || \
3010
        (hostnum) == FS_HPFS_ || \
3011
        ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
3011
        ((hostnum) == FS_NTFS_ /* && (hostver) == 50 */ )) { \
3012
        _OEM_INTERN((string)); \
3012
        _OEM_INTERN((string)); \
3013
    } else { \
3013
    } else { \
3014
        _ISO_INTERN((string)); \
3014
        _ISO_INTERN((string)); \
(-)unzip-6.0.orig/zipinfo.c (+62 lines)
Lines 457-462 Link Here
457
    int    tflag_slm=TRUE, tflag_2v=FALSE;
457
    int    tflag_slm=TRUE, tflag_2v=FALSE;
458
    int    explicit_h=FALSE, explicit_t=FALSE;
458
    int    explicit_h=FALSE, explicit_t=FALSE;
459
459
460
#ifdef UNIX
461
    extern char OEM_CP[MAX_CP_NAME];
462
    extern char ISO_CP[MAX_CP_NAME];
463
#endif
460
464
461
#ifdef MACOS
465
#ifdef MACOS
462
    uO.lflag = LFLAG;         /* reset default on each call */
466
    uO.lflag = LFLAG;         /* reset default on each call */
Lines 501-506 Link Here
501
                            uO.lflag = 0;
505
                            uO.lflag = 0;
502
                    }
506
                    }
503
                    break;
507
                    break;
508
#ifdef UNIX
509
    			case ('I'):
510
                    if (negative) {
511
                        Info(slide, 0x401, ((char *)slide,
512
                          "error:  encodings can't be negated"));
513
                        return(PK_PARAM);
514
    				} else {
515
    					if(*s) { /* Handle the -Icharset case */
516
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
517
    						if(*s == '-') { 
518
    	                        Info(slide, 0x401, ((char *)slide,
519
        		                  "error:  a valid character encoding should follow the -I argument"));
520
    	                        return(PK_PARAM); 
521
    						}
522
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
523
    					} else { /* -I charset */
524
    						++argv;
525
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
526
    	                        Info(slide, 0x401, ((char *)slide,
527
        		                  "error:  a valid character encoding should follow the -I argument"));
528
    	                        return(PK_PARAM); 
529
    						}
530
    						s = *argv;
531
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
532
    					}
533
    					while(*(++s)); /* No params straight after charset name */
534
    				}
535
    				break;
536
#endif /* ?UNIX */
504
                case 'l':      /* longer form of "ls -l" type listing */
537
                case 'l':      /* longer form of "ls -l" type listing */
505
                    if (negative)
538
                    if (negative)
506
                        uO.lflag = -2, negative = 0;
539
                        uO.lflag = -2, negative = 0;
Lines 521-526 Link Here
521
                        G.M_flag = TRUE;
554
                        G.M_flag = TRUE;
522
                    break;
555
                    break;
523
#endif
556
#endif
557
#ifdef UNIX
558
    			case ('O'):
559
                    if (negative) {
560
                        Info(slide, 0x401, ((char *)slide,
561
                          "error:  encodings can't be negated"));
562
                        return(PK_PARAM);
563
    				} else {
564
    					if(*s) { /* Handle the -Ocharset case */
565
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
566
    						if(*s == '-') { 
567
    	                        Info(slide, 0x401, ((char *)slide,
568
        		                  "error:  a valid character encoding should follow the -I argument"));
569
    	                        return(PK_PARAM); 
570
    						}
571
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
572
    					} else { /* -O charset */
573
    						++argv;
574
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
575
    	                        Info(slide, 0x401, ((char *)slide,
576
        		                  "error:  a valid character encoding should follow the -O argument"));
577
    	                        return(PK_PARAM); 
578
    						}
579
    						s = *argv;
580
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
581
    					}
582
    					while(*(++s)); /* No params straight after charset name */
583
    				}
584
    				break;
585
#endif /* ?UNIX */
524
                case 's':      /* default:  shorter "ls -l" type listing */
586
                case 's':      /* default:  shorter "ls -l" type listing */
525
                    if (negative)
587
                    if (negative)
526
                        uO.lflag = -2, negative = 0;
588
                        uO.lflag = -2, negative = 0;

Return to bug 620470