]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-locale.patch
- typo
[packages/rpm.git] / rpm-locale.patch
1 diff -ur -x Makefile -x Makefile.in -x configure -x po rpm-4.4.2.org/rpmio/Makefile.am rpm-4.4.2/rpmio/Makefile.am
2 --- rpm-4.4.2.org/rpmio/Makefile.am     2007-02-13 20:51:36.290623000 +0100
3 +++ rpm-4.4.2/rpmio/Makefile.am 2007-02-13 20:42:52.362623000 +0100
4 @@ -31,7 +31,7 @@
5  librpmio_la_SOURCES = \
6         LzmaDecode.c argv.c digest.c fts.c macro.c rpmdav.c \
7         rpmhook.c rpmio.c rpmlog.c rpmlua.c rpmmalloc.c \
8 -       rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c stubs.c url.c ugid.c
9 +       rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c strtolocale.c stubs.c url.c ugid.c
10  librpmio_la_LDFLAGS = -release 4.4 $(LDFLAGS) \
11         @WITH_BEECRYPT_LIB@ \
12         @WITH_NEON_LIB@ \
13 diff -ur -x Makefile -x Makefile.in -x configure -x po rpm-4.4.2.org/rpmio/rpmio.h rpm-4.4.2/rpmio/rpmio.h
14 --- rpm-4.4.2.org/rpmio/rpmio.h 2007-02-13 20:51:36.290623000 +0100
15 +++ rpm-4.4.2/rpmio/rpmio.h     2007-02-13 20:43:52.742623000 +0100
16 @@ -709,6 +709,13 @@
17   */
18  int xstrncasecmp(const char *s1, const char * s2, size_t n)    /*@*/;
19  
20 +/** \ingroup rpmio
21 + * Force encoding of string.
22 + */
23 +/*@only@*/ /*@null@*/
24 +const char * xstrtolocale(/*@only@*/ const char *str)
25 +        /*@modifies *str @*/;
26 +
27  #ifdef __cplusplus
28  }
29  #endif
30
31 --- /dev/null   2007-02-07 08:10:39.238623000 +0100
32 +++ rpm-4.4.2/rpmio/strtolocale.c       2007-02-13 20:42:06.650623000 +0100
33 @@ -0,0 +1,65 @@
34 +/** \ingroup rpmio
35 + * \file rpmio/strtolocale.c
36 + */
37 +
38 +#include "system.h"
39 +#include <langinfo.h>
40 +#include <iconv.h>
41 +#include "debug.h"
42 +
43 +static char *locale_encoding = NULL;
44 +static int locale_encoding_is_utf8;
45 +
46 +const char * xstrtolocale(const char *str)
47 +{
48 +    iconv_t cd;
49 +    size_t src_size, dest_size;
50 +    char *result, *src, *dest;
51 +
52 +    if (locale_encoding == NULL) {
53 +        const char *encoding = nl_langinfo(CODESET);
54 +        locale_encoding = xmalloc(strlen(encoding) + 11);
55 +        sprintf(locale_encoding, "%s//TRANSLIT", encoding);
56 +        locale_encoding_is_utf8 = strcasecmp(encoding, "UTF-8") == 0;
57 +    }
58 +
59 +    if (!str || !*str || locale_encoding_is_utf8)
60 +       return str;
61 +
62 +    cd = iconv_open(locale_encoding, "UTF-8");
63 +    if (cd == (iconv_t)-1)
64 +        return str;
65 +
66 +    src_size = strlen(str);
67 +    dest_size = src_size + 1;
68 +    result = xmalloc(dest_size);
69 +    src = (char *)str;
70 +    dest = result;
71 +    for(;;) {
72 +        size_t status = iconv(cd, &src, &src_size, &dest, &dest_size);
73 +        if (status == (size_t)-1) {
74 +            size_t dest_offset;
75 +            if (errno != E2BIG) {
76 +                free(result);
77 +                iconv_close(cd);
78 +                return str;
79 +            }
80 +            dest_offset = dest - result;
81 +            dest_size += 16;
82 +            result = xrealloc(result, dest_offset + dest_size);
83 +            dest = result + dest_offset;
84 +        } else if (src_size == 0) {
85 +            if (src == NULL) break;
86 +            src = NULL;
87 +        }
88 +    }
89 +    iconv_close(cd);
90 +    free((void *)str);
91 +    if (dest_size == 0) {
92 +        size_t dest_offset = dest - result;
93 +        result = xrealloc(result, dest_offset + 1);
94 +        dest = result + dest_offset;
95 +    }
96 +    *dest = '\0';
97 +    return result;
98 +}
99 --- rpm-4.4.2.org/lib/formats.c 2005-01-26 05:46:54.000000000 +0100
100 +++ rpm-4.4.2/lib/formats.c     2007-02-13 20:50:01.082623000 +0100
101 @@ -301,6 +301,7 @@
102      char * t, * te;
103      unsigned long anint = 0;
104      int xx;
105 +    int freeit = 0;
106  
107  /*@-branchstate@*/
108      switch (type) {
109 @@ -308,6 +309,10 @@
110      case RPM_STRING_TYPE:
111         s = data;
112         xtag = "string";
113 +       /* XXX Force utf8 strings. */
114 +       s = xstrdup(s);
115 +       s = xstrtolocale(s);
116 +       freeit = 1;
117         break;
118      case RPM_BIN_TYPE:
119      {  int cpl = b64encode_chars_per_line;
120 @@ -321,6 +326,7 @@
121         b64encode_chars_per_line = cpl;
122  /*@=mods@*/
123         xtag = "base64";
124 +       freeit = 1;
125      }  break;
126      case RPM_CHAR_TYPE:
127      case RPM_INT8_TYPE:
128 @@ -367,7 +373,7 @@
129  
130      /* XXX s was malloc'd */
131  /*@-branchstate@*/
132 -    if (!strcmp(xtag, "base64"))
133 +    if (freeit)
134         s = _free(s);
135  /*@=branchstate@*/
136  
137 @@ -1077,6 +1083,7 @@
138  
139      if (rc && (*data) != NULL) {
140         *data = xstrdup(*data);
141 +       *data = xstrtolocale(*data);
142         *freeData = 1;
143         return 0;
144      }
This page took 0.042264 seconds and 3 git commands to generate.