aboutsummaryrefslogtreecommitdiffstats
path: root/jnlib
diff options
context:
space:
mode:
Diffstat (limited to 'jnlib')
-rw-r--r--jnlib/stringhelp.c75
-rw-r--r--jnlib/w32-gettext.c47
-rw-r--r--jnlib/w32-reg.c39
3 files changed, 85 insertions, 76 deletions
diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c
index 3173ebc15..c43b120d6 100644
--- a/jnlib/stringhelp.c
+++ b/jnlib/stringhelp.c
@@ -30,6 +30,9 @@
#include <unistd.h>
#include <sys/types.h>
#ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+# endif
# include <windows.h>
#endif
@@ -230,7 +233,7 @@ length_sans_trailing_chars (const unsigned char *line, size_t len,
{
const unsigned char *p, *mark;
size_t n;
-
+
for( mark=NULL, p=line, n=0; n < len; n++, p++ )
{
if (strchr (trimchars, *p ))
@@ -241,8 +244,8 @@ length_sans_trailing_chars (const unsigned char *line, size_t len,
else
mark = NULL;
}
-
- if (mark)
+
+ if (mark)
return mark - line;
return len;
}
@@ -355,16 +358,16 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
{
const char *argv[32];
int argc;
- size_t n;
+ size_t n;
int skip = 1;
char *home_buffer = NULL;
- char *name, *home, *p;
-
- n = strlen (first_part) + 1;
+ char *name, *home, *p;
+
+ n = strlen (first_part) + 1;
argc = 0;
- while ( (argv[argc] = va_arg (arg_ptr, const char *)) )
+ while ( (argv[argc] = va_arg (arg_ptr, const char *)) )
{
- n += strlen (argv[argc]) + 1;
+ n += strlen (argv[argc]) + 1;
if (argc >= DIM (argv)-1)
{
if (xmode)
@@ -372,11 +375,11 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
errno = EINVAL;
return NULL;
}
- argc++;
+ argc++;
}
n++;
-
- home = NULL;
+
+ home = NULL;
if (*first_part == '~')
{
if (first_part[1] == '/' || !first_part[1])
@@ -386,13 +389,13 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
if (!home)
home = home_buffer = get_pwdir (xmode, NULL);
if (home && *home)
- n += strlen (home);
+ n += strlen (home);
}
else
{
/* This is the "~username/" or "~username" case. */
char *user;
-
+
if (xmode)
user = jnlib_xstrdup (first_part+1);
else
@@ -405,7 +408,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
if (p)
*p = 0;
skip = 1 + strlen (user);
-
+
home = home_buffer = get_pwdir (xmode, user);
jnlib_free (user);
if (home)
@@ -426,7 +429,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
return NULL;
}
}
-
+
if (home)
p = stpcpy (stpcpy (name, home), first_part + skip);
else
@@ -481,9 +484,9 @@ int
compare_filenames (const char *a, const char *b)
{
#ifdef HAVE_DRIVE_LETTERS
- for ( ; *a && *b; a++, b++ )
+ for ( ; *a && *b; a++, b++ )
{
- if (*a != *b
+ if (*a != *b
&& (toupper (*(const unsigned char*)a)
!= toupper (*(const unsigned char*)b) )
&& !((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/')))
@@ -492,7 +495,7 @@ compare_filenames (const char *a, const char *b)
if ((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/'))
return 0;
else
- return (toupper (*(const unsigned char*)a)
+ return (toupper (*(const unsigned char*)a)
- toupper (*(const unsigned char*)b));
#else
return strcmp(a,b);
@@ -531,7 +534,7 @@ hextobyte (const char *s)
/* Print a BUFFER to stream FP while replacing all control characters
and the characters DELIM and DELIM2 with standard C escape
sequences. Returns the number of characters printed. */
-size_t
+size_t
print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
int delim, int delim2)
{
@@ -540,9 +543,9 @@ print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
for (; length; length--, p++, count++)
{
- if (*p < 0x20
+ if (*p < 0x20
|| *p == 0x7f
- || *p == delim
+ || *p == delim
|| *p == delim2
|| ((delim || delim2) && *p=='\\'))
{
@@ -595,7 +598,7 @@ print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
}
/* Same as print_sanitized_buffer2 but with just one delimiter. */
-size_t
+size_t
print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
int delim)
{
@@ -603,7 +606,7 @@ print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
}
-size_t
+size_t
print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
size_t length, int delim)
{
@@ -611,7 +614,7 @@ print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
size_t i;
/* We can handle plain ascii simpler, so check for it first. */
- for (i=0; i < length; i++ )
+ for (i=0; i < length; i++ )
{
if ( (p[i] & 0x80) )
break;
@@ -630,20 +633,20 @@ print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
}
-size_t
+size_t
print_sanitized_string2 (FILE *fp, const char *string, int delim, int delim2)
{
return string? print_sanitized_buffer2 (fp, string, strlen (string),
delim, delim2):0;
}
-size_t
+size_t
print_sanitized_string (FILE *fp, const char *string, int delim)
{
return string? print_sanitized_buffer (fp, string, strlen (string), delim):0;
}
-size_t
+size_t
print_sanitized_utf8_string (FILE *fp, const char *string, int delim)
{
return string? print_sanitized_utf8_buffer (fp,
@@ -663,7 +666,7 @@ sanitize_buffer (const void *p_arg, size_t n, int delim)
char *buffer, *d;
/* First count length. */
- for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ )
+ for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ )
{
if ( *p < 0x20 || *p == 0x7f || *p == delim || (delim && *p=='\\'))
{
@@ -735,13 +738,13 @@ const char *
w32_strerror (int ec)
{
static char strerr[256];
-
+
if (ec == -1)
ec = (int)GetLastError ();
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
strerr, DIM (strerr)-1, NULL);
- return strerr;
+ return strerr;
}
#endif /*HAVE_W32_SYSTEM*/
@@ -762,7 +765,7 @@ ascii_islower (int c)
return c >= 'a' && c <= 'z';
}
-int
+int
ascii_toupper (int c)
{
if (c >= 'a' && c <= 'z')
@@ -770,7 +773,7 @@ ascii_toupper (int c)
return c;
}
-int
+int
ascii_tolower (int c)
{
if (c >= 'A' && c <= 'Z')
@@ -792,7 +795,7 @@ ascii_strcasecmp( const char *a, const char *b )
return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
}
-int
+int
ascii_strncasecmp (const char *a, const char *b, size_t n)
{
const unsigned char *p1 = (const unsigned char *)a;
@@ -814,7 +817,7 @@ ascii_strncasecmp (const char *a, const char *b, size_t n)
++p2;
}
while (c1 == c2);
-
+
return c1 - c2;
}
@@ -860,7 +863,7 @@ ascii_memcasemem (const void *haystack, size_t nhaystack,
{
const char *a = haystack;
const char *b = a + nhaystack - nneedle;
-
+
for (; a <= b; a++)
{
if ( !ascii_memcasecmp (a, needle, nneedle) )
diff --git a/jnlib/w32-gettext.c b/jnlib/w32-gettext.c
index 834b2aa17..14cb1e1be 100644
--- a/jnlib/w32-gettext.c
+++ b/jnlib/w32-gettext.c
@@ -6,12 +6,12 @@
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
-
+
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
@@ -32,6 +32,9 @@
#include <sys/stat.h>
#include <stdint.h>
#include <locale.h>
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
#include <windows.h>
#ifdef JNLIB_IN_JNLIB
@@ -595,8 +598,8 @@
#ifndef SUBLANG_UZBEK_CYRILLIC
#define SUBLANG_UZBEK_CYRILLIC 0x02
#endif
-
-/* Return an XPG style locale name
+
+/* Return an XPG style locale name
language[_territory[.codeset]][@modifier].
Don't even bother determining the codeset; it's not useful in this
context, because message catalogs are not specific to a single
@@ -1034,7 +1037,7 @@ hash_string( const char *str_param )
{
unsigned long int hval, g;
const char *str = str_param;
-
+
hval = 0;
while (*str != '\0')
{
@@ -1158,7 +1161,7 @@ free_domain (struct loaded_domain *domain)
jnlib_free (domain);
}
-
+
static struct loaded_domain *
load_domain (const char *filename)
{
@@ -1169,7 +1172,7 @@ load_domain (const char *filename)
struct loaded_domain *domain = NULL;
size_t to_read;
char *read_ptr;
-
+
fp = fopen (filename, "rb");
if (!fp)
return NULL;
@@ -1225,7 +1228,7 @@ load_domain (const char *filename)
domain->data = (char *) data;
domain->data_native = (char *) data + size;
domain->must_swap = data->magic != MAGIC;
-
+
/* Fill in the information about the available tables. */
switch (SWAPIT (domain->must_swap, data->revision))
{
@@ -1276,7 +1279,7 @@ utf8_to_wchar (const char *string, size_t length, size_t *retlen)
return NULL;
nbytes = (size_t)(n+1) * sizeof(*result);
- if (nbytes / sizeof(*result) != (n+1))
+ if (nbytes / sizeof(*result) != (n+1))
{
errno = ENOMEM;
return NULL;
@@ -1465,17 +1468,17 @@ get_string (struct loaded_domain *domain, uint32_t idx,
+ SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
translen = SWAPIT(domain->must_swap, domain->trans_tab[idx].length);
}
- else if (!domain->mapped[idx])
+ else if (!domain->mapped[idx])
{
/* Not yet mapped. Map from utf-8 to native encoding now. */
const char *p_utf8;
size_t plen_utf8, buflen;
char *buf;
- p_utf8 = (domain->data
+ p_utf8 = (domain->data
+ SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
plen_utf8 = SWAPIT(domain->must_swap, domain->trans_tab[idx].length);
-
+
buf = utf8_to_native (p_utf8, plen_utf8, &buflen);
if (!buf)
{
@@ -1487,7 +1490,7 @@ get_string (struct loaded_domain *domain, uint32_t idx,
/* Copy into the DATA_NATIVE area. */
char *p_tmp;
- p_tmp = (domain->data_native
+ p_tmp = (domain->data_native
+ SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
memcpy (p_tmp, buf, buflen);
domain->mapped[idx] = buflen;
@@ -1523,7 +1526,7 @@ get_string (struct loaded_domain *domain, uint32_t idx,
}
jnlib_free (buf);
}
- else if (domain->mapped[idx] == 1)
+ else if (domain->mapped[idx] == 1)
{
/* The translated string is in the overflow_space. */
for (os=domain->overflow_space; os; os = os->next)
@@ -1540,8 +1543,8 @@ get_string (struct loaded_domain *domain, uint32_t idx,
translen = 0;
}
}
- else
- {
+ else
+ {
trans = (domain->data_native
+ SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
translen = domain->mapped[idx];
@@ -1559,7 +1562,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural)
{
struct loaded_domain *domain;
uint32_t top, bottom, nstr;
-
+
if (!(domain = the_domain))
goto not_found;
@@ -1576,7 +1579,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural)
{
nstr--;
if (nstr < domain->nstrings
- && SWAPIT(domain->must_swap,
+ && SWAPIT(domain->must_swap,
domain->orig_tab[nstr].length) >= len
&& !strcmp (msgid, (domain->data
+ SWAPIT(domain->must_swap,
@@ -1599,7 +1602,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural)
while (bottom < top)
{
int cmp_val;
-
+
nstr = (bottom + top) / 2;
cmp_val = strcmp (msgid, (domain->data
+ SWAPIT(domain->must_swap,
@@ -1671,10 +1674,10 @@ gettext_select_utf8 (int value)
int
main (int argc, char **argv)
{
- const char atext1[] =
+ const char atext1[] =
"Warning: You have entered an insecure passphrase.%%0A"
"A passphrase should be at least %u character long.";
- const char atext2[] =
+ const char atext2[] =
"Warning: You have entered an insecure passphrase.%%0A"
"A passphrase should be at least %u characters long.";
@@ -1683,7 +1686,7 @@ main (int argc, char **argv)
argc--;
argv++;
}
-
+
bindtextdomain ("gnupg2", "c:/programme/gnu/gnupg/share/locale");
printf ("locale is `%s'\n", gettext_localename ());
diff --git a/jnlib/w32-reg.c b/jnlib/w32-reg.c
index e6bd911c5..a6e239548 100644
--- a/jnlib/w32-reg.c
+++ b/jnlib/w32-reg.c
@@ -25,6 +25,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
#include <windows.h>
#include "libjnlib-config.h"
@@ -34,7 +37,7 @@ static HKEY
get_root_key(const char *root)
{
HKEY root_key;
-
+
if (!root)
root_key = HKEY_CURRENT_USER;
else if (!strcmp( root, "HKEY_CLASSES_ROOT" ) )
@@ -51,7 +54,7 @@ get_root_key(const char *root)
root_key = HKEY_CURRENT_CONFIG;
else
return NULL;
-
+
return root_key;
}
@@ -65,10 +68,10 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
HKEY root_key, key_handle;
DWORD n1, nbytes, type;
char *result = NULL;
-
+
if ( !(root_key = get_root_key(root) ) )
return NULL;
-
+
if ( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) )
{
if (root)
@@ -94,7 +97,7 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
if (type == REG_EXPAND_SZ && strchr (result, '%'))
{
char *tmp;
-
+
n1 += 1000;
tmp = jnlib_malloc (n1+1);
if (!tmp)
@@ -111,7 +114,7 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
if (nbytes && nbytes > n1)
{
/* Oops - truncated, better don't expand at all. */
- jnlib_free (tmp);
+ jnlib_free (tmp);
goto leave;
}
tmp[nbytes] = 0;
@@ -126,14 +129,14 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
result = jnlib_malloc (strlen (tmp)+1);
if (!result)
result = tmp;
- else
+ else
{
strcpy (result, tmp);
jnlib_free (tmp);
}
}
- else
- {
+ else
+ {
/* Error - don't expand. */
jnlib_free (tmp);
}
@@ -146,22 +149,22 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
int
-write_w32_registry_string (const char *root, const char *dir,
+write_w32_registry_string (const char *root, const char *dir,
const char *name, const char *value)
{
HKEY root_key, reg_key;
-
+
if ( !(root_key = get_root_key(root) ) )
return -1;
-
- if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key )
+
+ if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, &reg_key )
!= ERROR_SUCCESS )
return -1;
-
- if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value,
+
+ if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value,
strlen( value ) ) != ERROR_SUCCESS )
{
- if ( RegCreateKey( root_key, name, &reg_key ) != ERROR_SUCCESS )
+ if ( RegCreateKey( root_key, name, &reg_key ) != ERROR_SUCCESS )
{
RegCloseKey(reg_key);
return -1;
@@ -173,9 +176,9 @@ write_w32_registry_string (const char *root, const char *dir,
return -1;
}
}
-
+
RegCloseKey (reg_key);
-
+
return 0;
}