| /**************************************************************************** |
| | (C) Copyright 2008 Novell, Inc. All Rights Reserved. |
| | |
| | GPLv2: This program is free software; you can redistribute it |
| | and/or modify it under the terms of version 2 of the GNU General |
| | Public License as published by the Free Software Foundation. |
| | |
| | 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. |
| +-------------------------------------------------------------------------*/ |
| |
| #include <stdarg.h> |
| #include <stddef.h> |
| #include <string.h> |
| |
| char *cat (char *dst, ...) |
| { |
| char *s = dst; |
| char *t; |
| va_list args; |
| |
| va_start(args, dst); |
| |
| *s = '\0'; |
| for (;;) { |
| t = va_arg(args, char *); |
| if (!t) break; |
| while ((*s = *t++)) |
| ++s; |
| } |
| va_end(args); |
| return dst; |
| } |
| |
| #if !defined(__HAVE_ARCH_STRLCPY) && !(__APPLE__) |
| /** |
| * strlcpy - Copy a %NUL terminated string into a sized buffer |
| * @dest: Where to copy the string to |
| * @src: Where to copy the string from |
| * @size: size of destination buffer |
| * |
| * Compatible with *BSD: the result is always a valid |
| * NUL-terminated string that fits in the buffer (unless, |
| * of course, the buffer size is zero). It does not pad |
| * out the result like strncpy() does. |
| */ |
| size_t strlcpy(char *dest, const char *src, size_t size) |
| { |
| size_t ret = strlen(src); |
| |
| if (size) { |
| size_t len = (ret >= size) ? size-1 : ret; |
| memcpy(dest, src, len); |
| dest[len] = '\0'; |
| } |
| return ret; |
| } |
| #endif |
| |
| #if !defined(__HAVE_ARCH_STRLCPY) && !(__APPLE__) |
| /** |
| * strlcat - Append a length-limited, %NUL-terminated string to another |
| * @dest: The string to be appended to |
| * @src: The string to append to it |
| * @count: The size of the destination buffer. |
| */ |
| size_t strlcat(char *dest, const char *src, size_t count) |
| { |
| size_t dsize = strlen(dest); |
| size_t len = strlen(src); |
| size_t res = dsize + len; |
| |
| dest += dsize; |
| count -= dsize; |
| if (len >= count) |
| len = count-1; |
| memcpy(dest, src, len); |
| dest[len] = 0; |
| return res; |
| } |
| #endif |
| |
| #if 0 |
| int main () |
| { |
| char buf[400]; |
| |
| printf("%s\n", cat(buf, "This", " is", " a", " string", 0)); |
| return 0; |
| } |
| #endif |