mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Restructured the compat functions and changed its license.
New fucntion xstrconcat for future use.
This commit is contained in:
parent
f5f0171d55
commit
20fe42d10b
11 changed files with 193 additions and 24 deletions
|
@ -1,3 +1,9 @@
|
|||
2009-08-25 Werner Koch <wk@g10code.com>
|
||||
|
||||
* compat.c: Change license to all-permissive. The GPL and the
|
||||
exception does no make sense here.
|
||||
(do_strconcat, xstrconcat): New.
|
||||
|
||||
2009-08-18 Werner Koch <wk@g10code.com>
|
||||
|
||||
* iobuf.c (fd_cache_close): Change debug printf format assuming
|
||||
|
|
107
util/compat.c
107
util/compat.c
|
@ -1,5 +1,42 @@
|
|||
/* compat.c - Simple compatibility functions
|
||||
* Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* The origin of this code is GnuPG.
|
||||
*
|
||||
* This file is free software; as a special exception the author gives
|
||||
* unlimited permission to copy and/or distribute it, with or without
|
||||
* modifications, as long as this notice is preserved.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* History:
|
||||
* 2006-09-28 dshaw Created. Added function hextobyte from GnuPG.
|
||||
* 2007-04-16 dshaw Added ascii_toupper, ascii_tolower, ascii_strcasecmp,
|
||||
* ascii_strncasecmp from GnuPG.
|
||||
* 2009-08-25 wk License changed by GnuPG maintainer from GPL with
|
||||
* OpenSSL exception to this all permissive license.
|
||||
* 2009-08-25 wk Wrote new function xstrconcat.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* We require an external malloc function named xtrymalloc. */
|
||||
void *xtrymalloc (size_t n);
|
||||
|
||||
|
||||
#ifndef DIM
|
||||
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int
|
||||
hextobyte (const char *s)
|
||||
{
|
||||
|
@ -92,3 +129,73 @@ ascii_strncasecmp (const char *a, const char *b, size_t n)
|
|||
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
do_strconcat (const char *s1, va_list arg_ptr)
|
||||
{
|
||||
const char *argv[48];
|
||||
size_t argc;
|
||||
size_t needed;
|
||||
char *buffer, *p;
|
||||
const char *r;
|
||||
|
||||
argc = 0;
|
||||
argv[argc++] = s1;
|
||||
needed = strlen (s1);
|
||||
while (((argv[argc] = va_arg (arg_ptr, const char *))))
|
||||
{
|
||||
needed += strlen (argv[argc]);
|
||||
if (argc >= DIM (argv)-1)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
argc++;
|
||||
}
|
||||
needed++;
|
||||
buffer = xtrymalloc (needed);
|
||||
if (buffer)
|
||||
{
|
||||
for (p = buffer, argc=0; argv[argc]; argc++)
|
||||
{
|
||||
for (r = argv[argc]; *r; )
|
||||
*p++ = *r++;
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/* Concatenate the string S1 with all the following strings up to a
|
||||
NULL. Returns a malloced buffer. */
|
||||
char *
|
||||
xstrconcat (const char *s1, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
char *result;
|
||||
|
||||
if (!s1)
|
||||
{
|
||||
result = xtrymalloc (1);
|
||||
if (result)
|
||||
*result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
va_start (arg_ptr, s1);
|
||||
result = do_strconcat (s1, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
}
|
||||
if (!result)
|
||||
{
|
||||
if (errno == EINVAL)
|
||||
fputs ("\nfatal: too many args for xstrconcat\n", stderr);
|
||||
else
|
||||
fputs ("\nfatal: out of memory\n", stderr);
|
||||
exit (2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue