2 * missing.c Replacements for functions that are or can be
3 * missing on some platforms.
9 static const char rcsid[] = "$Id$";
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
21 #include "libradius.h"
25 char *crypt(char *key, char *salt)
27 /*log(L_ERR, "crypt() called but not implemented");*/
28 return "____fnord____";
32 #ifndef HAVE_STRNCASECMP
33 int strncasecmp(char *s1, char *s2, int n)
36 unsigned char *p1, *p2;
39 p1 = (unsigned char *)s1;
40 p2 = (unsigned char *)s2;
44 if (*p1 == 0 && *p2 == 0)
49 if (islower(c1)) c1 = toupper(c1);
50 if (islower(c2)) c2 = toupper(c2);
52 if ((dif = c1 - c2) != 0)
62 #ifndef HAVE_STRCASECMP
63 int strcasecmp(char *s1, char *s2)
71 return strncasecmp(s1, s2, l1);
75 #ifndef HAVE_INET_ATON
76 int inet_aton(char *cp, struct in_addr *inp)
80 if (sscanf(cp, "%d.%d.%d.%d", &a1, &a2, &a3, &a4) != 4)
83 inp->s_addr = htonl((a1 << 24) + (a2 << 16) + (a3 << 8) + a4);
88 #ifndef HAVE_GETHOSTNAME
89 int gethostname(char *name, int len)
93 h = getenv("HOSTNAME");
94 if (strlen(h) + 1 > len)
103 * Get next token from string *stringp, where tokens are
104 * possibly-empty strings separated by characters from delim.
106 * Writes NULs into the string at *stringp to end tokens.
107 * delim need not remain constant from call to call. On
108 * return, *stringp points past the last NUL written (if there
109 * might be further tokens), or is NULL (if there are
110 * definitely no more tokens).
112 * If *stringp is NULL, strsep returns NULL.
115 strsep(char **stringp, const char *delim)
122 if ((s = *stringp) == NULL)
129 if ((sc = *spanp++) == c) {
140 return NULL; /* NOTREACHED, but the compiler complains */
144 #ifndef HAVE_LOCALTIME_R
146 * We use localtime_r() by default in the server.
148 * For systems which do NOT have localtime_r(), we make the
149 * assumption that localtime() is re-entrant, and returns a
150 * per-thread data structure.
152 * Even if localtime is NOT re-entrant, this function will
153 * lower the possibility of race conditions.
155 struct tm *localtime_r(const time_t *l_clock, struct tm *result)
157 memcpy(result, localtime(l_clock), sizeof(*result));
165 * We use ctime_r() by default in the server.
167 * For systems which do NOT have ctime_r(), we make the
168 * assumption that ctime() is re-entrant, and returns a
169 * per-thread data structure.
171 * Even if ctime is NOT re-entrant, this function will
172 * lower the possibility of race conditions.
174 char *ctime_r(const time_t *l_clock, char *l_buf)
176 strcpy(l_buf, ctime(l_clock));