Subversion Repositories freemyipod

Rev

Rev 160 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
160 theseven 1
/* ucl_str.c -- string functions for the the UCL library
2
 
3
   This file is part of the UCL data compression library.
4
 
5
   Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
6
   All Rights Reserved.
7
 
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.
12
 
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.
17
 
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.
22
 
23
   Markus F.X.J. Oberhumer
24
   <markus@oberhumer.com>
25
   http://www.oberhumer.com/opensource/ucl/
26
 */
27
 
28
 
29
#include "ucl_conf.h"
30
 
31
#undef ucl_memcmp
32
#undef ucl_memcpy
33
#undef ucl_memmove
34
#undef ucl_memset
35
 
36
 
37
/***********************************************************************
38
// slow but portable <string.h> stuff, only used in assertions
39
************************************************************************/
40
 
41
UCL_PUBLIC(int)
42
ucl_memcmp(const ucl_voidp s1, const ucl_voidp s2, ucl_uint len)
43
{
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;
50
 
51
    if (len > 0) do
52
    {
53
        d = *p1 - *p2;
54
        if (d != 0)
55
            return d;
56
        p1++;
57
        p2++;
58
    }
59
    while (--len > 0);
60
    return 0;
61
#endif
62
}
63
 
64
 
65
UCL_PUBLIC(ucl_voidp)
66
ucl_memcpy(ucl_voidp dest, const ucl_voidp src, ucl_uint len)
67
{
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;
73
 
74
    if (len <= 0 || p1 == p2)
75
        return dest;
76
    do
77
        *p1++ = *p2++;
78
    while (--len > 0);
79
    return dest;
80
#endif
81
}
82
 
83
 
84
UCL_PUBLIC(ucl_voidp)
85
ucl_memmove(ucl_voidp dest, const ucl_voidp src, ucl_uint len)
86
{
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;
92
 
93
    if (len <= 0 || p1 == p2)
94
        return dest;
95
 
96
    if (p1 < p2)
97
    {
98
        do
99
            *p1++ = *p2++;
100
        while (--len > 0);
101
    }
102
    else
103
    {
104
        p1 += len;
105
        p2 += len;
106
        do
107
            *--p1 = *--p2;
108
        while (--len > 0);
109
    }
110
    return dest;
111
#endif
112
}
113
 
114
 
115
UCL_PUBLIC(ucl_voidp)
116
ucl_memset(ucl_voidp s, int c, ucl_uint len)
117
{
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;
122
 
123
    if (len > 0) do
124
        *p++ = UCL_BYTE(c);
125
    while (--len > 0);
126
    return s;
127
#endif
128
}
129
 
130
 
131
/*
132
vi:ts=4:et
133
*/