diff --git a/src/argp/mempcpy.c b/src/argp/mempcpy.c new file mode 100644 index 0000000000000000000000000000000000000000..6fa228b2c9f8443a36a0d6c5b3a891e3ec9c4d93 --- /dev/null +++ b/src/argp/mempcpy.c @@ -0,0 +1,18 @@ +/* strndup.c + * + */ + +/* Written by Niels M�ller <nisse@lysator.liu.se> + * + * This file is hereby placed in the public domain. + */ + +#include <string.h> + +void * +mempcpy (void *to, const void *from, size_t size) +{ + memcpy(to, from, size); + return (char *) to + size; +} + diff --git a/src/argp/strchrnul.c b/src/argp/strchrnul.c new file mode 100644 index 0000000000000000000000000000000000000000..af1b4bbb9165e3c1ae187b3cf50588816921861f --- /dev/null +++ b/src/argp/strchrnul.c @@ -0,0 +1,21 @@ +/* strchrnul.c + * + */ + +/* Written by Niels M�ller <nisse@lysator.liu.se> + * + * This file is hereby placed in the public domain. + */ + +/* FIXME: What is this function supposed to do? My guess is that it is + * like strchr, but returns a pointer to the NUL character, not a NULL + * pointer, if the character isn't found. */ + +char *strchrnul(const char *s, int c) +{ + const char *p = s; + while (*p && (*p != c)) + p++; + + return (char *) p; +} diff --git a/src/argp/strndup.c b/src/argp/strndup.c new file mode 100644 index 0000000000000000000000000000000000000000..f01065a533b21051c940755f020633ff2a573c0c --- /dev/null +++ b/src/argp/strndup.c @@ -0,0 +1,31 @@ +/* strndup.c + * + */ + +/* Written by Niels M�ller <nisse@lysator.liu.se> + * + * This file is hereby placed in the public domain. + */ + +#include <stdlib.h> +#include <string.h> + +char * +strndup (const char *s, size_t size) +{ + char *r; + char *end = memchr(s, 0, size); + + if (end) + /* Length + 1 */ + size = end - s + 1; + + r = malloc(size); + + if (size) + { + memcpy(r, s, size-1); + r[size-1] = '\0'; + } + return r; +}