diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-20 04:18:53 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-20 04:18:53 +0000 |
commit | a580a8f59a7c9e806c451338ab4682371970c185 (patch) | |
tree | 5fd5b2ab1de6c7a6732e9a5e2047e2a7ac26b663 /lib | |
parent | be27a1dd3f0c4be2fd717bc03c5f2756e4bfabde (diff) |
Update man page and sccs tags from lite2. Minor cleanup by me as well.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/string/strdup.3 | 23 | ||||
-rw-r--r-- | lib/libc/string/strdup.c | 25 |
2 files changed, 30 insertions, 18 deletions
diff --git a/lib/libc/string/strdup.3 b/lib/libc/string/strdup.3 index 4129fe5c0e6..04ec042d00c 100644 --- a/lib/libc/string/strdup.3 +++ b/lib/libc/string/strdup.3 @@ -1,5 +1,7 @@ -.\" Copyright (c) 1990, 1991 The Regents of the University of California. -.\" All rights reserved. +.\" $OpenBSD: strdup.3,v 1.4 1997/08/20 04:18:51 millert Exp $ +.\" +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -29,9 +31,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strdup.3,v 1.3 1996/10/29 23:41:57 michaels Exp $ +.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93 .\" -.Dd April 19, 1991 +.Dd June 9, 1993 .Dt STRDUP 3 .Os .Sh NAME @@ -52,13 +54,14 @@ does the copy, and returns a pointer to it. The pointer may subsequently be used as an argument to the function .Xr free 3 . +.Pp +If insufficient memory is available, NULL is returned. .Sh SEE ALSO -.Xr free 3 , -.Xr malloc 3 , -.Xt strcpy 3 , -.Xt strlen 3 +.Xr free 3 +.Xr malloc 3 +.Xr strcpy 3 +.Xr strlen 3 .Sh HISTORY The .Fn strdup -function is -.Ud . +function first appeared in 4.4BSD. diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c index 74c462d2411..be7f7ad0946 100644 --- a/lib/libc/string/strdup.c +++ b/lib/libc/string/strdup.c @@ -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 * modification, are permitted provided that the following conditions @@ -32,9 +34,16 @@ */ #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 */ +#include <sys/types.h> + +#include <stddef.h> #include <stdlib.h> #include <string.h> @@ -42,12 +51,12 @@ char * strdup(str) const char *str; { - size_t len; + size_t siz; 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); } |