mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
common: Remove libjnlib-config.h (jnlib merge).
* common/libjnlib-config.h: Remove. * common/common-defs.h (getenv) [HAVE_GETENV]: New. From removed header. (getpid) [HAVE_W32CE_SYSTEM]: New. From removed header. * common/argparse.c: Include util.h and common-defs.h. Replace jnlib_ macro names for non-GNUPG builds by x* names. * common/dotlock.c: Ditto. * common/logging.c: Include util.h and common-defs.h. Replace jnlib_ symbol names by x* names. * common/strlist.c: Ditto. * common/utf8conv.c: Ditto. * common/w32-reg.c: Ditto. * common/mischelp.c: Ditto. Also remove _jnlib_free. * common/stringhelp.c: Ditto. (JNLIB_LOG_WITH_PREFIX): Do not depend on this macro. * common/logging.h (JNLIB_LOG_WITH_PREFIX): Do not depend on this macro. -- This is part 1 of the patches to merge the jnlib files into common/. It does not make much sense to keep jnlib/ files separate. They are not often use elsewhere and maintaining the complex marcos stuff is too troublesome for the future. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
154f3ed2bf
commit
17bcd08708
@ -27,8 +27,8 @@ noinst_LIBRARIES = libcommon.a libcommonpth.a libgpgrl.a \
|
||||
if !HAVE_W32CE_SYSTEM
|
||||
noinst_LIBRARIES += libsimple-pwquery.a
|
||||
endif
|
||||
noinst_PROGRAMS = $(jnlib_tests) $(module_tests) $(module_maint_tests)
|
||||
TESTS = $(jnlib_tests) $(module_tests)
|
||||
noinst_PROGRAMS = $(module_tests) $(module_maint_tests)
|
||||
TESTS = $(module_tests)
|
||||
|
||||
BUILT_SOURCES = audit-events.h status-codes.h
|
||||
|
||||
@ -40,8 +40,10 @@ AM_CFLAGS = $(LIBGCRYPT_CFLAGS) $(LIBASSUAN_CFLAGS) $(KSBA_CFLAGS)
|
||||
|
||||
include $(top_srcdir)/am/cmacros.am
|
||||
|
||||
jnlib_sources = \
|
||||
libjnlib-config.h \
|
||||
|
||||
common_sources = \
|
||||
common-defs.h \
|
||||
util.h i18n.c i18n.h \
|
||||
types.h host2net.h dynload.h w32help.h \
|
||||
mapstrings.c stringhelp.c stringhelp.h \
|
||||
strlist.c strlist.h \
|
||||
@ -49,16 +51,7 @@ jnlib_sources = \
|
||||
argparse.c argparse.h \
|
||||
logging.c logging.h \
|
||||
dotlock.c dotlock.h \
|
||||
mischelp.c mischelp.h
|
||||
|
||||
if HAVE_W32_SYSTEM
|
||||
jnlib_sources += w32-reg.c w32-afunix.c w32-afunix.h
|
||||
endif
|
||||
|
||||
|
||||
common_sources = \
|
||||
common-defs.h \
|
||||
util.h i18n.c i18n.h \
|
||||
mischelp.c mischelp.h \
|
||||
status.c status.h\
|
||||
shareddefs.h \
|
||||
openpgpdefs.h \
|
||||
@ -95,6 +88,10 @@ common_sources = \
|
||||
agent-opt.c \
|
||||
helpfile.c
|
||||
|
||||
if HAVE_W32_SYSTEM
|
||||
common_sources += w32-reg.c w32-afunix.c w32-afunix.h
|
||||
endif
|
||||
|
||||
# Sources possible requiring a TLS library are put into a separate
|
||||
# conveince library.
|
||||
tls_sources = \
|
||||
@ -118,13 +115,13 @@ without_npth_sources = \
|
||||
get-passphrase.c get-passphrase.h
|
||||
|
||||
|
||||
libcommon_a_SOURCES = $(jnlib_sources) $(common_sources) $(without_npth_sources)
|
||||
libcommon_a_SOURCES = $(common_sources) $(without_npth_sources)
|
||||
if USE_DNS_SRV
|
||||
libcommon_a_SOURCES += srv.c
|
||||
endif
|
||||
libcommon_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) -DWITHOUT_NPTH=1
|
||||
|
||||
libcommonpth_a_SOURCES = $(jnlib_sources) $(common_sources)
|
||||
libcommonpth_a_SOURCES = $(common_sources)
|
||||
if USE_DNS_SRV
|
||||
libcommonpth_a_SOURCES += srv.c
|
||||
endif
|
||||
@ -169,17 +166,16 @@ endif
|
||||
#
|
||||
# Module tests
|
||||
#
|
||||
t_jnlib_src = t-support.h
|
||||
jnlib_tests = t-stringhelp t-timestuff
|
||||
if HAVE_W32_SYSTEM
|
||||
jnlib_tests += t-w32-reg
|
||||
endif
|
||||
module_tests = t-convert t-percent t-gettime t-sysutils t-sexputil \
|
||||
module_tests = t-stringhelp t-timestuff \
|
||||
t-convert t-percent t-gettime t-sysutils t-sexputil \
|
||||
t-session-env t-openpgp-oid t-ssh-utils \
|
||||
t-mapstrings t-zb32 t-mbox-util
|
||||
if !HAVE_W32CE_SYSTEM
|
||||
module_tests += t-exechelp
|
||||
endif
|
||||
if HAVE_W32_SYSTEM
|
||||
module_tests += t-w32-reg
|
||||
endif
|
||||
|
||||
if MAINTAINER_MODE
|
||||
module_maint_tests = t-helpfile t-b64 t-http
|
||||
@ -187,6 +183,7 @@ else
|
||||
module_maint_tests =
|
||||
endif
|
||||
|
||||
t_extra_src = t-support.h
|
||||
|
||||
t_common_cflags = $(KSBA_CFLAGS) $(LIBGCRYPT_CFLAGS) \
|
||||
$(LIBASSUAN_CFLAGS) $(GPG_ERROR_CFLAGS)
|
||||
@ -195,19 +192,13 @@ t_common_ldadd = libcommon.a \
|
||||
$(LIBINTL) $(LIBICONV)
|
||||
|
||||
|
||||
# jnlib tests
|
||||
t_stringhelp_SOURCES = t-stringhelp.c $(t_jnlib_src)
|
||||
# Common tests
|
||||
t_stringhelp_SOURCES = t-stringhelp.c $(t_extra_src)
|
||||
t_stringhelp_LDADD = $(t_common_ldadd)
|
||||
|
||||
t_timestuff_SOURCES = t-timestuff.c $(t_jnlib_src)
|
||||
t_timestuff_SOURCES = t-timestuff.c $(t_extra_src)
|
||||
t_timestuff_LDADD = $(t_common_ldadd)
|
||||
|
||||
if HAVE_W32_SYSTEM
|
||||
t_w32_reg_SOURCES = t-w32-reg.c $(t_jnlib_src)
|
||||
t_w32_reg_LDADD = $(t_common_ldadd)
|
||||
endif
|
||||
|
||||
# common tests
|
||||
t_convert_LDADD = $(t_common_ldadd)
|
||||
t_percent_LDADD = $(t_common_ldadd)
|
||||
t_gettime_LDADD = $(t_common_ldadd)
|
||||
@ -223,6 +214,12 @@ t_mapstrings_LDADD = $(t_common_ldadd)
|
||||
t_zb32_LDADD = $(t_common_ldadd)
|
||||
t_mbox_util_LDADD = $(t_common_ldadd)
|
||||
|
||||
# System specific test
|
||||
if HAVE_W32_SYSTEM
|
||||
t_w32_reg_SOURCES = t-w32-reg.c $(t_extra_src)
|
||||
t_w32_reg_LDADD = $(t_common_ldadd)
|
||||
endif
|
||||
|
||||
# http tests
|
||||
t_http_SOURCES = t-http.c
|
||||
t_http_CFLAGS = $(t_common_cflags) $(NTBTLS_CFLAGS) $(LIBGNUTLS_CFLAGS)
|
||||
|
@ -47,13 +47,13 @@
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef GNUPG_MAJOR_VERSION
|
||||
# include "libjnlib-config.h"
|
||||
# include "util.h"
|
||||
# include "common-defs.h"
|
||||
# include "i18n.h"
|
||||
# include "mischelp.h"
|
||||
# include "stringhelp.h"
|
||||
# include "logging.h"
|
||||
# ifdef JNLIB_NEED_UTF8CONV
|
||||
# include "utf8conv.h"
|
||||
# endif
|
||||
#endif /*GNUPG_MAJOR_VERSION*/
|
||||
|
||||
#include "argparse.h"
|
||||
@ -83,12 +83,12 @@
|
||||
# ifndef DIM
|
||||
# define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
||||
# endif
|
||||
# define jnlib_malloc(a) malloc ((a))
|
||||
# define jnlib_realloc(a,b) realloc ((a), (b))
|
||||
# define jnlib_strdup(a) strdup ((a))
|
||||
# define jnlib_free(a) free ((a))
|
||||
# define jnlib_log_error my_log_error
|
||||
# define jnlib_log_bug my_log_bug
|
||||
# define xtrymalloc(a) malloc ((a))
|
||||
# define xtryrealloc(a,b) realloc ((a), (b))
|
||||
# define xtrystrdup(a) strdup ((a))
|
||||
# define xfree(a) free ((a))
|
||||
# define log_error my_log_error
|
||||
# define log_bug my_log_bug
|
||||
# define trim_spaces(a) my_trim_spaces ((a))
|
||||
# define map_static_macro_string(a) (a)
|
||||
#endif /*!GNUPG_MAJOR_VERSION*/
|
||||
@ -343,7 +343,7 @@ initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno )
|
||||
arg->err = 0;
|
||||
arg->flags |= 1<<15; /* Mark as initialized. */
|
||||
if ( *arg->argc < 0 )
|
||||
jnlib_log_bug ("invalid argument for arg_parse\n");
|
||||
log_bug ("invalid argument for arg_parse\n");
|
||||
}
|
||||
|
||||
|
||||
@ -372,29 +372,28 @@ initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno )
|
||||
s = _("out of core");
|
||||
else
|
||||
s = _("invalid option");
|
||||
jnlib_log_error ("%s:%u: %s\n", filename, *lineno, s);
|
||||
log_error ("%s:%u: %s\n", filename, *lineno, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
s = arg->internal.last? arg->internal.last:"[??]";
|
||||
|
||||
if ( arg->r_opt == ARGPARSE_MISSING_ARG )
|
||||
jnlib_log_error (_("missing argument for option \"%.50s\"\n"), s);
|
||||
log_error (_("missing argument for option \"%.50s\"\n"), s);
|
||||
else if ( arg->r_opt == ARGPARSE_INVALID_ARG )
|
||||
jnlib_log_error (_("invalid argument for option \"%.50s\"\n"), s);
|
||||
log_error (_("invalid argument for option \"%.50s\"\n"), s);
|
||||
else if ( arg->r_opt == ARGPARSE_UNEXPECTED_ARG )
|
||||
jnlib_log_error (_("option \"%.50s\" does not expect an "
|
||||
"argument\n"), s );
|
||||
log_error (_("option \"%.50s\" does not expect an argument\n"), s);
|
||||
else if ( arg->r_opt == ARGPARSE_INVALID_COMMAND )
|
||||
jnlib_log_error (_("invalid command \"%.50s\"\n"), s);
|
||||
log_error (_("invalid command \"%.50s\"\n"), s);
|
||||
else if ( arg->r_opt == ARGPARSE_AMBIGUOUS_OPTION )
|
||||
jnlib_log_error (_("option \"%.50s\" is ambiguous\n"), s);
|
||||
log_error (_("option \"%.50s\" is ambiguous\n"), s);
|
||||
else if ( arg->r_opt == ARGPARSE_AMBIGUOUS_COMMAND )
|
||||
jnlib_log_error (_("command \"%.50s\" is ambiguous\n"),s );
|
||||
log_error (_("command \"%.50s\" is ambiguous\n"),s );
|
||||
else if ( arg->r_opt == ARGPARSE_OUT_OF_CORE )
|
||||
jnlib_log_error ("%s\n", _("out of core\n"));
|
||||
log_error ("%s\n", _("out of core\n"));
|
||||
else
|
||||
jnlib_log_error (_("invalid option \"%.50s\"\n"), s);
|
||||
log_error (_("invalid option \"%.50s\"\n"), s);
|
||||
}
|
||||
if (arg->err != ARGPARSE_PRINT_WARNING)
|
||||
exit (2);
|
||||
@ -418,7 +417,7 @@ store_alias( ARGPARSE_ARGS *arg, char *name, char *value )
|
||||
(void)name;
|
||||
(void)value;
|
||||
#if 0
|
||||
ALIAS_DEF a = jnlib_xmalloc( sizeof *a );
|
||||
ALIAS_DEF a = xmalloc( sizeof *a );
|
||||
a->name = name;
|
||||
a->value = value;
|
||||
a->next = (ALIAS_DEF)arg->internal.aliases;
|
||||
@ -500,7 +499,7 @@ ignore_invalid_option_add (ARGPARSE_ARGS *arg, FILE *fp)
|
||||
name[namelen] = 0;
|
||||
if (!ignore_invalid_option_p (arg, name))
|
||||
{
|
||||
item = jnlib_malloc (sizeof *item + namelen);
|
||||
item = xtrymalloc (sizeof *item + namelen);
|
||||
if (!item)
|
||||
return 1;
|
||||
strcpy (item->name, name);
|
||||
@ -524,7 +523,7 @@ ignore_invalid_option_clear (ARGPARSE_ARGS *arg)
|
||||
for (item = arg->internal.iio_list; item; item = tmpitem)
|
||||
{
|
||||
tmpitem = item->next;
|
||||
jnlib_free (item);
|
||||
xfree (item);
|
||||
}
|
||||
arg->internal.iio_list = NULL;
|
||||
}
|
||||
@ -655,7 +654,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
}
|
||||
if (!p || !*p)
|
||||
{
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
arg->r_opt = ARGPARSE_INVALID_ALIAS;
|
||||
}
|
||||
else
|
||||
@ -673,7 +672,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
if (!buffer)
|
||||
{
|
||||
keyword[i] = 0;
|
||||
buffer = jnlib_strdup (keyword);
|
||||
buffer = xtrystrdup (keyword);
|
||||
if (!buffer)
|
||||
arg->r_opt = ARGPARSE_OUT_OF_CORE;
|
||||
}
|
||||
@ -692,7 +691,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
p[strlen(p)-1] = 0;
|
||||
}
|
||||
if (!set_opt_arg (arg, opts[idx].flags, p))
|
||||
jnlib_free(buffer);
|
||||
xfree (buffer);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -782,7 +781,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
char *tmp;
|
||||
size_t tmplen = buflen + 50;
|
||||
|
||||
tmp = jnlib_realloc (buffer, tmplen);
|
||||
tmp = xtryrealloc (buffer, tmplen);
|
||||
if (tmp)
|
||||
{
|
||||
buflen = tmplen;
|
||||
@ -791,7 +790,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
}
|
||||
else
|
||||
{
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
arg->r_opt = ARGPARSE_OUT_OF_CORE;
|
||||
break;
|
||||
}
|
||||
@ -802,7 +801,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
else
|
||||
{
|
||||
size_t tmplen = DIM(keyword) + 50;
|
||||
buffer = jnlib_malloc (tmplen);
|
||||
buffer = xtrymalloc (tmplen);
|
||||
if (buffer)
|
||||
{
|
||||
buflen = tmplen;
|
||||
@ -1200,9 +1199,7 @@ long_opt_strlen( ARGPARSE_OPTS *o )
|
||||
if ( o->description && *o->description == '|' )
|
||||
{
|
||||
const char *s;
|
||||
#ifdef JNLIB_NEED_UTF8CONV
|
||||
int is_utf8 = is_native_utf8 ();
|
||||
#endif
|
||||
|
||||
s=o->description+1;
|
||||
if ( *s != '=' )
|
||||
@ -1211,9 +1208,7 @@ long_opt_strlen( ARGPARSE_OPTS *o )
|
||||
continuation bytes (10xxxxxx) if we are on a native utf8
|
||||
terminal. */
|
||||
for (; *s && *s != '|'; s++ )
|
||||
#ifdef JNLIB_NEED_UTF8CONV
|
||||
if ( is_utf8 && (*s&0xc0) != 0x80 )
|
||||
#endif
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
|
@ -20,6 +20,17 @@
|
||||
#ifndef GNUPG_COMMON_COMMON_DEFS_H
|
||||
#define GNUPG_COMMON_COMMON_DEFS_H
|
||||
|
||||
|
||||
/* Dummy replacement for getenv. */
|
||||
#ifndef HAVE_GETENV
|
||||
#define getenv(a) (NULL)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
#define getpid() GetCurrentProcessId ()
|
||||
#endif
|
||||
|
||||
|
||||
/*-- ttyio.c --*/
|
||||
void tty_private_set_rl_hooks (void (*init_stream) (FILE *),
|
||||
void (*set_completer) (rl_completion_func_t*),
|
||||
|
@ -310,7 +310,8 @@
|
||||
#endif
|
||||
|
||||
#ifdef GNUPG_MAJOR_VERSION
|
||||
# include "libjnlib-config.h"
|
||||
# include "util.h"
|
||||
# include "common-defs.h"
|
||||
# include "stringhelp.h" /* For stpcpy and w32_strerror. */
|
||||
#endif
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
@ -334,19 +335,17 @@
|
||||
/* In GnuPG we use wrappers around the malloc fucntions. If they are
|
||||
not defined we assume that this code is used outside of GnuPG and
|
||||
fall back to the regular malloc functions. */
|
||||
#ifndef jnlib_malloc
|
||||
# define jnlib_malloc(a) malloc ((a))
|
||||
# define jnlib_calloc(a,b) calloc ((a), (b))
|
||||
# define jnlib_free(a) free ((a))
|
||||
#ifndef xtrymalloc
|
||||
# define xtrymalloc(a) malloc ((a))
|
||||
# define xtrycalloc(a,b) calloc ((a), (b))
|
||||
# define xfree(a) free ((a))
|
||||
#endif
|
||||
|
||||
/* Wrapper to set ERRNO. */
|
||||
#ifndef jnlib_set_errno
|
||||
# ifdef HAVE_W32CE_SYSTEM
|
||||
# define jnlib_set_errno(e) gpg_err_set_errno ((e))
|
||||
/* Wrapper to set ERRNO (required for W32CE). */
|
||||
#ifdef GPG_ERROR_VERSION
|
||||
# define my_set_errno(e) gpg_err_set_errno ((e))
|
||||
#else
|
||||
# define jnlib_set_errno(e) do { errno = (e); } while (0)
|
||||
# endif
|
||||
# define my_set_errno(e) do { errno = (e); } while (0)
|
||||
#endif
|
||||
|
||||
/* Gettext macro replacement. */
|
||||
@ -488,7 +487,7 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
expected_len = 10 + 1 + h->nodename_len + 1;
|
||||
if ( expected_len >= sizeof buffer_space)
|
||||
{
|
||||
buffer = jnlib_malloc (expected_len);
|
||||
buffer = xtrymalloc (expected_len);
|
||||
if (!buffer)
|
||||
return -1;
|
||||
}
|
||||
@ -501,8 +500,8 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
my_info_2 ("error opening lockfile '%s': %s\n",
|
||||
h->lockname, strerror(errno) );
|
||||
if (buffer != buffer_space)
|
||||
jnlib_free (buffer);
|
||||
jnlib_set_errno (e); /* Need to return ERRNO here. */
|
||||
xfree (buffer);
|
||||
my_set_errno (e); /* Need to return ERRNO here. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -518,8 +517,8 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
my_info_1 ("error reading lockfile '%s'\n", h->lockname );
|
||||
close (fd);
|
||||
if (buffer != buffer_space)
|
||||
jnlib_free (buffer);
|
||||
jnlib_set_errno (0); /* Do not return an inappropriate ERRNO. */
|
||||
xfree (buffer);
|
||||
my_set_errno (0); /* Do not return an inappropriate ERRNO. */
|
||||
return -1;
|
||||
}
|
||||
p += res;
|
||||
@ -532,8 +531,8 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
{
|
||||
my_info_1 ("invalid size of lockfile '%s'\n", h->lockname);
|
||||
if (buffer != buffer_space)
|
||||
jnlib_free (buffer);
|
||||
jnlib_set_errno (0); /* Better don't return an inappropriate ERRNO. */
|
||||
xfree (buffer);
|
||||
my_set_errno (0); /* Better don't return an inappropriate ERRNO. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -543,8 +542,8 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
{
|
||||
my_error_2 ("invalid pid %d in lockfile '%s'\n", pid, h->lockname);
|
||||
if (buffer != buffer_space)
|
||||
jnlib_free (buffer);
|
||||
jnlib_set_errno (0);
|
||||
xfree (buffer);
|
||||
my_set_errno (0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -554,7 +553,7 @@ read_lockfile (dotlock_t h, int *same_node )
|
||||
*same_node = 1;
|
||||
|
||||
if (buffer != buffer_space)
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
return pid;
|
||||
}
|
||||
#endif /*HAVE_POSIX_SYSTEM */
|
||||
@ -578,7 +577,7 @@ use_hardlinks_p (const char *tname)
|
||||
return -1;
|
||||
nlink = (unsigned int)sb.st_nlink;
|
||||
|
||||
lname = jnlib_malloc (strlen (tname) + 1 + 1);
|
||||
lname = xtrymalloc (strlen (tname) + 1 + 1);
|
||||
if (!lname)
|
||||
return -1;
|
||||
strcpy (lname, tname);
|
||||
@ -595,7 +594,7 @@ use_hardlinks_p (const char *tname)
|
||||
res = 1; /* No hardlink support. */
|
||||
|
||||
unlink (lname);
|
||||
jnlib_free (lname);
|
||||
xfree (lname);
|
||||
return res;
|
||||
}
|
||||
#endif /*HAVE_POSIX_SYSTEM */
|
||||
@ -640,12 +639,12 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
|
||||
all_lockfiles = h;
|
||||
|
||||
tnamelen = dirpartlen + 6 + 30 + strlen(nodename) + 10 + 1;
|
||||
h->tname = jnlib_malloc (tnamelen + 1);
|
||||
h->tname = xtrymalloc (tnamelen + 1);
|
||||
if (!h->tname)
|
||||
{
|
||||
all_lockfiles = h->next;
|
||||
UNLOCK_all_lockfiles ();
|
||||
jnlib_free (h);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
h->nodename_len = strlen (nodename);
|
||||
@ -657,7 +656,7 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
|
||||
|
||||
do
|
||||
{
|
||||
jnlib_set_errno (0);
|
||||
my_set_errno (0);
|
||||
fd = open (h->tname, O_WRONLY|O_CREAT|O_EXCL,
|
||||
S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR );
|
||||
}
|
||||
@ -669,8 +668,8 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
|
||||
UNLOCK_all_lockfiles ();
|
||||
my_error_2 (_("failed to create temporary file '%s': %s\n"),
|
||||
h->tname, strerror(errno));
|
||||
jnlib_free (h->tname);
|
||||
jnlib_free (h);
|
||||
xfree (h->tname);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
if ( write (fd, pidstr, 11 ) != 11 )
|
||||
@ -702,14 +701,14 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
|
||||
goto write_failed;
|
||||
}
|
||||
|
||||
h->lockname = jnlib_malloc (strlen (file_to_lock) + 6 );
|
||||
h->lockname = xtrymalloc (strlen (file_to_lock) + 6 );
|
||||
if (!h->lockname)
|
||||
{
|
||||
all_lockfiles = h->next;
|
||||
UNLOCK_all_lockfiles ();
|
||||
unlink (h->tname);
|
||||
jnlib_free (h->tname);
|
||||
jnlib_free (h);
|
||||
xfree (h->tname);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
strcpy (stpcpy (h->lockname, file_to_lock), EXTSEP_S "lock");
|
||||
@ -726,8 +725,8 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
|
||||
if ( fd != -1 )
|
||||
close (fd);
|
||||
unlink (h->tname);
|
||||
jnlib_free (h->tname);
|
||||
jnlib_free (h);
|
||||
xfree (h->tname);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
#endif /*HAVE_POSIX_SYSTEM*/
|
||||
@ -746,12 +745,12 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
|
||||
h->next = all_lockfiles;
|
||||
all_lockfiles = h;
|
||||
|
||||
h->lockname = jnlib_malloc ( strlen (file_to_lock) + 6 );
|
||||
h->lockname = xtrymalloc ( strlen (file_to_lock) + 6 );
|
||||
if (!h->lockname)
|
||||
{
|
||||
all_lockfiles = h->next;
|
||||
UNLOCK_all_lockfiles ();
|
||||
jnlib_free (h);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
strcpy (stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
|
||||
@ -775,7 +774,7 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
|
||||
NULL, OPEN_ALWAYS, 0, NULL);
|
||||
else
|
||||
h->lockhd = INVALID_HANDLE_VALUE;
|
||||
jnlib_free (wname);
|
||||
xfree (wname);
|
||||
#else
|
||||
h->lockhd = CreateFile (h->lockname,
|
||||
GENERIC_READ|GENERIC_WRITE,
|
||||
@ -788,8 +787,8 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
|
||||
all_lockfiles = h->next;
|
||||
UNLOCK_all_lockfiles ();
|
||||
my_error_2 (_("can't create '%s': %s\n"), h->lockname, w32_strerror (-1));
|
||||
jnlib_free (h->lockname);
|
||||
jnlib_free (h);
|
||||
xfree (h->lockname);
|
||||
xfree (h);
|
||||
return NULL;
|
||||
}
|
||||
return h;
|
||||
@ -835,11 +834,11 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
|
||||
|
||||
if (flags)
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
my_set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
h = jnlib_calloc (1, sizeof *h);
|
||||
h = xtrycalloc (1, sizeof *h);
|
||||
if (!h)
|
||||
return NULL;
|
||||
h->extra_fd = -1;
|
||||
@ -890,7 +889,7 @@ dotlock_destroy_unix (dotlock_t h)
|
||||
unlink (h->lockname);
|
||||
if (h->tname && !h->use_o_excl)
|
||||
unlink (h->tname);
|
||||
jnlib_free (h->tname);
|
||||
xfree (h->tname);
|
||||
}
|
||||
#endif /*HAVE_POSIX_SYSTEM*/
|
||||
|
||||
@ -943,9 +942,9 @@ dotlock_destroy (dotlock_t h)
|
||||
#else /* !HAVE_DOSISH_SYSTEM */
|
||||
dotlock_destroy_unix (h);
|
||||
#endif /* HAVE_DOSISH_SYSTEM */
|
||||
jnlib_free (h->lockname);
|
||||
xfree (h->lockname);
|
||||
}
|
||||
jnlib_free(h);
|
||||
xfree(h);
|
||||
}
|
||||
|
||||
|
||||
@ -972,7 +971,7 @@ dotlock_take_unix (dotlock_t h, long timeout)
|
||||
|
||||
do
|
||||
{
|
||||
jnlib_set_errno (0);
|
||||
my_set_errno (0);
|
||||
fd = open (h->lockname, O_WRONLY|O_CREAT|O_EXCL,
|
||||
S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR );
|
||||
}
|
||||
@ -1101,7 +1100,7 @@ dotlock_take_unix (dotlock_t h, long timeout)
|
||||
goto again;
|
||||
}
|
||||
|
||||
jnlib_set_errno (EACCES);
|
||||
my_set_errno (EACCES);
|
||||
return -1;
|
||||
}
|
||||
#endif /*HAVE_POSIX_SYSTEM*/
|
||||
|
@ -46,7 +46,7 @@ dlopen (const char *name, int flag)
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
wchar_t *wname = utf8_to_wchar (name);
|
||||
hd = wname? LoadLibrary (wname) : NULL;
|
||||
_jnlib_free (wname);
|
||||
xfree (wname);
|
||||
#else
|
||||
hd = LoadLibrary (name);
|
||||
#endif
|
||||
@ -62,7 +62,7 @@ dlsym (void *hd, const char *sym)
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
wchar_t *wsym = utf8_to_wchar (sym);
|
||||
void *fnc = wsym? GetProcAddress (hd, wsym) : NULL;
|
||||
_jnlib_free (wsym);
|
||||
xfree (wsym);
|
||||
#else
|
||||
void *fnc = GetProcAddress (hd, sym);
|
||||
#endif
|
||||
|
@ -1,110 +0,0 @@
|
||||
/* libjnlib-config.h - local configuration of the jnlib functions
|
||||
* Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of JNLIB, which is a subsystem of GnuPG.
|
||||
*
|
||||
* JNLIB is free software; you can redistribute it and/or modify it
|
||||
* under the terms of either
|
||||
*
|
||||
* - the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* or
|
||||
*
|
||||
* - the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* or both in parallel, as here.
|
||||
*
|
||||
* JNLIB 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copies of the GNU General Public License
|
||||
* and the GNU Lesser General Public License along with this program;
|
||||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/****************
|
||||
* This header is to be included only by the files in this directory
|
||||
* it should not be used by other modules.
|
||||
*/
|
||||
|
||||
#ifndef LIBJNLIB_CONFIG_H
|
||||
#define LIBJNLIB_CONFIG_H
|
||||
|
||||
#include <gcrypt.h> /* gcry_malloc & Cie. */
|
||||
#include "logging.h"
|
||||
|
||||
/* We require support for utf-8 conversion. */
|
||||
#define JNLIB_NEED_UTF8CONV 1
|
||||
|
||||
|
||||
|
||||
#if !defined(JNLIB_NEED_UTF8CONV) && defined(HAVE_W32_SYSTEM)
|
||||
#define JNLIB_NEED_UTF8CONV 1
|
||||
#endif
|
||||
|
||||
/* Gettext stuff */
|
||||
#ifdef USE_SIMPLE_GETTEXT
|
||||
# include <gpg-error.h>
|
||||
# define _(a) gettext (a)
|
||||
# define N_(a) (a)
|
||||
|
||||
#else
|
||||
#ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(a) gettext (a)
|
||||
# ifdef gettext_noop
|
||||
# define N_(a) gettext_noop (a)
|
||||
# else
|
||||
# define N_(a) (a)
|
||||
# endif
|
||||
#else
|
||||
# define _(a) (a)
|
||||
# define N_(a) (a)
|
||||
#endif
|
||||
#endif /* !USE_SIMPLE_GETTEXT */
|
||||
|
||||
/* Malloc functions to be used by jnlib. */
|
||||
#define jnlib_malloc(a) gcry_malloc( (a) )
|
||||
#define jnlib_calloc(a,b) gcry_calloc( (a), (b) )
|
||||
#define jnlib_realloc(a,b) gcry_realloc( (a), (b) )
|
||||
#define jnlib_strdup(a) gcry_strdup( (a) )
|
||||
#define jnlib_xmalloc(a) gcry_xmalloc( (a) )
|
||||
#define jnlib_xcalloc(a,b) gcry_xcalloc( (a), (b) )
|
||||
#define jnlib_xrealloc(a,n) gcry_xrealloc( (a), (n) )
|
||||
#define jnlib_xstrdup(a) gcry_xstrdup( (a) )
|
||||
#define jnlib_free(a) gcry_free( (a) )
|
||||
|
||||
/* Logging functions to be used by jnlib. */
|
||||
#define jnlib_log_debug log_debug
|
||||
#define jnlib_log_info log_info
|
||||
#define jnlib_log_error log_error
|
||||
#define jnlib_log_fatal log_fatal
|
||||
#define jnlib_log_bug log_bug
|
||||
|
||||
/* Wrapper to set ERRNO. */
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
# define jnlib_set_errno(e) gpg_err_set_errno ((e))
|
||||
#else
|
||||
# define jnlib_set_errno(e) do { errno = (e); } while (0)
|
||||
#endif
|
||||
|
||||
/* Dummy replacement for getenv. */
|
||||
#ifndef HAVE_GETENV
|
||||
#define getenv(a) (NULL)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_W32CE_SYSTEM
|
||||
#define getpid() GetCurrentProcessId ()
|
||||
#endif
|
||||
|
||||
#endif /*LIBJNUTIL_CONFIG_H*/
|
@ -56,9 +56,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define JNLIB_NEED_LOG_LOGV 1
|
||||
#define JNLIB_NEED_AFLOCAL 1
|
||||
#include "libjnlib-config.h"
|
||||
#include "util.h"
|
||||
#include "i18n.h"
|
||||
#include "common-defs.h"
|
||||
#include "logging.h"
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
@ -261,7 +262,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
|
||||
void *addrbuf = NULL;
|
||||
#endif /*HAVE_INET_PTON*/
|
||||
|
||||
addrstr = jnlib_malloc (strlen (name) + 1);
|
||||
addrstr = xtrymalloc (strlen (name) + 1);
|
||||
if (!addrstr)
|
||||
addrlen = 0; /* This indicates an error. */
|
||||
else if (*name == '[')
|
||||
@ -271,7 +272,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
|
||||
p = strchr (addrstr, ']');
|
||||
if (!p || p[1] != ':' || !parse_portno (p+2, &port))
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
addrlen = 0;
|
||||
}
|
||||
else
|
||||
@ -289,7 +290,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
|
||||
srvr_addr = (struct sockaddr *)&srvr_addr_in6;
|
||||
addrlen = sizeof srvr_addr_in6;
|
||||
#else
|
||||
jnlib_set_errno (EAFNOSUPPORT);
|
||||
gpg_err_set_errno (EAFNOSUPPORT);
|
||||
addrlen = 0;
|
||||
#endif
|
||||
}
|
||||
@ -301,7 +302,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
|
||||
p = strchr (addrstr, ':');
|
||||
if (!p || !parse_portno (p+1, &port))
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
addrlen = 0;
|
||||
}
|
||||
else
|
||||
@ -334,7 +335,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size)
|
||||
#endif /*!HAVE_INET_PTON*/
|
||||
}
|
||||
|
||||
jnlib_free (addrstr);
|
||||
xfree (addrstr);
|
||||
}
|
||||
|
||||
cookie->fd = addrlen? socket (pf, SOCK_STREAM, 0) : -1;
|
||||
@ -425,7 +426,7 @@ fun_closer (void *cookie_arg)
|
||||
|
||||
if (cookie->fd != -1 && cookie->fd != 2)
|
||||
sock_close (cookie->fd);
|
||||
jnlib_free (cookie);
|
||||
xfree (cookie);
|
||||
log_socket = -1;
|
||||
return 0;
|
||||
}
|
||||
@ -487,7 +488,7 @@ set_file_fd (const char *name, int fd)
|
||||
/* The xmalloc below is justified because we can expect that this
|
||||
function is called only during initialization and there is no
|
||||
easy way out of this error condition. */
|
||||
cookie = jnlib_xmalloc (sizeof *cookie + (name? strlen (name):0));
|
||||
cookie = xmalloc (sizeof *cookie + (name? strlen (name):0));
|
||||
strcpy (cookie->name, name? name:"");
|
||||
cookie->quiet = 0;
|
||||
cookie->is_socket = 0;
|
||||
@ -648,7 +649,7 @@ do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr)
|
||||
: read_w32_registry_string (NULL, GNUPG_REGISTRY_DIR,
|
||||
"DefaultLogFile"));
|
||||
log_set_file (tmp && *tmp? tmp : NULL);
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
#else
|
||||
log_set_file (NULL); /* Make sure a log stream has been set. */
|
||||
#endif
|
||||
|
@ -33,16 +33,10 @@
|
||||
#define LIBJNLIB_LOGGING_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "mischelp.h"
|
||||
#include "w32help.h"
|
||||
|
||||
/* Flag values for log_set_prefix. */
|
||||
#define JNLIB_LOG_WITH_PREFIX 1
|
||||
#define JNLIB_LOG_WITH_TIME 2
|
||||
#define JNLIB_LOG_WITH_PID 4
|
||||
#define JNLIB_LOG_RUN_DETACHED 256
|
||||
#define JNLIB_LOG_NO_REGISTRY 512
|
||||
|
||||
int log_get_errorcount (int clear);
|
||||
void log_inc_errorcount (void);
|
||||
void log_set_file( const char *name );
|
||||
@ -62,10 +56,14 @@ estream_t log_get_stream (void);
|
||||
# define BUG() bug_at( __FILE__ , __LINE__ )
|
||||
#endif
|
||||
|
||||
/* To avoid mandatory inclusion of stdarg and other stuff, do it only
|
||||
if explicitly requested to do so. */
|
||||
#ifdef JNLIB_NEED_LOG_LOGV
|
||||
#include <stdarg.h>
|
||||
/* Flag values for log_set_prefix. */
|
||||
#define JNLIB_LOG_WITH_PREFIX 1
|
||||
#define JNLIB_LOG_WITH_TIME 2
|
||||
#define JNLIB_LOG_WITH_PID 4
|
||||
#define JNLIB_LOG_RUN_DETACHED 256
|
||||
#define JNLIB_LOG_NO_REGISTRY 512
|
||||
|
||||
/* Log levels as used by log_log. */
|
||||
enum jnlib_log_levels {
|
||||
JNLIB_LOG_BEGIN,
|
||||
JNLIB_LOG_CONT,
|
||||
@ -79,7 +77,6 @@ enum jnlib_log_levels {
|
||||
void log_log (int level, const char *fmt, ...) JNLIB_GCC_A_PRINTF(2,3);
|
||||
void log_logv (int level, const char *fmt, va_list arg_ptr);
|
||||
void log_string (int level, const char *string);
|
||||
#endif /*JNLIB_NEED_LOG_LOGV*/
|
||||
|
||||
|
||||
void log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
|
||||
|
@ -42,22 +42,13 @@
|
||||
#endif /*!HAVE_W32_SYSTEM*/
|
||||
#include <errno.h>
|
||||
|
||||
#include "libjnlib-config.h"
|
||||
#include "util.h"
|
||||
#include "common-defs.h"
|
||||
#include "stringhelp.h"
|
||||
#include "utf8conv.h"
|
||||
#include "mischelp.h"
|
||||
|
||||
|
||||
/* Because we can't use our jnlib_free macro in inline functions we
|
||||
provide this wrapper. */
|
||||
void
|
||||
_jnlib_free (void *p)
|
||||
{
|
||||
if (p)
|
||||
jnlib_free (p);
|
||||
}
|
||||
|
||||
|
||||
/* Check whether the files NAME1 and NAME2 are identical. This is for
|
||||
example achieved by comparing the inode numbers of the files. */
|
||||
int
|
||||
@ -81,7 +72,7 @@ same_file_p (const char *name1, const char *name2)
|
||||
file1 = CreateFile (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
else
|
||||
file1 = INVALID_HANDLE_VALUE;
|
||||
jnlib_free (wname);
|
||||
xfree (wname);
|
||||
}
|
||||
#else
|
||||
file1 = CreateFile (name1, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
@ -97,7 +88,7 @@ same_file_p (const char *name1, const char *name2)
|
||||
file2 = CreateFile (wname, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
else
|
||||
file2 = INVALID_HANDLE_VALUE;
|
||||
jnlib_free (wname);
|
||||
xfree (wname);
|
||||
}
|
||||
#else
|
||||
file2 = CreateFile (name2, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
@ -159,7 +150,7 @@ timegm (struct tm *tm)
|
||||
/* System time is UTC thus the conversion is pretty easy. */
|
||||
if (!SystemTimeToFileTime (&st, &ft))
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
return (time_t)(-1);
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,6 @@
|
||||
#define LIBJNLIB_MISCHELP_H
|
||||
|
||||
|
||||
/* Because we can't use the internal jnlib_free macro in inline
|
||||
functions we provide a wrapper function as well. */
|
||||
void _jnlib_free (void *p);
|
||||
|
||||
/* Check whether the files NAME1 and NAME2 are identical. This is for
|
||||
example achieved by comparing the inode numbers of the files. */
|
||||
int same_file_p (const char *name1, const char *name2);
|
||||
|
@ -50,7 +50,7 @@
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "libjnlib-config.h"
|
||||
#include "common-defs.h"
|
||||
#include "utf8conv.h"
|
||||
#include "sysutils.h"
|
||||
#include "stringhelp.h"
|
||||
@ -427,7 +427,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
|
||||
{
|
||||
if (xmode)
|
||||
BUG ();
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
argc++;
|
||||
@ -1136,7 +1136,7 @@ do_strconcat (const char *s1, va_list arg_ptr)
|
||||
needed += strlen (argv[argc]);
|
||||
if (argc >= DIM (argv)-1)
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
argc++;
|
||||
|
@ -35,11 +35,10 @@
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "libjnlib-config.h"
|
||||
#include "util.h"
|
||||
#include "common-defs.h"
|
||||
#include "strlist.h"
|
||||
#ifdef JNLIB_NEED_UTF8CONV
|
||||
#include "utf8conv.h"
|
||||
#endif
|
||||
|
||||
void
|
||||
free_strlist( strlist_t sl )
|
||||
@ -48,7 +47,7 @@ free_strlist( strlist_t sl )
|
||||
|
||||
for(; sl; sl = sl2 ) {
|
||||
sl2 = sl->next;
|
||||
jnlib_free(sl);
|
||||
xfree(sl);
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +59,7 @@ add_to_strlist( strlist_t *list, const char *string )
|
||||
{
|
||||
strlist_t sl;
|
||||
|
||||
sl = jnlib_xmalloc( sizeof *sl + strlen(string));
|
||||
sl = xmalloc( sizeof *sl + strlen(string));
|
||||
sl->flags = 0;
|
||||
strcpy(sl->d, string);
|
||||
sl->next = *list;
|
||||
@ -76,7 +75,7 @@ add_to_strlist_try (strlist_t *list, const char *string)
|
||||
{
|
||||
strlist_t sl;
|
||||
|
||||
sl = jnlib_malloc (sizeof *sl + strlen (string));
|
||||
sl = xtrymalloc (sizeof *sl + strlen (string));
|
||||
if (sl)
|
||||
{
|
||||
sl->flags = 0;
|
||||
@ -91,7 +90,6 @@ add_to_strlist_try (strlist_t *list, const char *string)
|
||||
/* Same as add_to_strlist() but if IS_UTF8 is *not* set, a conversion
|
||||
to UTF-8 is done. This function terminates the process on memory
|
||||
shortage. */
|
||||
#ifdef JNLIB_NEED_UTF8CONV
|
||||
strlist_t
|
||||
add_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
|
||||
{
|
||||
@ -103,11 +101,10 @@ add_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
|
||||
{
|
||||
char *p = native_to_utf8( string );
|
||||
sl = add_to_strlist( list, p );
|
||||
jnlib_free ( p );
|
||||
xfree ( p );
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
#endif /* JNLIB_NEED_UTF8CONV*/
|
||||
|
||||
|
||||
/* Add STRING to the LIST at the end. This function terminates the
|
||||
@ -117,7 +114,7 @@ append_to_strlist( strlist_t *list, const char *string )
|
||||
{
|
||||
strlist_t r, sl;
|
||||
|
||||
sl = jnlib_xmalloc( sizeof *sl + strlen(string));
|
||||
sl = xmalloc( sizeof *sl + strlen(string));
|
||||
sl->flags = 0;
|
||||
strcpy(sl->d, string);
|
||||
sl->next = NULL;
|
||||
@ -132,7 +129,6 @@ append_to_strlist( strlist_t *list, const char *string )
|
||||
}
|
||||
|
||||
|
||||
#ifdef JNLIB_NEED_UTF8CONV
|
||||
strlist_t
|
||||
append_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
|
||||
{
|
||||
@ -144,11 +140,10 @@ append_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
|
||||
{
|
||||
char *p = native_to_utf8 (string);
|
||||
sl = append_to_strlist( list, p );
|
||||
jnlib_free( p );
|
||||
xfree( p );
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
#endif /* JNLIB_NEED_UTF8CONV */
|
||||
|
||||
|
||||
/* Return a copy of LIST. This function terminates the process on
|
||||
@ -161,7 +156,7 @@ strlist_copy (strlist_t list)
|
||||
last = &newlist;
|
||||
for (; list; list = list->next)
|
||||
{
|
||||
sl = jnlib_xmalloc (sizeof *sl + strlen (list->d));
|
||||
sl = xmalloc (sizeof *sl + strlen (list->d));
|
||||
sl->flags = list->flags;
|
||||
strcpy(sl->d, list->d);
|
||||
sl->next = NULL;
|
||||
@ -204,11 +199,11 @@ strlist_pop (strlist_t *list)
|
||||
|
||||
if(sl)
|
||||
{
|
||||
str=jnlib_xmalloc(strlen(sl->d)+1);
|
||||
str = xmalloc(strlen(sl->d)+1);
|
||||
strcpy(str,sl->d);
|
||||
|
||||
*list=sl->next;
|
||||
jnlib_free(sl);
|
||||
xfree(sl);
|
||||
}
|
||||
|
||||
return str;
|
||||
|
@ -128,9 +128,7 @@ gcry_free (void *a)
|
||||
|
||||
/* Stubs for gpg-error functions required because some compilers do
|
||||
not eliminate the supposed-to-be-unused-inline-functions and thus
|
||||
require functions called from these inline fucntions. Although we
|
||||
do not use gpg-error, gpg-error.h may get included via gcrypt.h if
|
||||
it happens to be used used in libjnlib-config.h. */
|
||||
require functions called from these inline functions. */
|
||||
#ifndef GPG_ERROR_H /* Don't do this if gpg-error.h has been included. */
|
||||
int
|
||||
gpg_err_code_from_errno (int err)
|
||||
|
@ -42,7 +42,9 @@
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
|
||||
#include "libjnlib-config.h"
|
||||
#include "util.h"
|
||||
#include "common-defs.h"
|
||||
#include "i18n.h"
|
||||
#include "stringhelp.h"
|
||||
#include "utf8conv.h"
|
||||
|
||||
@ -318,7 +320,7 @@ native_to_utf8 (const char *orig_string)
|
||||
if (no_translation)
|
||||
{
|
||||
/* Already utf-8 encoded. */
|
||||
buffer = jnlib_xstrdup (orig_string);
|
||||
buffer = xstrdup (orig_string);
|
||||
}
|
||||
else if (!use_iconv)
|
||||
{
|
||||
@ -329,7 +331,7 @@ native_to_utf8 (const char *orig_string)
|
||||
if (*s & 0x80)
|
||||
length++;
|
||||
}
|
||||
buffer = jnlib_xmalloc (length + 1);
|
||||
buffer = xmalloc (length + 1);
|
||||
for (p = (unsigned char *)buffer, s = string; *s; s++)
|
||||
{
|
||||
if ( (*s & 0x80 ))
|
||||
@ -363,7 +365,7 @@ native_to_utf8 (const char *orig_string)
|
||||
if ((*s & 0x80))
|
||||
length += 5; /* We may need up to 6 bytes for the utf8 output. */
|
||||
}
|
||||
buffer = jnlib_xmalloc (length + 1);
|
||||
buffer = xmalloc (length + 1);
|
||||
|
||||
inptr = string;
|
||||
inbytes = strlen (string);
|
||||
@ -606,7 +608,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
|
||||
if (!buffer)
|
||||
{
|
||||
/* Allocate the buffer after the first pass. */
|
||||
buffer = p = jnlib_xmalloc (n + 1);
|
||||
buffer = p = xmalloc (n + 1);
|
||||
}
|
||||
else if (with_iconv)
|
||||
{
|
||||
@ -622,7 +624,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
|
||||
if (cd == (iconv_t)-1)
|
||||
{
|
||||
handle_iconv_error (active_charset_name, "utf-8", 1);
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
return utf8_to_native (string, length, delim);
|
||||
}
|
||||
|
||||
@ -634,7 +636,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
|
||||
outbytes = n * MB_LEN_MAX;
|
||||
if (outbytes / MB_LEN_MAX != n)
|
||||
BUG (); /* Actually an overflow. */
|
||||
outbuf = outptr = jnlib_xmalloc (outbytes);
|
||||
outbuf = outptr = xmalloc (outbytes);
|
||||
if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
|
||||
&outptr, &outbytes) == (size_t)-1)
|
||||
{
|
||||
@ -645,9 +647,9 @@ do_utf8_to_native (const char *string, size_t length, int delim,
|
||||
"utf-8", active_charset_name, strerror (errno));
|
||||
shown = 1;
|
||||
/* Didn't worked out. Try again but without iconv. */
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
buffer = NULL;
|
||||
jnlib_free (outbuf);
|
||||
xfree (outbuf);
|
||||
outbuf = do_utf8_to_native (string, length, delim, 0);
|
||||
}
|
||||
else /* Success. */
|
||||
@ -656,7 +658,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
|
||||
/* We could realloc the buffer now but I doubt that it
|
||||
makes much sense given that it will get freed
|
||||
anyway soon after. */
|
||||
jnlib_free (buffer);
|
||||
xfree (buffer);
|
||||
}
|
||||
iconv_close (cd);
|
||||
return outbuf;
|
||||
@ -726,19 +728,19 @@ wchar_to_utf8 (const wchar_t *string)
|
||||
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
|
||||
if (n < 0)
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = jnlib_malloc (n+1);
|
||||
result = xtrymalloc (n+1);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
|
||||
if (n < 0)
|
||||
{
|
||||
jnlib_free (result);
|
||||
jnlib_set_errno (EINVAL);
|
||||
xfree (result);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
@ -759,25 +761,25 @@ utf8_to_wchar (const char *string)
|
||||
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
|
||||
if (n < 0)
|
||||
{
|
||||
jnlib_set_errno (EINVAL);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nbytes = (size_t)(n+1) * sizeof(*result);
|
||||
if (nbytes / sizeof(*result) != (n+1))
|
||||
{
|
||||
jnlib_set_errno (ENOMEM);
|
||||
gpg_err_set_errno (ENOMEM);
|
||||
return NULL;
|
||||
}
|
||||
result = jnlib_malloc (nbytes);
|
||||
result = xtrymalloc (nbytes);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
|
||||
if (n < 0)
|
||||
{
|
||||
free (result);
|
||||
jnlib_set_errno (EINVAL);
|
||||
xfree (result);
|
||||
gpg_err_set_errno (EINVAL);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
|
@ -41,7 +41,8 @@
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
#include "libjnlib-config.h"
|
||||
#include "util.h"
|
||||
#include "common-defs.h"
|
||||
#include "utf8conv.h"
|
||||
#include "w32help.h"
|
||||
|
||||
@ -95,17 +96,17 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
|
||||
{
|
||||
if (root)
|
||||
{
|
||||
jnlib_free (wdir);
|
||||
xfree (wdir);
|
||||
return NULL; /* No need for a RegClose, so return immediately. */
|
||||
}
|
||||
/* It seems to be common practise to fall back to HKLM. */
|
||||
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, wdir, 0, KEY_READ, &key_handle) )
|
||||
{
|
||||
jnlib_free (wdir);
|
||||
xfree (wdir);
|
||||
return NULL; /* Still no need for a RegClose. */
|
||||
}
|
||||
}
|
||||
jnlib_free (wdir);
|
||||
xfree (wdir);
|
||||
|
||||
if (name)
|
||||
{
|
||||
@ -119,12 +120,12 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
|
||||
nbytes = 2;
|
||||
if (RegQueryValueEx (key_handle, wname, 0, NULL, NULL, &nbytes))
|
||||
goto leave;
|
||||
result = jnlib_malloc ((n1=nbytes+2));
|
||||
result = xtrymalloc ((n1=nbytes+2));
|
||||
if (!result)
|
||||
goto leave;
|
||||
if (RegQueryValueEx (key_handle, wname, 0, &type, result, &n1))
|
||||
{
|
||||
jnlib_free (result);
|
||||
xfree (result);
|
||||
result = NULL;
|
||||
goto leave;
|
||||
}
|
||||
@ -134,11 +135,11 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
|
||||
{
|
||||
wchar_t *tmp = (void*)result;
|
||||
result = wchar_to_utf8 (tmp);
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
}
|
||||
|
||||
leave:
|
||||
jnlib_free (wname);
|
||||
xfree (wname);
|
||||
RegCloseKey (key_handle);
|
||||
return result;
|
||||
#else /*!HAVE_W32CE_SYSTEM*/
|
||||
@ -161,12 +162,12 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
|
||||
nbytes = 1;
|
||||
if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) )
|
||||
goto leave;
|
||||
result = jnlib_malloc ((n1=nbytes+1));
|
||||
result = xtrymalloc ((n1=nbytes+1));
|
||||
if (!result)
|
||||
goto leave;
|
||||
if (RegQueryValueEx( key_handle, name, 0, &type, result, &n1 ))
|
||||
{
|
||||
jnlib_free (result);
|
||||
xfree (result);
|
||||
result = NULL;
|
||||
goto leave;
|
||||
}
|
||||
@ -176,46 +177,46 @@ read_w32_registry_string (const char *root, const char *dir, const char *name)
|
||||
char *tmp;
|
||||
|
||||
n1 += 1000;
|
||||
tmp = jnlib_malloc (n1+1);
|
||||
tmp = xtrymalloc (n1+1);
|
||||
if (!tmp)
|
||||
goto leave;
|
||||
nbytes = ExpandEnvironmentStrings (result, tmp, n1);
|
||||
if (nbytes && nbytes > n1)
|
||||
{
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
n1 = nbytes;
|
||||
tmp = jnlib_malloc (n1 + 1);
|
||||
tmp = xtrymalloc (n1 + 1);
|
||||
if (!tmp)
|
||||
goto leave;
|
||||
nbytes = ExpandEnvironmentStrings (result, tmp, n1);
|
||||
if (nbytes && nbytes > n1)
|
||||
{
|
||||
/* Oops - truncated, better don't expand at all. */
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
goto leave;
|
||||
}
|
||||
tmp[nbytes] = 0;
|
||||
jnlib_free (result);
|
||||
xfree (result);
|
||||
result = tmp;
|
||||
}
|
||||
else if (nbytes)
|
||||
{
|
||||
/* Okay, reduce the length. */
|
||||
tmp[nbytes] = 0;
|
||||
jnlib_free (result);
|
||||
result = jnlib_malloc (strlen (tmp)+1);
|
||||
xfree (result);
|
||||
result = xtrymalloc (strlen (tmp)+1);
|
||||
if (!result)
|
||||
result = tmp;
|
||||
else
|
||||
{
|
||||
strcpy (result, tmp);
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error - don't expand. */
|
||||
jnlib_free (tmp);
|
||||
xfree (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user