Commit ba335de9 authored by Niels Möller's avatar Niels Möller

* src/argp/strndup.c, src/argp/strchrnul.c src/argp/mempcpy.c:

Moved replacement functions to separate files.

Rev: src/argp/mempcpy.c:1.1
Rev: src/argp/strchrnul.c:1.1
Rev: src/argp/strndup.c:1.1
parent b04e81f6
/* 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;
}
/* 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;
}
/* strndup.c
*
*/
/* Written by Niels Mller <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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment