Cleaner solution to plugin-included core files.
[kugel-rb.git] / tools / ucl / src / ucl_str.c
blob5866fb63770b963ee96892dacaddab4372a42572
1 /* ucl_str.c -- string functions for the the UCL library
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/ucl/
29 #include "ucl_conf.h"
31 #undef ucl_memcmp
32 #undef ucl_memcpy
33 #undef ucl_memmove
34 #undef ucl_memset
37 /***********************************************************************
38 // slow but portable <string.h> stuff, only used in assertions
39 ************************************************************************/
41 UCL_PUBLIC(int)
42 ucl_memcmp(const ucl_voidp s1, const ucl_voidp s2, ucl_uint len)
44 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCMP)
45 return memcmp(s1,s2,len);
46 #else
47 const ucl_byte *p1 = (const ucl_byte *) s1;
48 const ucl_byte *p2 = (const ucl_byte *) s2;
49 int d;
51 if (len > 0) do
53 d = *p1 - *p2;
54 if (d != 0)
55 return d;
56 p1++;
57 p2++;
59 while (--len > 0);
60 return 0;
61 #endif
65 UCL_PUBLIC(ucl_voidp)
66 ucl_memcpy(ucl_voidp dest, const ucl_voidp src, ucl_uint len)
68 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMCPY)
69 return memcpy(dest,src,len);
70 #else
71 ucl_byte *p1 = (ucl_byte *) dest;
72 const ucl_byte *p2 = (const ucl_byte *) src;
74 if (len <= 0 || p1 == p2)
75 return dest;
77 *p1++ = *p2++;
78 while (--len > 0);
79 return dest;
80 #endif
84 UCL_PUBLIC(ucl_voidp)
85 ucl_memmove(ucl_voidp dest, const ucl_voidp src, ucl_uint len)
87 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMMOVE)
88 return memmove(dest,src,len);
89 #else
90 ucl_byte *p1 = (ucl_byte *) dest;
91 const ucl_byte *p2 = (const ucl_byte *) src;
93 if (len <= 0 || p1 == p2)
94 return dest;
96 if (p1 < p2)
99 *p1++ = *p2++;
100 while (--len > 0);
102 else
104 p1 += len;
105 p2 += len;
107 *--p1 = *--p2;
108 while (--len > 0);
110 return dest;
111 #endif
115 UCL_PUBLIC(ucl_voidp)
116 ucl_memset(ucl_voidp s, int c, ucl_uint len)
118 #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
119 return memset(s,c,len);
120 #else
121 ucl_byte *p = (ucl_byte *) s;
123 if (len > 0) do
124 *p++ = UCL_BYTE(c);
125 while (--len > 0);
126 return s;
127 #endif
132 vi:ts=4:et