|
@ -1,6 +1,8 @@ |
|
|
|
|
|
/* $OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $ */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Copyright (c) 1988 The Regents of the University of California. |
|
|
|
|
|
* All rights reserved. |
|
|
|
|
|
|
|
|
* Copyright (c) 1988, 1993 |
|
|
|
|
|
* The Regents of the University of California. All rights reserved. |
|
|
* |
|
|
* |
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
* modification, are permitted provided that the following conditions |
|
|
* modification, are permitted provided that the following conditions |
|
@ -32,9 +34,16 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
static char *rcsid = "$OpenBSD: strdup.c,v 1.2 1996/08/19 08:34:16 tholo Exp $"; |
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; |
|
|
|
|
|
#else |
|
|
|
|
|
static char *rcsid = "$OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $"; |
|
|
|
|
|
#endif |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
|
|
|
|
|
@ -42,12 +51,12 @@ char * |
|
|
strdup(str) |
|
|
strdup(str) |
|
|
const char *str; |
|
|
const char *str; |
|
|
{ |
|
|
{ |
|
|
size_t len; |
|
|
|
|
|
|
|
|
size_t siz; |
|
|
char *copy; |
|
|
char *copy; |
|
|
|
|
|
|
|
|
len = strlen(str) + 1; |
|
|
|
|
|
if (!(copy = malloc(len))) |
|
|
|
|
|
return((char *)NULL); |
|
|
|
|
|
memcpy(copy, str, len); |
|
|
|
|
|
|
|
|
siz = strlen(str) + 1; |
|
|
|
|
|
if ((copy = malloc(siz)) == NULL) |
|
|
|
|
|
return(NULL); |
|
|
|
|
|
(void)memcpy(copy, str, siz); |
|
|
return(copy); |
|
|
return(copy); |
|
|
} |
|
|
} |