[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11952 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11952 - gnunet/src/util |
Date: |
Fri, 25 Jun 2010 17:37:07 +0200 |
Author: grothoff
Date: 2010-06-25 17:37:07 +0200 (Fri, 25 Jun 2010)
New Revision: 11952
Removed:
gnunet/src/util/common_gettext.c
gnunet/src/util/program_lib_argz.c
gnunet/src/util/program_lib_mempcpy.c
gnunet/src/util/program_lib_strndup.c
gnunet/src/util/program_lib_strnlen.c
Modified:
gnunet/src/util/Makefile.am
gnunet/src/util/common_logging.c
gnunet/src/util/connection.c
gnunet/src/util/crypto_crc.c
gnunet/src/util/crypto_ksk.c
gnunet/src/util/crypto_random.c
gnunet/src/util/os_load.c
gnunet/src/util/plugin.c
gnunet/src/util/program.c
gnunet/src/util/test_crypto_ksk.c
gnunet/src/util/test_crypto_rsa.c
Log:
cleaning argz mess
Modified: gnunet/src/util/Makefile.am
===================================================================
--- gnunet/src/util/Makefile.am 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/Makefile.am 2010-06-25 15:37:07 UTC (rev 11952)
@@ -29,7 +29,6 @@
client.c \
common_allocation.c \
common_endian.c \
- common_gettext.c \
common_logging.c \
configuration.c \
connection.c \
@@ -370,10 +369,6 @@
EXTRA_DIST = \
- program_lib_argz.c \
- program_lib_strndup.c \
- program_lib_strnlen.c \
- program_lib_mempcpy.c \
test_configuration_data.conf \
test_program_data.conf \
test_pseudonym_data.conf \
Deleted: gnunet/src/util/common_gettext.c
===================================================================
--- gnunet/src/util/common_gettext.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/common_gettext.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -1,42 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2008 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- GNUnet 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 copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file util/common_gettext.c
- * @brief gettext init routine
- * @author Heikki Lindholm
- */
-#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_os_lib.h"
-
-void __attribute__ ((constructor)) GNUNET_util_generic_ltdl_init ()
-{
-#if ENABLE_NLS
- char *path;
-
- path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
- if (path != NULL)
- {
- BINDTEXTDOMAIN ("GNUnet", path);
- GNUNET_free (path);
- }
-#endif
-}
Modified: gnunet/src/util/common_logging.c
===================================================================
--- gnunet/src/util/common_logging.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/common_logging.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -571,6 +571,20 @@
void __attribute__ ((constructor)) GNUNET_util_cl_init ()
{
GNUNET_stderr = stderr;
+#ifdef MINGW
+ InitWinEnv (NULL);
+#endif
}
+
+/**
+ * Destructor
+ */
+void __attribute__ ((destructor)) GNUNET_util_cl_fini ()
+{
+#ifdef MINGW
+ ShutdownWinEnv ();
+#endif
+}
+
/* end of common_logging.c */
Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/connection.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -726,11 +726,11 @@
len = sizeof (error);
errno = 0;
error = 0;
- if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR,
- &error, &len)) || (error != 0)
- || (errno != 0))
+ if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR,
+ &error, &len)) ||
+ (error != 0) )
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
GNUNET_free (ap);
Modified: gnunet/src/util/crypto_crc.c
===================================================================
--- gnunet/src/util/crypto_crc.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/crypto_crc.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -52,10 +52,16 @@
* with the ccorrect final value. Thus, it is safe to call
* even on a table that someone else is using concurrently.
*/
-void __attribute__ ((constructor)) GNUNET_CRYPTO_crc_init ()
+static void
+crc_init ()
{
+ static int once;
unsigned int i, j;
uLong h = 1;
+
+ if (once)
+ return;
+ once = 1;
crc_table[0] = 0;
for (i = 128; i; i >>= 1)
{
@@ -79,6 +85,7 @@
static uLong
crc32 (uLong crc, const char *buf, size_t len)
{
+ crc_init ();
GNUNET_assert (crc_table[255] != 0);
crc ^= 0xffffffff;
while (len--)
Modified: gnunet/src/util/crypto_ksk.c
===================================================================
--- gnunet/src/util/crypto_ksk.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/crypto_ksk.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -684,8 +684,6 @@
}
-
-
typedef struct
{
GNUNET_HashCode hc;
@@ -693,6 +691,7 @@
} KBlockKeyCacheLine;
static KBlockKeyCacheLine **cache;
+
static unsigned int cacheSize;
/**
@@ -724,92 +723,6 @@
}
-/**
- * Process ID of the "find" process that we use for
- * entropy gathering.
- */
-static pid_t genproc;
-
-/**
- * Function called by libgcrypt whenever we are
- * blocked gathering entropy.
- */
-static void
-entropy_generator (void *cls,
- const char *what, int printchar, int current, int total)
-{
- unsigned long code;
- enum GNUNET_OS_ProcessStatusType type;
- int ret;
-
- if (0 != strcmp (what, "need_entropy"))
- return;
- if (current == total)
- {
- if (genproc != 0)
- {
- if (0 != PLIBC_KILL (genproc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
- GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
- genproc = 0;
- }
- return;
- }
- if (genproc != 0)
- {
- ret = GNUNET_OS_process_status (genproc, &type, &code);
- if (ret == GNUNET_NO)
- return; /* still running */
- if (ret == GNUNET_SYSERR)
- {
- GNUNET_break (0);
- return;
- }
- if (0 != PLIBC_KILL (genproc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
- GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
- genproc = 0;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting `%s' process to generate entropy\n"), "find");
- genproc = GNUNET_OS_start_process (NULL, NULL, "sh",
- "sh",
- "-c",
- "exec find / -mount -type f -exec cp {}
/dev/null \\; 2>/dev/null",
- NULL);
-}
-
-
-static void
-killfind ()
-{
- if (genproc != 0)
- {
- PLIBC_KILL (genproc, SIGKILL);
- genproc = 0;
- }
-}
-
-
-void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init ()
-{
- gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
- if (!gcry_check_version (GCRYPT_VERSION))
- {
- fprintf (stderr,
- _
- ("libgcrypt has not the expected version (version %s is
required).\n"),
- GCRYPT_VERSION);
- abort ();
- }
-#ifdef gcry_fast_random_poll
- gcry_fast_random_poll ();
-#endif
- gcry_set_progress_handler (&entropy_generator, NULL);
- atexit (&killfind);
-}
-
-
void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini ()
{
int i;
@@ -820,7 +733,7 @@
GNUNET_free (cache[i]);
}
GNUNET_array_grow (cache, cacheSize, 0);
- gcry_set_progress_handler (NULL, NULL);
}
-/* end of kblockkey.c */
+
+/* end of crypto_ksk.c */
Modified: gnunet/src/util/crypto_random.c
===================================================================
--- gnunet/src/util/crypto_random.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/crypto_random.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_crypto_lib.h"
+#include "gnunet_os_lib.h"
#include <gcrypt.h>
/**
@@ -161,12 +162,99 @@
gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
}
+
/**
- * Initializer
+ * Process ID of the "find" process that we use for
+ * entropy gathering.
*/
-void __attribute__ ((constructor)) GNUNET_util_random_init ()
+static pid_t genproc;
+
+/**
+ * Function called by libgcrypt whenever we are
+ * blocked gathering entropy.
+ */
+static void
+entropy_generator (void *cls,
+ const char *what, int printchar, int current, int total)
{
+ unsigned long code;
+ enum GNUNET_OS_ProcessStatusType type;
+ int ret;
+
+ if (0 != strcmp (what, "need_entropy"))
+ return;
+ if (current == total)
+ {
+ if (genproc != 0)
+ {
+ if (0 != PLIBC_KILL (genproc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
+ genproc = 0;
+ }
+ return;
+ }
+ if (genproc != 0)
+ {
+ ret = GNUNET_OS_process_status (genproc, &type, &code);
+ if (ret == GNUNET_NO)
+ return; /* still running */
+ if (ret == GNUNET_SYSERR)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (0 != PLIBC_KILL (genproc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
+ genproc = 0;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Starting `%s' process to generate entropy\n"), "find");
+ genproc = GNUNET_OS_start_process (NULL, NULL, "sh",
+ "sh",
+ "-c",
+ "exec find / -mount -type f -exec cp {}
/dev/null \\; 2>/dev/null",
+ NULL);
+}
+
+
+static void
+killfind ()
+{
+ if (genproc != 0)
+ {
+ PLIBC_KILL (genproc, SIGKILL);
+ genproc = 0;
+ }
+}
+
+
+void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
+{
SRANDOM (time (NULL));
+ gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+ if (!gcry_check_version (GCRYPT_VERSION))
+ {
+ fprintf (stderr,
+ _
+ ("libgcrypt has not the expected version (version %s is
required).\n"),
+ GCRYPT_VERSION);
+ abort ();
+ }
+#ifdef gcry_fast_random_poll
+ gcry_fast_random_poll ();
+#endif
+ gcry_set_progress_handler (&entropy_generator, NULL);
+ atexit (&killfind);
}
+
+void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini ()
+{
+ gcry_set_progress_handler (NULL, NULL);
+}
+
+
+
/* end of crypto_random.c */
Modified: gnunet/src/util/os_load.c
===================================================================
--- gnunet/src/util/os_load.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/os_load.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -156,9 +156,10 @@
unsigned long long usage_time = 0, total_time = 1;
/* Get the first line with the data */
+ memset (line, 0, sizeof (line));
rewind (proc_stat);
fflush (proc_stat);
- if (NULL == fgets (line, 256, proc_stat))
+ if (NULL == fgets (line, sizeof (line), proc_stat))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR |
GNUNET_ERROR_TYPE_BULK,
Modified: gnunet/src/util/plugin.c
===================================================================
--- gnunet/src/util/plugin.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/plugin.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -53,6 +53,12 @@
/**
+ * Have we been initialized?
+ */
+static int initialized;
+
+
+/**
* Libtool search path before we started.
*/
static char *old_dlsearchpath;
@@ -67,17 +73,14 @@
/**
* Setup libtool paths.
*/
-void __attribute__ ((constructor)) GNUNET_PLUGIN_init ()
+static void
+plugin_init ()
{
int err;
const char *opath;
char *path;
char *cpath;
-#ifdef MINGW
- InitWinEnv (NULL);
-#endif
-
err = lt_dlinit ();
if (err > 0)
{
@@ -114,7 +117,8 @@
/**
* Shutdown libtool.
*/
-void __attribute__ ((destructor)) GNUNET_PLUGIN_fini ()
+static void
+plugin_fini ()
{
lt_dlsetsearchpath (old_dlsearchpath);
if (old_dlsearchpath != NULL)
@@ -122,11 +126,6 @@
GNUNET_free (old_dlsearchpath);
old_dlsearchpath = NULL;
}
-
-#ifdef MINGW
- ShutdownWinEnv ();
-#endif
-
lt_dlexit ();
}
@@ -173,6 +172,11 @@
GNUNET_PLUGIN_Callback init;
void *ret;
+ if (! initialized)
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
{
@@ -235,6 +239,11 @@
lt_dlclose (pos->handle);
GNUNET_free (pos->name);
GNUNET_free (pos);
+ if (plugins == NULL)
+ {
+ plugin_fini();
+ initialized = GNUNET_NO;
+ }
return ret;
}
Modified: gnunet/src/util/program.c
===================================================================
--- gnunet/src/util/program.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/program.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -35,15 +35,6 @@
#include "gnunet_scheduler_lib.h"
#include <gcrypt.h>
-#if HAVE_ARGZ_H
-#include <argz.h>
-#else
-#include "program_lib_strnlen.c"
-#include "program_lib_strndup.c"
-#include "program_lib_mempcpy.c"
-#include "program_lib_argz.c"
-#endif
-
/**
* Context for the command.
*/
@@ -156,19 +147,27 @@
gargs = getenv ("GNUNET_ARGS");
if (gargs != NULL)
{
- char *gargz;
- size_t gargl;
char **gargv;
+ unsigned int gargc;
int i;
-
- argz_create_sep (gargs, ' ', &gargz, &gargl);
+ char *tok;
+ char *cargs;
+
+ gargv = NULL;
+ gargc = 0;
for (i=0;i<argc;i++)
- argz_insert (&gargz, &gargl, gargz, argv[i]);
- gargv = GNUNET_malloc (sizeof (char*) * (gargl+1));
- argz_extract (gargz, gargl, gargv);
- argc = argz_count (gargz, gargl);
- free (gargz);
+ GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
+ cargs = GNUNET_strdup (gargs);
+ tok = strtok (cargs, " ");
+ while (NULL != tok)
+ {
+ GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
+ tok = strtok (NULL, " ");
+ }
+ GNUNET_free (cargs);
+ GNUNET_array_append (gargv, gargc, NULL);
argv = (char *const *) gargv;
+ argc = gargc - 1;
}
memset (&cc, 0, sizeof (cc));
loglev = NULL;
Deleted: gnunet/src/util/program_lib_argz.c
===================================================================
--- gnunet/src/util/program_lib_argz.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/program_lib_argz.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -1,403 +0,0 @@
-/* Functions for dealing with '\0' separated arg vectors.
- Copyright (C) 1995-1998, 2000-2002, 2006, 2008 Free Software Foundation,
Inc.
- This file is part of the GNU C Library.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-
-/* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */
-error_t
-argz_append (char **argz, size_t *argz_len, const char *buf, size_t buf_len)
-{
- size_t new_argz_len = *argz_len + buf_len;
- char *new_argz = realloc (*argz, new_argz_len);
- if (new_argz)
- {
- memcpy (new_argz + *argz_len, buf, buf_len);
- *argz = new_argz;
- *argz_len = new_argz_len;
- return 0;
- }
- else
- return ENOMEM;
-}
-
-/* Add STR to the argz vector in ARGZ & ARGZ_LEN. This should be moved into
- argz.c in libshouldbelibc. */
-error_t
-argz_add (char **argz, size_t *argz_len, const char *str)
-{
- return argz_append (argz, argz_len, str, strlen (str) + 1);
-}
-
-
-
-error_t
-argz_add_sep (char **argz, size_t *argz_len, const char *string, int delim)
-{
- size_t nlen = strlen (string) + 1;
-
- if (nlen > 1)
- {
- const char *rp;
- char *wp;
-
- *argz = (char *) realloc (*argz, *argz_len + nlen);
- if (*argz == NULL)
- return ENOMEM;
-
- wp = *argz + *argz_len;
- rp = string;
- do
- if (*rp == delim)
- {
- if (wp > *argz && wp[-1] != '\0')
- *wp++ = '\0';
- else
- --nlen;
- }
- else
- *wp++ = *rp;
- while (*rp++ != '\0');
-
- *argz_len += nlen;
- }
-
- return 0;
-}
-
-
-
-error_t
-argz_create_sep (const char *string, int delim, char **argz, size_t *len)
-{
- size_t nlen = strlen (string) + 1;
-
- if (nlen > 1)
- {
- const char *rp;
- char *wp;
-
- *argz = (char *) malloc (nlen);
- if (*argz == NULL)
- return ENOMEM;
-
- rp = string;
- wp = *argz;
- do
- if (*rp == delim)
- {
- if (wp > *argz && wp[-1] != '\0')
- *wp++ = '\0';
- else
- --nlen;
- }
- else
- *wp++ = *rp;
- while (*rp++ != '\0');
-
- if (nlen == 0)
- {
- free (*argz);
- *argz = NULL;
- *len = 0;
- }
-
- *len = nlen;
- }
- else
- {
- *argz = NULL;
- *len = 0;
- }
-
- return 0;
-}
-
-
-/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an
- existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end.
- Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN,
- ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not
- in ARGZ, EINVAL is returned, else if memory can't be allocated for the new
- ARGZ, ENOMEM is returned, else 0. */
-error_t
-argz_insert (char **argz, size_t *argz_len, char *before, const char *entry)
-{
- if (! before)
- return argz_add (argz, argz_len, entry);
-
- if (before < *argz || before >= *argz + *argz_len)
- return EINVAL;
-
- if (before > *argz)
- /* Make sure before is actually the beginning of an entry. */
- while (before[-1])
- before--;
-
- {
- size_t after_before = *argz_len - (before - *argz);
- size_t entry_len = strlen (entry) + 1;
- size_t new_argz_len = *argz_len + entry_len;
- char *new_argz = realloc (*argz, new_argz_len);
-
- if (new_argz)
- {
- before = new_argz + (before - *argz);
- memmove (before + entry_len, before, after_before);
- memmove (before, entry, entry_len);
- *argz = new_argz;
- *argz_len = new_argz_len;
- return 0;
- }
- else
- return ENOMEM;
- }
-}
-
-
-char *
-argz_next (const char *argz, size_t argz_len, const char *entry)
-{
- if (entry)
- {
- if (entry < argz + argz_len)
- entry = strchr (entry, '\0') + 1;
-
- return entry >= argz + argz_len ? NULL : (char *) entry;
- }
- else
- if (argz_len > 0)
- return (char *) argz;
- else
- return NULL;
-}
-
-
-/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
- except the last into the character SEP. */
-void
-argz_stringify (char *argz, size_t len, int sep)
-{
- if (len > 0)
- while (1)
- {
- size_t part_len = strnlen (argz, len);
- argz += part_len;
- len -= part_len;
- if (len-- <= 1) /* includes final '\0' we want to stop at */
- break;
- *argz++ = sep;
- }
-}
-
-
-/* Returns the number of strings in ARGZ. */
-size_t
-argz_count (const char *argz, size_t len)
-{
- size_t count = 0;
- while (len > 0)
- {
- size_t part_len = strlen(argz);
- argz += part_len + 1;
- len -= part_len + 1;
- count++;
- }
- return count;
-}
-
-
-/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into
- ARGV, which must be large enough to hold them all. */
-void
-argz_extract (const char *argz, size_t len, char **argv)
-{
- while (len > 0)
- {
- size_t part_len = strlen (argz);
- *argv++ = (char *) argz;
- argz += part_len + 1;
- len -= part_len + 1;
- }
- *argv = 0;
-}
-
-
-/* Make a '\0' separated arg vector from a unix argv vector, returning it in
- ARGZ, and the total length in LEN. If a memory allocation error occurs,
- ENOMEM is returned, otherwise 0. */
-error_t
-argz_create (char *const argv[], char **argz, size_t *len)
-{
- int argc;
- size_t tlen = 0;
- char *const *ap;
- char *p;
-
- for (argc = 0; argv[argc] != NULL; ++argc)
- tlen += strlen (argv[argc]) + 1;
-
- if (tlen == 0)
- *argz = NULL;
- else
- {
- *argz = malloc (tlen);
- if (*argz == NULL)
- return ENOMEM;
-
- for (p = *argz, ap = argv; *ap; ++ap, ++p)
- p = stpcpy (p, *ap);
- }
- *len = tlen;
-
- return 0;
-}
-
-
-/* Delete ENTRY from ARGZ & ARGZ_LEN, if any. */
-void
-argz_delete (char **argz, size_t *argz_len, char *entry)
-{
- if (entry)
- /* Get rid of the old value for NAME. */
- {
- size_t entry_len = strlen (entry) + 1;
- *argz_len -= entry_len;
- memmove (entry, entry + entry_len, *argz_len - (entry - *argz));
- if (*argz_len == 0)
- {
- free (*argz);
- *argz = 0;
- }
- }
-}
-
-
-/* Append BUF, of length BUF_LEN to *TO, of length *TO_LEN, reallocating and
- updating *TO & *TO_LEN appropriately. If an allocation error occurs,
- *TO's old value is freed, and *TO is set to 0. */
-static void
-str_append (char **to, size_t *to_len, const char *buf, const size_t buf_len)
-{
- size_t new_len = *to_len + buf_len;
- char *new_to = realloc (*to, new_len + 1);
-
- if (new_to)
- {
- *((char *) mempcpy (new_to + *to_len, buf, buf_len)) = '\0';
- *to = new_to;
- *to_len = new_len;
- }
- else
- {
- free (*to);
- *to = 0;
- }
-}
-
-/* Replace any occurrences of the string STR in ARGZ with WITH, reallocating
- ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be
- incremented by number of replacements performed. */
-error_t
-argz_replace (char **argz, size_t *argz_len, const char *str, const char *with,
- unsigned *replace_count)
-{
- error_t err = 0;
-
- if (str && *str)
- {
- char *arg = 0;
- char *src = *argz;
- size_t src_len = *argz_len;
- char *dst = 0;
- size_t dst_len = 0;
- int delayed_copy = 1; /* True while we've avoided copying anything.
*/
- size_t str_len = strlen (str), with_len = strlen (with);
-
- while (!err && (arg = argz_next (src, src_len, arg)))
- {
- char *match = strstr (arg, str);
- if (match)
- {
- char *from = match + str_len;
- size_t to_len = match - arg;
- char *to = strndup (arg, to_len);
-
- while (to && from)
- {
- str_append (&to, &to_len, with, with_len);
- if (to)
- {
- match = strstr (from, str);
- if (match)
- {
- str_append (&to, &to_len, from, match - from);
- from = match + str_len;
- }
- else
- {
- str_append (&to, &to_len, from, strlen (from));
- from = 0;
- }
- }
- }
-
- if (to)
- {
- if (delayed_copy)
- /* We avoided copying SRC to DST until we found a match;
- now that we've done so, copy everything from the start
- of SRC. */
- {
- if (arg > src)
- err = argz_append (&dst, &dst_len, src, (arg - src));
- delayed_copy = 0;
- }
- if (! err)
- err = argz_add (&dst, &dst_len, to);
- free (to);
- }
- else
- err = ENOMEM;
-
- if (replace_count)
- (*replace_count)++;
- }
- else if (! delayed_copy)
- err = argz_add (&dst, &dst_len, arg);
- }
-
- if (! err)
- {
- if (! delayed_copy)
- /* We never found any instances of str. */
- {
- free (src);
- *argz = dst;
- *argz_len = dst_len;
- }
- }
- else if (dst_len > 0)
- free (dst);
- }
-
- return err;
-}
Deleted: gnunet/src/util/program_lib_mempcpy.c
===================================================================
--- gnunet/src/util/program_lib_mempcpy.c 2010-06-25 14:24:09 UTC (rev
11951)
+++ gnunet/src/util/program_lib_mempcpy.c 2010-06-25 15:37:07 UTC (rev
11952)
@@ -1,27 +0,0 @@
-/* Copy memory area and return pointer after last written byte.
- Copyright (C) 2003, 2007 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-/* Specification. */
-#include <string.h>
-
-/* Copy N bytes of SRC to DEST, return pointer to bytes after the
- last written byte. */
-void *
-mempcpy (void *dest, const void *src, size_t n)
-{
- return (char *) memcpy (dest, src, n) + n;
-}
Deleted: gnunet/src/util/program_lib_strndup.c
===================================================================
--- gnunet/src/util/program_lib_strndup.c 2010-06-25 14:24:09 UTC (rev
11951)
+++ gnunet/src/util/program_lib_strndup.c 2010-06-25 15:37:07 UTC (rev
11952)
@@ -1,35 +0,0 @@
-/* A replacement function, for systems that lack strndup.
-
- Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
- Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2, 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#include <string.h>
-
-#include <stdlib.h>
-
-char *
-strndup (char const *s, size_t n)
-{
- size_t len = strnlen (s, n);
- char *new = malloc (len + 1);
-
- if (new == NULL)
- return NULL;
-
- new[len] = '\0';
- return memcpy (new, s, len);
-}
Deleted: gnunet/src/util/program_lib_strnlen.c
===================================================================
--- gnunet/src/util/program_lib_strnlen.c 2010-06-25 14:24:09 UTC (rev
11951)
+++ gnunet/src/util/program_lib_strnlen.c 2010-06-25 15:37:07 UTC (rev
11952)
@@ -1,29 +0,0 @@
-/* Find the length of STRING, but scan at most MAXLEN characters.
- Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
- Written by Simon Josefsson.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#include <string.h>
-
-/* Find the length of STRING, but scan at most MAXLEN characters.
- If no '\0' terminator is found in that many characters, return MAXLEN. */
-
-size_t
-strnlen (const char *string, size_t maxlen)
-{
- const char *end = memchr (string, '\0', maxlen);
- return end ? (size_t) (end - string) : maxlen;
-}
Modified: gnunet/src/util/test_crypto_ksk.c
===================================================================
--- gnunet/src/util/test_crypto_ksk.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/test_crypto_ksk.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -170,7 +170,7 @@
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_rsa_verify
- (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PING, &purp, &sig, &pkey))
+ (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
{
printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
ok = GNUNET_SYSERR;
Modified: gnunet/src/util/test_crypto_rsa.c
===================================================================
--- gnunet/src/util/test_crypto_rsa.c 2010-06-25 14:24:09 UTC (rev 11951)
+++ gnunet/src/util/test_crypto_rsa.c 2010-06-25 15:37:07 UTC (rev 11952)
@@ -228,7 +228,7 @@
}
if (GNUNET_SYSERR !=
GNUNET_CRYPTO_rsa_verify
- (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PING, &purp, &sig, &pkey))
+ (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, &purp, &sig, &pkey))
{
printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
ok = GNUNET_SYSERR;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11952 - gnunet/src/util,
gnunet <=