2 * missing.c Replacements for functions that are or can be
3 * missing on some platforms.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Copyright 2000,2006 The FreeRADIUS server project
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/libradius.h>
32 char *crypt(char *key, char *salt)
34 /*log(L_ERR, "crypt() called but not implemented");*/
35 return "____fnord____";
39 #ifndef HAVE_STRNCASECMP
40 int strncasecmp(char *s1, char *s2, int n)
43 unsigned char *p1, *p2;
46 p1 = (unsigned char *)s1;
47 p2 = (unsigned char *)s2;
51 if (*p1 == 0 && *p2 == 0)
56 if (islower(c1)) c1 = toupper(c1);
57 if (islower(c2)) c2 = toupper(c2);
59 if ((dif = c1 - c2) != 0)
69 #ifndef HAVE_STRCASECMP
70 int strcasecmp(char *s1, char *s2)
78 return strncasecmp(s1, s2, l1);
82 #ifndef HAVE_INET_ATON
83 int inet_aton(char *cp, struct in_addr *inp)
87 if (sscanf(cp, "%d.%d.%d.%d", &a1, &a2, &a3, &a4) != 4)
90 inp->s_addr = htonl((a1 << 24) + (a2 << 16) + (a3 << 8) + a4);
97 * Get next token from string *stringp, where tokens are
98 * possibly-empty strings separated by characters from delim.
100 * Writes NULs into the string at *stringp to end tokens.
101 * delim need not remain constant from call to call. On
102 * return, *stringp points past the last NUL written (if there
103 * might be further tokens), or is NULL (if there are
104 * definitely no more tokens).
106 * If *stringp is NULL, strsep returns NULL.
109 strsep(char **stringp, const char *delim)
116 if ((s = *stringp) == NULL)
123 if ((sc = *spanp++) == c) {
134 return NULL; /* NOTREACHED, but the compiler complains */
138 #ifndef HAVE_LOCALTIME_R
140 * We use localtime_r() by default in the server.
142 * For systems which do NOT have localtime_r(), we make the
143 * assumption that localtime() is re-entrant, and returns a
144 * per-thread data structure.
146 * Even if localtime is NOT re-entrant, this function will
147 * lower the possibility of race conditions.
149 struct tm *localtime_r(const time_t *l_clock, struct tm *result)
151 memcpy(result, localtime(l_clock), sizeof(*result));
159 * We use ctime_r() by default in the server.
161 * For systems which do NOT have ctime_r(), we make the
162 * assumption that ctime() is re-entrant, and returns a
163 * per-thread data structure.
165 * Even if ctime is NOT re-entrant, this function will
166 * lower the possibility of race conditions.
168 char *ctime_r(const time_t *l_clock, char *l_buf)
170 strcpy(l_buf, ctime(l_clock));
176 #ifndef HAVE_GMTIME_R
178 * We use gmtime_r() by default in the server.
180 * For systems which do NOT have gmtime_r(), we make the
181 * assumption that gmtime() is re-entrant, and returns a
182 * per-thread data structure.
184 * Even if gmtime is NOT re-entrant, this function will
185 * lower the possibility of race conditions.
187 struct tm *gmtime_r(const time_t *l_clock, struct tm *result)
189 memcpy(result, gmtime(l_clock), sizeof(*result));