Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / libpam / libpam_misc / xstrdup.c
1 /* $FreeBSD: src/contrib/libpam/libpam_misc/xstrdup.c,v 1.2.6.2 2001/06/11 15:28:15 markm Exp $ */
2 /* $DragonFly: src/contrib/libpam/libpam_misc/Attic/xstrdup.c,v 1.2 2003/06/17 04:24:03 dillon Exp $ */
3 /* $Header: /home/morgan/pam/Linux-PAM-0.53/libpam_misc/RCS/xstrdup.c,v 1.4 1996/11/10 20:10:56 morgan Exp $ */
4
5 /*
6  * $Log: xstrdup.c,v $
7  * Revision 1.4  1996/11/10 20:10:56  morgan
8  * modification for stack paranoia
9  *
10  */
11
12 #include <stdlib.h>
13 #include <security/pam_misc.h>
14
15 /*
16  * Safe duplication of character strings. "Paranoid"; don't leave
17  * evidence of old token around for later stack analysis.
18  */
19
20 char *xstrdup(const char *x)
21 {
22      register char *new=NULL;
23
24      if (x != NULL) {
25           register int i;
26
27           for (i=0; x[i]; ++i);                       /* length of string */
28           if ((new = malloc(++i)) == NULL) {
29                i = 0;
30           } else {
31                while (i-- > 0) {
32                     new[i] = x[i];
33                }
34           }
35           x = NULL;
36      }
37
38      return new;                 /* return the duplicate or NULL on error */
39 }