1.1 --- a/sourcepawn/compiler/lstring.c Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,124 +0,0 @@
1.4 -/* Safe string copying and concatenation
1.5 - * These routines are originally distributed in two separate files. I have
1.6 - * copied the files verbatim in this single source file, including all comments.
1.7 - * The only change is that the second set of include files is commented out
1.8 - * (there is no need to include the same files twice).
1.9 - */
1.10 -
1.11 -#include "lstring.h"
1.12 -
1.13 -#if !defined HAVE_SAFESTR
1.14 -
1.15 -/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
1.16 -
1.17 -/*
1.18 - * Copyright (c) 1998 Todd C. Miller <[email protected]>
1.19 - *
1.20 - * Permission to use, copy, modify, and distribute this software for any
1.21 - * purpose with or without fee is hereby granted, provided that the above
1.22 - * copyright notice and this permission notice appear in all copies.
1.23 - *
1.24 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1.25 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.26 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1.27 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1.28 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1.29 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1.30 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.31 - */
1.32 -
1.33 -/*
1.34 - #include <sys/types.h> already included through lstring.h
1.35 - */
1.36 -#include <string.h> /* for strlen() */
1.37 -
1.38 -/*
1.39 - * Copy src to string dst of size siz. At most siz-1 characters
1.40 - * will be copied. Always NUL terminates (unless siz == 0).
1.41 - * Returns strlen(src); if retval >= siz, truncation occurred.
1.42 - */
1.43 -size_t
1.44 -strlcpy(char *dst, const char *src, size_t siz)
1.45 -{
1.46 - char *d = dst;
1.47 - const char *s = src;
1.48 - size_t n = siz;
1.49 -
1.50 - /* Copy as many bytes as will fit */
1.51 - if (n != 0 && --n != 0) {
1.52 - do {
1.53 - if ((*d++ = *s++) == 0)
1.54 - break;
1.55 - } while (--n != 0);
1.56 - }
1.57 -
1.58 - /* Not enough room in dst, add NUL and traverse rest of src */
1.59 - if (n == 0) {
1.60 - if (siz != 0)
1.61 - *d = '\0'; /* NUL-terminate dst */
1.62 - while (*s++)
1.63 - ;
1.64 - }
1.65 -
1.66 - return(s - src - 1); /* count does not include NUL */
1.67 -}
1.68 -
1.69 -/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
1.70 -
1.71 -/*
1.72 - * Copyright (c) 1998 Todd C. Miller <[email protected]>
1.73 - *
1.74 - * Permission to use, copy, modify, and distribute this software for any
1.75 - * purpose with or without fee is hereby granted, provided that the above
1.76 - * copyright notice and this permission notice appear in all copies.
1.77 - *
1.78 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1.79 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.80 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1.81 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1.82 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1.83 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1.84 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.85 - */
1.86 -
1.87 -/*
1.88 - #include <sys/types.h> already included
1.89 - #include <string.h> already included
1.90 -*/
1.91 -
1.92 -/*
1.93 - * Appends src to string dst of size siz (unlike strncat, siz is the
1.94 - * full size of dst, not space left). At most siz-1 characters
1.95 - * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
1.96 - * Returns strlen(src) + MIN(siz, strlen(initial dst)).
1.97 - * If retval >= siz, truncation occurred.
1.98 - */
1.99 -size_t
1.100 -strlcat(char *dst, const char *src, size_t siz)
1.101 -{
1.102 - char *d = dst;
1.103 - const char *s = src;
1.104 - size_t n = siz;
1.105 - size_t dlen;
1.106 -
1.107 - /* Find the end of dst and adjust bytes left but don't go past end */
1.108 - while (n-- != 0 && *d != '\0')
1.109 - d++;
1.110 - dlen = d - dst;
1.111 - n = siz - dlen;
1.112 -
1.113 - if (n == 0)
1.114 - return(dlen + strlen(s));
1.115 - while (*s != '\0') {
1.116 - if (n != 1) {
1.117 - *d++ = *s;
1.118 - n--;
1.119 - }
1.120 - s++;
1.121 - }
1.122 - *d = '\0';
1.123 -
1.124 - return(dlen + (s - src)); /* count does not include NUL */
1.125 -}
1.126 -
1.127 -#endif /* #if !defined HAVE_SAFESTR */