summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>1997-08-20 04:18:52 +0000
committermillert <>1997-08-20 04:18:52 +0000
commit4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d (patch)
tree491119cbafe91e0b3d6f6b0d329dfe76a07e68e0
parenteefd83616fed7208460c4c742ea85c68488acf7c (diff)
downloadopenbsd-4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d.tar.gz
openbsd-4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d.tar.bz2
openbsd-4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d.zip
Update man page and sccs tags from lite2. Minor cleanup by me as well.
-rw-r--r--src/lib/libc/string/strdup.323
-rw-r--r--src/lib/libc/string/strdup.c25
2 files changed, 30 insertions, 18 deletions
diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3
index 4129fe5c0e..04ec042d00 100644
--- a/src/lib/libc/string/strdup.3
+++ b/src/lib/libc/string/strdup.3
@@ -1,5 +1,7 @@
1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 1.\" $OpenBSD: strdup.3,v 1.4 1997/08/20 04:18:51 millert Exp $
2.\" All rights reserved. 2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
3.\" 5.\"
4.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
@@ -29,9 +31,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
31.\" 33.\"
32.\" $OpenBSD: strdup.3,v 1.3 1996/10/29 23:41:57 michaels Exp $ 34.\" @(#)strdup.3 8.1 (Berkeley) 6/9/93
33.\" 35.\"
34.Dd April 19, 1991 36.Dd June 9, 1993
35.Dt STRDUP 3 37.Dt STRDUP 3
36.Os 38.Os
37.Sh NAME 39.Sh NAME
@@ -52,13 +54,14 @@ does the copy, and returns a pointer to it.
52The pointer may subsequently be used as an 54The pointer may subsequently be used as an
53argument to the function 55argument to the function
54.Xr free 3 . 56.Xr free 3 .
57.Pp
58If insufficient memory is available, NULL is returned.
55.Sh SEE ALSO 59.Sh SEE ALSO
56.Xr free 3 , 60.Xr free 3
57.Xr malloc 3 , 61.Xr malloc 3
58.Xt strcpy 3 , 62.Xr strcpy 3
59.Xt strlen 3 63.Xr strlen 3
60.Sh HISTORY 64.Sh HISTORY
61The 65The
62.Fn strdup 66.Fn strdup
63function is 67function first appeared in 4.4BSD.
64.Ud .
diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c
index 74c462d241..be7f7ad094 100644
--- a/src/lib/libc/string/strdup.c
+++ b/src/lib/libc/string/strdup.c
@@ -1,6 +1,8 @@
1/* $OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $ */
2
1/* 3/*
2 * Copyright (c) 1988 The Regents of the University of California. 4 * Copyright (c) 1988, 1993
3 * All rights reserved. 5 * The Regents of the University of California. All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
@@ -32,9 +34,16 @@
32 */ 34 */
33 35
34#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strdup.c,v 1.2 1996/08/19 08:34:16 tholo Exp $"; 37#if 0
38static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
39#else
40static char *rcsid = "$OpenBSD: strdup.c,v 1.3 1997/08/20 04:18:52 millert Exp $";
41#endif
36#endif /* LIBC_SCCS and not lint */ 42#endif /* LIBC_SCCS and not lint */
37 43
44#include <sys/types.h>
45
46#include <stddef.h>
38#include <stdlib.h> 47#include <stdlib.h>
39#include <string.h> 48#include <string.h>
40 49
@@ -42,12 +51,12 @@ char *
42strdup(str) 51strdup(str)
43 const char *str; 52 const char *str;
44{ 53{
45 size_t len; 54 size_t siz;
46 char *copy; 55 char *copy;
47 56
48 len = strlen(str) + 1; 57 siz = strlen(str) + 1;
49 if (!(copy = malloc(len))) 58 if ((copy = malloc(siz)) == NULL)
50 return((char *)NULL); 59 return(NULL);
51 memcpy(copy, str, len); 60 (void)memcpy(copy, str, siz);
52 return(copy); 61 return(copy);
53} 62}