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 The FreeRADIUS server project
24 static const char rcsid[] = "$Id$";
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
36 #include "libradius.h"
40 char *crypt(char *key, char *salt)
42 /*log(L_ERR, "crypt() called but not implemented");*/
43 return "____fnord____";
47 #ifndef HAVE_STRNCASECMP
48 int strncasecmp(char *s1, char *s2, int n)
51 unsigned char *p1, *p2;
54 p1 = (unsigned char *)s1;
55 p2 = (unsigned char *)s2;
59 if (*p1 == 0 && *p2 == 0)
64 if (islower(c1)) c1 = toupper(c1);
65 if (islower(c2)) c2 = toupper(c2);
67 if ((dif = c1 - c2) != 0)
77 #ifndef HAVE_STRCASECMP
78 int strcasecmp(char *s1, char *s2)
86 return strncasecmp(s1, s2, l1);
90 #ifndef HAVE_INET_ATON
91 int inet_aton(char *cp, struct in_addr *inp)
95 if (sscanf(cp, "%d.%d.%d.%d", &a1, &a2, &a3, &a4) != 4)
98 inp->s_addr = htonl((a1 << 24) + (a2 << 16) + (a3 << 8) + a4);
103 #ifndef HAVE_GETHOSTNAME
104 int gethostname(char *name, int len)
108 h = getenv("HOSTNAME");
109 if (!h || (strlen(h) + 1 > len))
118 * Get next token from string *stringp, where tokens are
119 * possibly-empty strings separated by characters from delim.
121 * Writes NULs into the string at *stringp to end tokens.
122 * delim need not remain constant from call to call. On
123 * return, *stringp points past the last NUL written (if there
124 * might be further tokens), or is NULL (if there are
125 * definitely no more tokens).
127 * If *stringp is NULL, strsep returns NULL.
130 strsep(char **stringp, const char *delim)
137 if ((s = *stringp) == NULL)
144 if ((sc = *spanp++) == c) {
155 return NULL; /* NOTREACHED, but the compiler complains */
159 #ifndef HAVE_LOCALTIME_R
161 * We use localtime_r() by default in the server.
163 * For systems which do NOT have localtime_r(), we make the
164 * assumption that localtime() is re-entrant, and returns a
165 * per-thread data structure.
167 * Even if localtime is NOT re-entrant, this function will
168 * lower the possibility of race conditions.
170 struct tm *localtime_r(const time_t *l_clock, struct tm *result)
172 memcpy(result, localtime(l_clock), sizeof(*result));
180 * We use ctime_r() by default in the server.
182 * For systems which do NOT have ctime_r(), we make the
183 * assumption that ctime() is re-entrant, and returns a
184 * per-thread data structure.
186 * Even if ctime is NOT re-entrant, this function will
187 * lower the possibility of race conditions.
189 char *ctime_r(const time_t *l_clock, char *l_buf)
191 strcpy(l_buf, ctime(l_clock));
197 #ifndef HAVE_GMTIME_R
199 * We use gmtime_r() by default in the server.
201 * For systems which do NOT have gmtime_r(), we make the
202 * assumption that gmtime() is re-entrant, and returns a
203 * per-thread data structure.
205 * Even if gmtime is NOT re-entrant, this function will
206 * lower the possibility of race conditions.
208 struct tm *gmtime_r(const time_t *l_clock, struct tm *result)
210 memcpy(result, gmtime(l_clock), sizeof(*result));