diff options
author | Werner Koch <[email protected]> | 2007-05-15 16:10:48 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-05-15 16:10:48 +0000 |
commit | 5f3bca96826fbaf9c4469a7eedef9294f4d74bfb (patch) | |
tree | dae425970a8c0dd0f77ab62c91b2700dfbaa811e /common/sexp-parse.h | |
parent | Preparing 2.0.4 (diff) | |
download | gnupg-5f3bca96826fbaf9c4469a7eedef9294f4d74bfb.tar.gz gnupg-5f3bca96826fbaf9c4469a7eedef9294f4d74bfb.zip |
Use estream_asprintf instead of the GNU asprintf.
Diffstat (limited to 'common/sexp-parse.h')
-rw-r--r-- | common/sexp-parse.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/common/sexp-parse.h b/common/sexp-parse.h index 1064e51c4..bb96e446f 100644 --- a/common/sexp-parse.h +++ b/common/sexp-parse.h @@ -1,5 +1,5 @@ /* sexp-parse.h - S-Exp helper functions - * Copyright (C) 2002, 2003 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -97,4 +97,34 @@ smatch (unsigned char const **buf, size_t buflen, const char *token) return 1; } +/* Format VALUE for use as the length indicatior of an S-expression. + The caller needs to provide a buffer HELP_BUFFER wth a length of + HELP_BUFLEN. The return value is a pointer into HELP_BUFFER with + the formatted length string. The colon and a trailing nul are + appended. HELP_BUFLEN must be at least 3 - a more useful value is + 15. If LENGTH is not NULL, the LENGTH of the resulting string + (excluding the terminating nul) is stored at that address. */ +static inline char * +smklen (char *help_buffer, size_t help_buflen, size_t value, size_t *length) +{ + char *p = help_buffer + help_buflen; + + if (help_buflen >= 3) + { + *--p = 0; + *--p = ':'; + do + { + *--p = '0' + (value % 10); + value /= 10; + } + while (value && p > help_buffer); + } + + if (length) + *length = (help_buffer + help_buflen) - p; + return p; +} + + #endif /*SEXP_PARSE_H*/ |