mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-07 17:33:02 +01:00
Add new function strconcat.
* include/util.h (GNUPG_GCC_A_SENTINEL): New. * util/strgutil.c (do_strconcat, strconcat): New. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
2e7a3ed390
commit
484d073058
@ -28,6 +28,14 @@
|
||||
#include "mpi.h"
|
||||
#include "compat.h"
|
||||
|
||||
/* GCC attributes. */
|
||||
#if __GNUC__ >= 4
|
||||
# define GNUPG_GCC_A_SENTINEL(a) __attribute__ ((sentinel(a)))
|
||||
#else
|
||||
# define GNUPG_GCC_A_SENTINEL(a)
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int *argc; /* pointer to argc (value subject to change) */
|
||||
char ***argv; /* pointer to argv (value subject to change) */
|
||||
@ -177,6 +185,8 @@ unsigned int check_trailing_chars( const byte *line, unsigned int len,
|
||||
const char *trimchars );
|
||||
unsigned int check_trailing_ws( const byte *line, unsigned int len );
|
||||
int string_count_chr( const char *string, int c );
|
||||
int has_invalid_email_chars (const char *s);
|
||||
int is_valid_mailbox (const char *name);
|
||||
int set_native_charset( const char *newset );
|
||||
const char* get_native_charset(void);
|
||||
char *native_to_utf8( const char *string );
|
||||
@ -238,7 +248,7 @@ int write_w32_registry_string(const char *root, const char *dir,
|
||||
char *xasprintf (const char *fmt, ...);
|
||||
char *xtryasprintf (const char *fmt, ...);
|
||||
char *xtryvasprintf (const char *fmt, va_list arg_ptr);
|
||||
|
||||
char *strconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
|
||||
|
||||
/*-- pka.c --*/
|
||||
char *get_pka_info (const char *address, unsigned char *fpr);
|
||||
|
@ -1166,6 +1166,59 @@ xtryvasprintf (const char *fmt, va_list arg_ptr)
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
do_strconcat (const char *s1, va_list arg_ptr)
|
||||
{
|
||||
const char *argv[48];
|
||||
size_t argc;
|
||||
size_t needed;
|
||||
char *buffer, *p;
|
||||
|
||||
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++)
|
||||
p = stpcpy (p, argv[argc]);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/* Concatenate the string S1 with all the following strings up to a
|
||||
NULL. Returns a malloced buffer with the new string or NULL on a
|
||||
malloc error or if too many arguments are given. */
|
||||
char *
|
||||
strconcat (const char *s1, ...)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
char *result;
|
||||
|
||||
if (!s1)
|
||||
result = xtrystrdup ("");
|
||||
else
|
||||
{
|
||||
va_start (arg_ptr, s1);
|
||||
result = do_strconcat (s1, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************
|
||||
******** locale insensitive ctype functions ********
|
||||
****************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user