summaryrefslogtreecommitdiff
path: root/jnlib
diff options
context:
space:
mode:
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-11-13 09:26:18 +0100
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-11-13 09:26:18 +0100
commite87a22655de485af790db1d4c51f4bc166a2bbd6 (patch)
tree93d088c2bc13d9a26e6f24b70936d998bd1404df /jnlib
parent6576640b55777bd811a12a188b9b1f3c63653799 (diff)
downloadgpg2-e87a22655de485af790db1d4c51f4bc166a2bbd6.tar.gz
gpg2-e87a22655de485af790db1d4c51f4bc166a2bbd6.tar.bz2
gpg2-e87a22655de485af790db1d4c51f4bc166a2bbd6.zip
Imported Upstream version 2.0.26upstream/2.0.26
Diffstat (limited to 'jnlib')
-rw-r--r--jnlib/Makefile.am2
-rw-r--r--jnlib/Makefile.in64
-rw-r--r--jnlib/argparse.c197
-rw-r--r--jnlib/argparse.h16
-rw-r--r--jnlib/mischelp.h2
-rw-r--r--jnlib/stringhelp.c75
-rw-r--r--jnlib/utf8conv.c144
-rw-r--r--jnlib/w32-gettext.c47
-rw-r--r--jnlib/w32-reg.c55
-rw-r--r--jnlib/w32help.h2
10 files changed, 349 insertions, 255 deletions
diff --git a/jnlib/Makefile.am b/jnlib/Makefile.am
index b3e7d7d..2ba2fbf 100644
--- a/jnlib/Makefile.am
+++ b/jnlib/Makefile.am
@@ -27,7 +27,7 @@ TESTS = $(module_tests)
AM_CPPFLAGS = -I$(top_srcdir)/intl
# We need libgcrypt because libjnlib-config includes gcrypt.h
-AM_CFLAGS = -DJNLIB_IN_JNLIB $(LIBGCRYPT_CFLAGS)
+AM_CFLAGS = -DJNLIB_IN_JNLIB $(GPG_ERROR_CFLAGS) $(LIBGCRYPT_CFLAGS)
noinst_LIBRARIES = libjnlib.a
diff --git a/jnlib/Makefile.in b/jnlib/Makefile.in
index a2d9663..8f5ac89 100644
--- a/jnlib/Makefile.in
+++ b/jnlib/Makefile.in
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -36,6 +36,23 @@
VPATH = @srcdir@
+am__make_dryrun = \
+ { \
+ am__dry=no; \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
+ | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+ *) \
+ for am__flg in $$MAKEFLAGS; do \
+ case $$am__flg in \
+ *=*|--*) ;; \
+ *n*) am__dry=yes; break;; \
+ esac; \
+ done;; \
+ esac; \
+ test $$am__dry = yes; \
+ }
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -123,6 +140,11 @@ CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libjnlib_a_SOURCES) $(t_stringhelp_SOURCES)
DIST_SOURCES = $(am__libjnlib_a_SOURCES_DIST) $(t_stringhelp_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
@@ -144,7 +166,11 @@ BITSIZEOF_SIG_ATOMIC_T = @BITSIZEOF_SIG_ATOMIC_T@
BITSIZEOF_SIZE_T = @BITSIZEOF_SIZE_T@
BITSIZEOF_WCHAR_T = @BITSIZEOF_WCHAR_T@
BITSIZEOF_WINT_T = @BITSIZEOF_WINT_T@
+BUILD_FILEVERSION = @BUILD_FILEVERSION@
+BUILD_HOSTNAME = @BUILD_HOSTNAME@
BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
+BUILD_REVISION = @BUILD_REVISION@
+BUILD_TIMESTAMP = @BUILD_TIMESTAMP@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CC_FOR_BUILD = @CC_FOR_BUILD@
@@ -326,7 +352,7 @@ EXTRA_DIST = README ChangeLog-2011
AM_CPPFLAGS = -I$(top_srcdir)/intl
# We need libgcrypt because libjnlib-config includes gcrypt.h
-AM_CFLAGS = -DJNLIB_IN_JNLIB $(LIBGCRYPT_CFLAGS)
+AM_CFLAGS = -DJNLIB_IN_JNLIB $(GPG_ERROR_CFLAGS) $(LIBGCRYPT_CFLAGS)
noinst_LIBRARIES = libjnlib.a
#libjnlib_a_LDFLAGS =
@@ -388,14 +414,14 @@ $(am__aclocal_m4_deps):
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
-libjnlib.a: $(libjnlib_a_OBJECTS) $(libjnlib_a_DEPENDENCIES)
+libjnlib.a: $(libjnlib_a_OBJECTS) $(libjnlib_a_DEPENDENCIES) $(EXTRA_libjnlib_a_DEPENDENCIES)
-rm -f libjnlib.a
$(libjnlib_a_AR) libjnlib.a $(libjnlib_a_OBJECTS) $(libjnlib_a_LIBADD)
$(RANLIB) libjnlib.a
clean-noinstPROGRAMS:
-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
-t-stringhelp$(EXEEXT): $(t_stringhelp_OBJECTS) $(t_stringhelp_DEPENDENCIES)
+t-stringhelp$(EXEEXT): $(t_stringhelp_OBJECTS) $(t_stringhelp_DEPENDENCIES) $(EXTRA_t_stringhelp_DEPENDENCIES)
@rm -f t-stringhelp$(EXEEXT)
$(LINK) $(t_stringhelp_OBJECTS) $(t_stringhelp_LDADD) $(LIBS)
@@ -565,14 +591,15 @@ check-TESTS: $(TESTS)
fi; \
dashes=`echo "$$dashes" | sed s/./=/g`; \
if test "$$failed" -eq 0; then \
- echo "$$grn$$dashes"; \
+ col="$$grn"; \
else \
- echo "$$red$$dashes"; \
+ col="$$red"; \
fi; \
- echo "$$banner"; \
- test -z "$$skipped" || echo "$$skipped"; \
- test -z "$$report" || echo "$$report"; \
- echo "$$dashes$$std"; \
+ echo "$${col}$$dashes$${std}"; \
+ echo "$${col}$$banner$${std}"; \
+ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+ test -z "$$report" || echo "$${col}$$report$${std}"; \
+ echo "$${col}$$dashes$${std}"; \
test "$$failed" -eq 0; \
else :; fi
@@ -621,10 +648,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- `test -z '$(STRIP)' || \
- echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
mostlyclean-generic:
clean-generic:
diff --git a/jnlib/argparse.c b/jnlib/argparse.c
index c9b5384..c457953 100644
--- a/jnlib/argparse.c
+++ b/jnlib/argparse.c
@@ -1,6 +1,7 @@
/* [argparse.c wk 17.06.97] Argument Parser for option handling
* Copyright (C) 1998, 1999, 2000, 2001, 2006
- * 2007, 2008 Free Software Foundation, Inc.
+ * 2007, 2008, 2012 Free Software Foundation, Inc.
+ * Copyright (C) 1997, 2013 Werner Koch
*
* This file is part of JNLIB.
*
@@ -92,7 +93,8 @@
* 4 = takes ulong argument
* Bit 3 : argument is optional (r_type will the be set to 0)
* Bit 4 : allow 0x etc. prefixed values.
- * Bit 7 : this is a command and not an option
+ * Bit 6 : Ignore this option
+ * Bit 7 : This is a command and not an option
* You stop the option processing by setting opts to NULL, the function will
* then return 0.
* @Return Value
@@ -116,6 +118,7 @@
* { 'o', "output", 2 },
* { 'c', "cross-ref", 2|8 },
* { 'm', "my-option", 1|8 },
+ * { 300, "ignored-long-option, ARGPARSE_OP_IGNORE},
* { 500, "have-no-short-option-for-this-long-option", 0 },
* {0} };
* ARGPARSE_ARGS pargs = { &argc, &argv, 0 }
@@ -143,6 +146,16 @@ struct alias_def_s {
const char *value; /* ptr into name */
};
+
+/* Object to store the names for the --ignore-invalid-option option.
+ This is a simple linked list. */
+typedef struct iio_item_def_s *IIO_ITEM_DEF;
+struct iio_item_def_s
+{
+ IIO_ITEM_DEF next;
+ char name[1]; /* String with the long option name. */
+};
+
static const char *(*strusage_handler)( int ) = NULL;
static int set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s);
@@ -162,6 +175,7 @@ initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno )
arg->internal.stopped = 0;
arg->internal.aliases = NULL;
arg->internal.cur_alias = NULL;
+ arg->internal.iio_list = NULL;
arg->err = 0;
arg->flags |= 1<<15; /* Mark as initialized. */
if ( *arg->argc < 0 )
@@ -244,6 +258,111 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
#endif
}
+
+/* Return true if KEYWORD is in the ignore-invalid-option list. */
+static int
+ignore_invalid_option_p (ARGPARSE_ARGS *arg, const char *keyword)
+{
+ IIO_ITEM_DEF item = arg->internal.iio_list;
+
+ for (; item; item = item->next)
+ if (!strcmp (item->name, keyword))
+ return 1;
+ return 0;
+}
+
+
+/* Add the keywords up to the next LF to the list of to be ignored
+ options. After returning FP will either be at EOF or the next
+ character read wll be the first of a new line. The function
+ returns 0 on success or true on malloc failure. */
+static int
+ignore_invalid_option_add (ARGPARSE_ARGS *arg, FILE *fp)
+{
+ IIO_ITEM_DEF item;
+ int c;
+ char name[100];
+ int namelen = 0;
+ int ready = 0;
+ enum { skipWS, collectNAME, skipNAME, addNAME} state = skipWS;
+
+ while (!ready)
+ {
+ c = getc (fp);
+ if (c == '\n')
+ ready = 1;
+ else if (c == EOF)
+ {
+ c = '\n';
+ ready = 1;
+ }
+ again:
+ switch (state)
+ {
+ case skipWS:
+ if (!isascii (c) || !isspace(c))
+ {
+ namelen = 0;
+ state = collectNAME;
+ goto again;
+ }
+ break;
+
+ case collectNAME:
+ if (isspace (c))
+ {
+ state = addNAME;
+ goto again;
+ }
+ else if (namelen < DIM(name)-1)
+ name[namelen++] = c;
+ else /* Too long. */
+ state = skipNAME;
+ break;
+
+ case skipNAME:
+ if (isspace (c))
+ {
+ state = skipWS;
+ goto again;
+ }
+ break;
+
+ case addNAME:
+ name[namelen] = 0;
+ if (!ignore_invalid_option_p (arg, name))
+ {
+ item = jnlib_malloc (sizeof *item + namelen);
+ if (!item)
+ return 1;
+ strcpy (item->name, name);
+ item->next = (IIO_ITEM_DEF)arg->internal.iio_list;
+ arg->internal.iio_list = item;
+ }
+ state = skipWS;
+ goto again;
+ }
+ }
+ return 0;
+}
+
+
+/* Clear the entire ignore-invalid-option list. */
+static void
+ignore_invalid_option_clear (ARGPARSE_ARGS *arg)
+{
+ IIO_ITEM_DEF item, tmpitem;
+
+ for (item = arg->internal.iio_list; item; item = tmpitem)
+ {
+ tmpitem = item->next;
+ jnlib_free (item);
+ }
+ arg->internal.iio_list = NULL;
+}
+
+
+
/****************
* Get options from a file.
* Lines starting with '#' are comment lines.
@@ -253,6 +372,10 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
* are not valid here.
* The special keyword "alias" may be used to store alias definitions,
* which are later expanded like long options.
+ * The option
+ * ignore-invalid-option OPTIONNAMEs
+ * is recognized and updates a list of option which should be ignored if they
+ * are not defined.
* Caller must free returned strings.
* If called with FP set to NULL command line args are parse instead.
*
@@ -298,13 +421,32 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
}
idx = i;
arg->r_opt = opts[idx].short_opt;
- if (!opts[idx].short_opt )
- arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
- ? ARGPARSE_INVALID_COMMAND
- : ARGPARSE_INVALID_OPTION);
- else if (!(opts[idx].flags & 7))
+ if ((opts[idx].flags & ARGPARSE_OPT_IGNORE))
+ {
+ state = i = 0;
+ continue;
+ }
+ else if (!opts[idx].short_opt )
+ {
+ if (!strcmp (keyword, "ignore-invalid-option"))
+ {
+ /* No argument - ignore this meta option. */
+ state = i = 0;
+ continue;
+ }
+ else if (ignore_invalid_option_p (arg, keyword))
+ {
+ /* This invalid option is in the iio list. */
+ state = i = 0;
+ continue;
+ }
+ arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
+ ? ARGPARSE_INVALID_COMMAND
+ : ARGPARSE_INVALID_OPTION);
+ }
+ else if (!(opts[idx].flags & ARGPARSE_TYPE_MASK))
arg->r_type = 0; /* Does not take an arg. */
- else if ((opts[idx].flags & 8) )
+ else if ((opts[idx].flags & ARGPARSE_OPT_OPTIONAL) )
arg->r_type = 0; /* Arg is optional. */
else
arg->r_opt = ARGPARSE_MISSING_ARG;
@@ -316,9 +458,9 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
/* No argument found. */
if (in_alias)
arg->r_opt = ARGPARSE_MISSING_ARG;
- else if (!(opts[idx].flags & 7))
+ else if (!(opts[idx].flags & ARGPARSE_TYPE_MASK))
arg->r_type = 0; /* Does not take an arg. */
- else if ((opts[idx].flags & 8))
+ else if ((opts[idx].flags & ARGPARSE_OPT_OPTIONAL))
arg->r_type = 0; /* No optional argument. */
else
arg->r_opt = ARGPARSE_MISSING_ARG;
@@ -354,7 +496,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
}
}
}
- else if (!(opts[idx].flags & 7))
+ else if (!(opts[idx].flags & ARGPARSE_TYPE_MASK))
arg->r_opt = ARGPARSE_UNEXPECTED_ARG;
else
{
@@ -389,6 +531,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
}
else if (c == EOF)
{
+ ignore_invalid_option_clear (arg);
if (ferror (fp))
arg->r_opt = ARGPARSE_READ_ERROR;
else
@@ -415,13 +558,29 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
break;
idx = i;
arg->r_opt = opts[idx].short_opt;
- if (!opts[idx].short_opt)
+ if ((opts[idx].flags & ARGPARSE_OPT_IGNORE))
+ {
+ state = 1; /* Process like a comment. */
+ }
+ else if (!opts[idx].short_opt)
{
if (!strcmp (keyword, "alias"))
{
in_alias = 1;
state = 3;
}
+ else if (!strcmp (keyword, "ignore-invalid-option"))
+ {
+ if (ignore_invalid_option_add (arg, fp))
+ {
+ arg->r_opt = ARGPARSE_OUT_OF_CORE;
+ break;
+ }
+ state = i = 0;
+ ++*lineno;
+ }
+ else if (ignore_invalid_option_p (arg, keyword))
+ state = 1; /* Process like a comment. */
else
{
arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND)
@@ -551,7 +710,7 @@ find_long_option( ARGPARSE_ARGS *arg,
return i;
}
}
- return -1;
+ return -1; /* Not found. */
}
int
@@ -637,7 +796,7 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
{
for (i=0; opts[i].short_opt; i++ )
{
- if ( opts[i].long_opt )
+ if (opts[i].long_opt && !(opts[i].flags & ARGPARSE_OPT_IGNORE))
printf ("--%s\n", opts[i].long_opt);
}
fputs ("--dump-options\n--help\n--version\n--warranty\n", stdout);
@@ -655,7 +814,7 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
arg->r_opt = opts[i].short_opt;
if ( i < 0 )
;
- else if ( (opts[i].flags & 0x07) )
+ else if ( (opts[i].flags & ARGPARSE_TYPE_MASK) )
{
if ( argpos )
{
@@ -739,7 +898,7 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
arg->internal.inarg++; /* Point to the next arg. */
arg->r.ret_str = s;
}
- else if ( (opts[i].flags & 7) )
+ else if ( (opts[i].flags & ARGPARSE_TYPE_MASK) )
{
if ( s[1] && !dash_kludge )
{
@@ -811,9 +970,9 @@ arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
static int
set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s)
{
- int base = (flags & 16)? 0 : 10;
+ int base = (flags & ARGPARSE_OPT_PREFIX)? 0 : 10;
- switch ( (arg->r_type = (flags & 7)) )
+ switch ( (arg->r_type = (flags & ARGPARSE_TYPE_MASK)) )
{
case ARGPARSE_TYPE_INT:
arg->r.ret_int = (int)strtol(s,NULL,base);
@@ -1107,7 +1266,7 @@ strusage( int level )
break;
case 11: p = "foo"; break;
case 13: p = "0.0"; break;
- case 14: p = "Copyright (C) 2012 Free Software Foundation, Inc."; break;
+ case 14: p = "Copyright (C) 2013 Free Software Foundation, Inc."; break;
case 15: p =
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n";
diff --git a/jnlib/argparse.h b/jnlib/argparse.h
index b211e5f..dd9b30b 100644
--- a/jnlib/argparse.h
+++ b/jnlib/argparse.h
@@ -24,12 +24,12 @@
#include "types.h"
typedef struct
-{
+{
int *argc; /* Pointer to ARGC (value subject to change). */
char ***argv; /* Pointer to ARGV (value subject to change). */
unsigned int flags; /* Global flags. May be set prior to calling the
parser. The parser may change the value. */
- int err; /* Print error description for last option.
+ int err; /* Print error description for last option.
Either 0, ARGPARSE_PRINT_WARNING or
ARGPARSE_PRINT_ERROR. */
@@ -49,6 +49,7 @@ typedef struct
const char *last;
void *aliases;
const void *cur_alias;
+ void *iio_list;
} internal; /* Private - do not change. */
} ARGPARSE_ARGS;
@@ -78,9 +79,12 @@ typedef struct
#define ARGPARSE_TYPE_STRING 2 /* Takes a string argument. */
#define ARGPARSE_TYPE_LONG 3 /* Takes a long argument. */
#define ARGPARSE_TYPE_ULONG 4 /* Takes an unsigned long argument. */
-#define ARGPARSE_OPT_OPTIONAL (1<<3) /* Argument is optional. */
+#define ARGPARSE_OPT_OPTIONAL (1<<3) /* Argument is optional. */
#define ARGPARSE_OPT_PREFIX (1<<4) /* Allow 0x etc. prefixed values. */
-#define ARGPARSE_OPT_COMMAND (1<<8) /* The argument is a command. */
+#define ARGPARSE_OPT_IGNORE (1<<6) /* Ignore command or option. */
+#define ARGPARSE_OPT_COMMAND (1<<7) /* The argument is a command. */
+
+#define ARGPARSE_TYPE_MASK 7 /* Mask for the type values (internal). */
/* A set of macros to make option definitions easier to read. */
#define ARGPARSE_x(s,l,t,f,d) \
@@ -147,9 +151,11 @@ typedef struct
#define ARGPARSE_c(s,l,d) \
{ (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_COMMAND), (d) }
+#define ARGPARSE_ignore(s,l) \
+ { (s), (l), (ARGPARSE_OPT_IGNORE), "@" }
#define ARGPARSE_group(s,d) \
- { (s), NULL, 0, (d) }
+ { (s), NULL, 0, (d) }
#define ARGPARSE_end() { 0, NULL, 0, NULL }
diff --git a/jnlib/mischelp.h b/jnlib/mischelp.h
index e478354..dc17384 100644
--- a/jnlib/mischelp.h
+++ b/jnlib/mischelp.h
@@ -19,7 +19,7 @@
*/
#ifndef LIBJNLIB_MISCHELP_H
-#define LIBJNLIB_MISCHHELP_H
+#define LIBJNLIB_MISCHELP_H
/* Check whether the files NAME1 and NAME2 are identical. This is for
diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c
index 3173ebc..c43b120 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/utf8conv.c b/jnlib/utf8conv.c
index fee4dc6..b5cf6a8 100644
--- a/jnlib/utf8conv.c
+++ b/jnlib/utf8conv.c
@@ -27,9 +27,7 @@
#include <langinfo.h>
#endif
#include <errno.h>
-#ifndef HAVE_W32_SYSTEM
-# include <iconv.h>
-#endif
+#include <iconv.h>
#include "libjnlib-config.h"
#include "stringhelp.h"
@@ -45,59 +43,6 @@ static int no_translation; /* Set to true if we let simply pass through. */
static int use_iconv; /* iconv comversion fucntions required. */
-/* Under W32 we dlopen the iconv dll and don't require any iconv
- related headers at all. However we need to define some stuff. */
-#ifdef HAVE_W32_SYSTEM
-typedef void *iconv_t;
-#ifndef ICONV_CONST
-#define ICONV_CONST const
-#endif
-static iconv_t (* __stdcall iconv_open) (const char *tocode,
- const char *fromcode);
-static size_t (* __stdcall iconv) (iconv_t cd,
- const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft);
-static int (* __stdcall iconv_close) (iconv_t cd);
-
-static int
-load_libiconv (void)
-{
- static int done;
-
- if (!done)
- {
- void *handle;
-
- done = 1; /* Do it right now because we might get called recursivly
- through gettext. */
-
- handle = dlopen ("iconv.dll", RTLD_LAZY);
- if (handle)
- {
- iconv_open = dlsym (handle, "libiconv_open");
- if (iconv_open)
- iconv = dlsym (handle, "libiconv");
- if (iconv)
- iconv_close = dlsym (handle, "libiconv_close");
- }
- if (!handle || !iconv_close)
- {
- log_info (_("error loading `%s': %s\n"),
- "iconv.dll", dlerror ());
- log_info (_("please see %s for more information\n"),
- "http://www.gnupg.org/download/iconv.html");
- iconv_open = NULL;
- iconv = NULL;
- iconv_close = NULL;
- if (handle)
- dlclose (handle);
- }
- }
- return iconv_open? 0: -1;
-}
-#endif /*HAVE_W32_SYSTEM*/
-
-
/* Error handler for iconv failures. This is needed to not clutter the
output with repeated diagnostics about a missing conversion. */
static void
@@ -152,13 +97,13 @@ set_native_charset (const char *newset)
{
const char *full_newset;
- if (!newset)
+ if (!newset)
{
#ifdef HAVE_W32_SYSTEM
static char codepage[30];
unsigned int cpno;
const char *aliases;
-
+
/* We are a console program thus we need to use the
GetConsoleOutputCP function and not the the GetACP which
would give the codepage for a GUI program. Note this is not
@@ -201,7 +146,7 @@ set_native_charset (const char *newset)
}
#else /*!HAVE_W32_SYSTEM*/
-
+
#ifdef HAVE_LANGINFO_CODESET
newset = nl_langinfo (CODESET);
#else /*!HAVE_LANGINFO_CODESET*/
@@ -225,7 +170,7 @@ set_native_charset (const char *newset)
mod = strchr (++dot, '@');
if (!mod)
mod = dot + strlen (dot);
- if (mod - dot < sizeof codepage && dot != mod)
+ if (mod - dot < sizeof codepage && dot != mod)
{
memcpy (codepage, dot, mod - dot);
codepage [mod - dot] = 0;
@@ -272,21 +217,16 @@ set_native_charset (const char *newset)
else
{
iconv_t cd;
-
-#ifdef HAVE_W32_SYSTEM
- if (load_libiconv ())
- return -1;
-#endif /*HAVE_W32_SYSTEM*/
cd = iconv_open (full_newset, "utf-8");
- if (cd == (iconv_t)-1)
+ if (cd == (iconv_t)-1)
{
handle_iconv_error (full_newset, "utf-8", 0);
return -1;
}
iconv_close (cd);
cd = iconv_open ("utf-8", full_newset);
- if (cd == (iconv_t)-1)
+ if (cd == (iconv_t)-1)
{
handle_iconv_error ("utf-8", full_newset, 0);
return -1;
@@ -306,7 +246,7 @@ get_native_charset ()
}
/* Return true if the native charset is utf-8. */
-int
+int
is_native_utf8 (void)
{
return no_translation;
@@ -353,13 +293,13 @@ native_to_utf8 (const char *orig_string)
*p = 0;
}
else
- {
+ {
/* Need to use iconv. */
iconv_t cd;
const char *inptr;
char *outptr;
size_t inbytes, outbytes;
-
+
cd = iconv_open ("utf-8", active_charset_name);
if (cd == (iconv_t)-1)
{
@@ -367,14 +307,14 @@ native_to_utf8 (const char *orig_string)
return native_to_utf8 (string);
}
- for (s=string; *s; s++ )
+ for (s=string; *s; s++ )
{
length++;
if ((*s & 0x80))
length += 5; /* We may need up to 6 bytes for the utf8 output. */
}
buffer = jnlib_xmalloc (length + 1);
-
+
inptr = string;
inbytes = strlen (string);
outptr = buffer;
@@ -448,10 +388,10 @@ do_utf8_to_native (const char *string, size_t length, int delim,
if (!nleft)
{
if (!(*s & 0x80))
- {
+ {
/* Plain ascii. */
if ( delim != -1
- && (*s < 0x20 || *s == 0x7f || *s == delim
+ && (*s < 0x20 || *s == 0x7f || *s == delim
|| (delim && *s == '\\')))
{
n++;
@@ -490,35 +430,35 @@ do_utf8_to_native (const char *string, size_t length, int delim,
encbuf[encidx++] = *s;
}
else if ((*s & 0xf0) == 0xe0) /* 1110 xxxx */
- {
+ {
val = *s & 0x0f;
nleft = 2;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xf8) == 0xf0) /* 1111 0xxx */
- {
+ {
val = *s & 0x07;
nleft = 3;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xfc) == 0xf8) /* 1111 10xx */
- {
+ {
val = *s & 0x03;
nleft = 4;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xfe) == 0xfc) /* 1111 110x */
- {
+ {
val = *s & 0x01;
nleft = 5;
encidx = 0;
encbuf[encidx++] = *s;
}
else /* Invalid encoding: print as \xNN. */
- {
+ {
if (p)
{
sprintf (p, "\\x%02x", *s);
@@ -551,7 +491,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
val <<= 6;
val |= *s & 0x3f;
if (!--nleft) /* Ready. */
- {
+ {
if (no_translation)
{
if (p)
@@ -590,12 +530,12 @@ do_utf8_to_native (const char *string, size_t length, int delim,
if (val >= 0x80 && val < 256)
{
/* We can simply print this character */
- n++;
+ n++;
if (p)
*p++ = val;
}
else
- {
+ {
/* We do not have a translation: print utf8. */
if (p)
{
@@ -625,7 +565,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
const char *inptr;
char *outbuf, *outptr;
size_t inbytes, outbytes;
-
+
*p = 0; /* Terminate the buffer. */
cd = iconv_open (active_charset_name, "utf-8");
@@ -642,14 +582,14 @@ do_utf8_to_native (const char *string, size_t length, int delim,
inbytes = n - 1;;
inptr = buffer;
outbytes = n * MB_LEN_MAX;
- if (outbytes / MB_LEN_MAX != n)
+ if (outbytes / MB_LEN_MAX != n)
BUG (); /* Actually an overflow. */
outbuf = outptr = jnlib_xmalloc (outbytes);
if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
- &outptr, &outbytes) == (size_t)-1)
+ &outptr, &outbytes) == (size_t)-1)
{
static int shown;
-
+
if (!shown)
log_info (_("conversion from `%s' to `%s' failed: %s\n"),
"utf-8", active_charset_name, strerror (errno));
@@ -661,7 +601,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
outbuf = do_utf8_to_native (string, length, delim, 0);
}
else /* Success. */
- {
+ {
*outptr = 0; /* Make sure it is a string. */
/* We could realloc the buffer now but I doubt that it
makes much sense given that it will get freed
@@ -694,45 +634,29 @@ utf8_to_native (const char *string, size_t length, int delim)
-/* Wrapper function for iconv_open, required for W32 as we dlopen that
- library on that system. */
-jnlib_iconv_t
+/* Wrapper function for iconv_open, formerly required for W32 as we
+ used to dlopen that library on that system. */
+jnlib_iconv_t
jnlib_iconv_open (const char *tocode, const char *fromcode)
{
-#ifdef HAVE_W32_SYSTEM
- if (load_libiconv ())
- return (jnlib_iconv_t)(-1);
-#endif /*HAVE_W32_SYSTEM*/
-
return (jnlib_iconv_t)iconv_open (tocode, fromcode);
}
-/* Wrapper function for iconv, required for W32 as we dlopen that
- library on that system. */
+/* Wrapper function for iconv, formerly required for W32 as we used to
+ dlopen that library on that system. */
size_t
jnlib_iconv (jnlib_iconv_t cd,
const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)
{
-
-#ifdef HAVE_W32_SYSTEM
- if (load_libiconv ())
- return 0;
-#endif /*HAVE_W32_SYSTEM*/
-
return iconv ((iconv_t)cd, (char**)inbuf, inbytesleft, outbuf, outbytesleft);
}
-/* Wrapper function for iconv_close, required for W32 as we dlopen that
- library on that system. */
+/* Wrapper function for iconv_close, formerly required for W32 as we
+ used to dlopen that library on that system. */
int
jnlib_iconv_close (jnlib_iconv_t cd)
{
-#ifdef HAVE_W32_SYSTEM
- if (load_libiconv ())
- return 0;
-#endif /*HAVE_W32_SYSTEM*/
-
return iconv_close ((iconv_t)cd);
}
diff --git a/jnlib/w32-gettext.c b/jnlib/w32-gettext.c
index 834b2aa..14cb1e1 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 e6bd911..e55f806 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);
}
@@ -145,38 +148,4 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
}
-int
-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 )
- != ERROR_SUCCESS )
- return -1;
-
- if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value,
- strlen( value ) ) != ERROR_SUCCESS )
- {
- if ( RegCreateKey( root_key, name, &reg_key ) != ERROR_SUCCESS )
- {
- RegCloseKey(reg_key);
- return -1;
- }
- if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value,
- strlen( value ) ) != ERROR_SUCCESS )
- {
- RegCloseKey(reg_key);
- return -1;
- }
- }
-
- RegCloseKey (reg_key);
-
- return 0;
-}
-
#endif /*HAVE_W32_SYSTEM*/
diff --git a/jnlib/w32help.h b/jnlib/w32help.h
index c503ad2..c7aa5cb 100644
--- a/jnlib/w32help.h
+++ b/jnlib/w32help.h
@@ -24,8 +24,6 @@
/*-- w32-reg.c --*/
char *read_w32_registry_string (const char *root,
const char *dir, const char *name );
-int write_w32_registry_string (const char *root, const char *dir,
- const char *name, const char *value);
#ifdef USE_SIMPLE_GETTEXT
char *bindtextdomain (const char *domainname, const char *dirname);