diff options
author | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:54:07 +0900 |
---|---|---|
committer | Sehong Na <sehong.na@samsung.com> | 2014-05-31 12:54:07 +0900 |
commit | 125ba4f9bd2352465139044bca2ecde421f2c0f2 (patch) | |
tree | 56fb917ad7c5607cbc05b418ca95a3b2242116a4 /lib | |
download | nasm-125ba4f9bd2352465139044bca2ecde421f2c0f2.tar.gz nasm-125ba4f9bd2352465139044bca2ecde421f2c0f2.tar.bz2 nasm-125ba4f9bd2352465139044bca2ecde421f2c0f2.zip |
Initialize Tizen 2.3submit/tizen_2.3/20140531.1014372.3a_release
Diffstat (limited to 'lib')
-rw-r--r-- | lib/snprintf.c | 25 | ||||
-rw-r--r-- | lib/strlcpy.c | 53 | ||||
-rw-r--r-- | lib/vsnprintf.c | 49 |
3 files changed, 127 insertions, 0 deletions
diff --git a/lib/snprintf.c b/lib/snprintf.c new file mode 100644 index 0000000..01734dc --- /dev/null +++ b/lib/snprintf.c @@ -0,0 +1,25 @@ +/* + * snprintf() + * + * Implement snprintf() in terms of vsnprintf() + */ + +#include "compiler.h" + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "nasmlib.h" + +int snprintf(char *str, size_t size, const char *format, ...) +{ + va_list ap; + int rv; + + va_start(ap, format); + rv = vsnprintf(str, size, format, ap); + va_end(ap); + + return rv; +} diff --git a/lib/strlcpy.c b/lib/strlcpy.c new file mode 100644 index 0000000..4335359 --- /dev/null +++ b/lib/strlcpy.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <string.h> +#include "compiler.h" + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +#ifndef HAVE_STRLCPY + +size_t strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif diff --git a/lib/vsnprintf.c b/lib/vsnprintf.c new file mode 100644 index 0000000..f5ae2fe --- /dev/null +++ b/lib/vsnprintf.c @@ -0,0 +1,49 @@ +/* + * vsnprintf() + * + * Poor substitute for a real vsnprintf() function for systems + * that don't have them... + */ + +#include "compiler.h" + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> + +#include "nasmlib.h" + +#define BUFFER_SIZE 65536 /* Bigger than any string we might print... */ + +static char snprintf_buffer[BUFFER_SIZE]; + +int vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int rv, bytes; + + if (size > BUFFER_SIZE) { + nasm_malloc_error(ERR_PANIC|ERR_NOFILE, + "snprintf: size (%d) > BUFFER_SIZE (%d)", + size, BUFFER_SIZE); + size = BUFFER_SIZE; + } + + rv = vsprintf(snprintf_buffer, format, ap); + if (rv >= BUFFER_SIZE) { + nasm_malloc_error(ERR_PANIC|ERR_NOFILE, + "snprintf buffer overflow"); + } + + if (size > 0) { + if ((size_t)rv < size-1) + bytes = rv; + else + bytes = size-1; + + memcpy(str, snprintf_buffer, bytes); + str[bytes] = '\0'; + } + + return rv; +} |