1 |
|
2 |
#include <string.h> |
3 |
#include "compat.h" |
4 |
|
5 |
/* |
6 |
* Name: strstr and strdup |
7 |
* |
8 |
* These are the standard library utilities. We define them here for |
9 |
* systems that don't have them. |
10 |
*/ |
11 |
|
12 |
#ifndef HAVE_STRSTR |
13 |
char *strstr(char *s1, char *s2) |
14 |
{ /* from libiberty */ |
15 |
char *p; |
16 |
int len = strlen(s2); |
17 |
|
18 |
if (*s2 == '\0') /* everything matches empty string */ |
19 |
return s1; |
20 |
for (p = s1; (p = strchr(p, *s2)) != NULL; p = strchr(p + 1, *s2)) { |
21 |
if (strncmp(p, s2, len) == 0) |
22 |
return (p); |
23 |
} |
24 |
return NULL; |
25 |
} |
26 |
#endif |
27 |
|
28 |
#ifndef HAVE_STRDUP |
29 |
char *strdup(char *s) |
30 |
{ |
31 |
char *retval; |
32 |
|
33 |
retval = (char *) malloc(strlen(s) + 1); |
34 |
if (retval == NULL) { |
35 |
perror("Hydra: out of memory in strdup"); |
36 |
exit(1); |
37 |
} |
38 |
return strcpy(retval, s); |
39 |
} |
40 |
#endif |
41 |
|
42 |
#ifndef HAVE_ALPHASORT |
43 |
|
44 |
int alphasort(const struct dirent **a, const struct dirent **b) |
45 |
{ |
46 |
return (strcmp((*a)->d_name, (*b)->d_name)); |
47 |
} |
48 |
|
49 |
#endif /* HAVE_ALPHASORT */ |
50 |
|
51 |
#ifndef HAVE_GMTIME_R |
52 |
struct tm *gmtime_r(const time_t *timep, struct tm *result) |
53 |
{ |
54 |
memcpy( result, gmtime( timep), sizeof( struct tm)); |
55 |
return result; |
56 |
} |
57 |
#endif |