blob: 28f13123c00ccae33c0507e982e6ce7c4fa7328a [file] [log] [blame]
Benny Prijonof260e462007-04-30 21:03:32 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <pj/types.h>
20#include <pj/compat/string.h>
21#include <pj/ctype.h>
22
23#if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H != 0
24/* Nothing to do */
25#else
26PJ_DEF(int) strcasecmp(const char *s1, const char *s2)
27{
28 while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
29 if (!*s1++)
30 return 0;
31 ++s2;
32 }
33 return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
34}
35
36PJ_DEF(int) strncasecmp(const char *s1, const char *s2, int len)
37{
38 if (!len) return 0;
39
40 while ((*s1==*s2) || (pj_tolower(*s1)==pj_tolower(*s2))) {
41 if (!*s1++ || --len <= 0)
42 return 0;
43 ++s2;
44 }
45 return (pj_tolower(*s1) < pj_tolower(*s2)) ? -1 : 1;
46}
47#endif
48
49#if defined(PJ_HAS_NO_SNPRINTF) && PJ_HAS_NO_SNPRINTF != 0
50
51PJ_DEF(int) snprintf(char *s1, pj_size_t len, const char *s2, ...)
52{
53 int ret;
54 va_list arg;
55
56 PJ_UNUSED_ARG(len);
57
58 va_start(arg, s2);
59 ret = vsprintf(s1, s2, arg);
60 va_end(arg);
61
62 return ret;
63}
64
65PJ_DEF(int) vsnprintf(char *s1, pj_size_t len, const char *s2, va_list arg)
66{
67 PJ_UNUSED_ARG(len);
68 return vsprintf(s1,s2,arg);
69}
70
71#endif
72