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/autoconf.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include <freeradius-devel/missing.h>
38 #include <freeradius-devel/libradius.h>
41 char *crypt(char *key, char *salt)
43 /*log(L_ERR, "crypt() called but not implemented");*/
44 return "____fnord____";
48 #ifndef HAVE_STRNCASECMP
49 int strncasecmp(char *s1, char *s2, int n)
52 unsigned char *p1, *p2;
55 p1 = (unsigned char *)s1;
56 p2 = (unsigned char *)s2;
60 if (*p1 == 0 && *p2 == 0)
65 if (islower(c1)) c1 = toupper(c1);
66 if (islower(c2)) c2 = toupper(c2);
68 if ((dif = c1 - c2) != 0)
78 #ifndef HAVE_STRCASECMP
79 int strcasecmp(char *s1, char *s2)
87 return strncasecmp(s1, s2, l1);
91 #ifndef HAVE_INET_ATON
92 int inet_aton(char *cp, struct in_addr *inp)
96 if (sscanf(cp, "%d.%d.%d.%d", &a1, &a2, &a3, &a4) != 4)
99 inp->s_addr = htonl((a1 << 24) + (a2 << 16) + (a3 << 8) + a4);
104 #ifndef HAVE_GETHOSTNAME
105 int gethostname(char *name, int len)
109 h = getenv("HOSTNAME");
110 if (!h || (strlen(h) + 1 > len))
119 * Get next token from string *stringp, where tokens are
120 * possibly-empty strings separated by characters from delim.
122 * Writes NULs into the string at *stringp to end tokens.
123 * delim need not remain constant from call to call. On
124 * return, *stringp points past the last NUL written (if there
125 * might be further tokens), or is NULL (if there are
126 * definitely no more tokens).
128 * If *stringp is NULL, strsep returns NULL.
131 strsep(char **stringp, const char *delim)
138 if ((s = *stringp) == NULL)
145 if ((sc = *spanp++) == c) {
156 return NULL; /* NOTREACHED, but the compiler complains */
160 #ifndef HAVE_LOCALTIME_R
162 * We use localtime_r() by default in the server.
164 * For systems which do NOT have localtime_r(), we make the
165 * assumption that localtime() is re-entrant, and returns a
166 * per-thread data structure.
168 * Even if localtime is NOT re-entrant, this function will
169 * lower the possibility of race conditions.
171 struct tm *localtime_r(const time_t *l_clock, struct tm *result)
173 memcpy(result, localtime(l_clock), sizeof(*result));
181 * We use ctime_r() by default in the server.
183 * For systems which do NOT have ctime_r(), we make the
184 * assumption that ctime() is re-entrant, and returns a
185 * per-thread data structure.
187 * Even if ctime is NOT re-entrant, this function will
188 * lower the possibility of race conditions.
190 char *ctime_r(const time_t *l_clock, char *l_buf)
192 strcpy(l_buf, ctime(l_clock));
198 #ifndef HAVE_GMTIME_R
200 * We use gmtime_r() by default in the server.
202 * For systems which do NOT have gmtime_r(), we make the
203 * assumption that gmtime() is re-entrant, and returns a
204 * per-thread data structure.
206 * Even if gmtime is NOT re-entrant, this function will
207 * lower the possibility of race conditions.
209 struct tm *gmtime_r(const time_t *l_clock, struct tm *result)
211 memcpy(result, gmtime(l_clock), sizeof(*result));