/[hydra]/hydra/src/strutil.c
ViewVC logotype

Contents of /hydra/src/strutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Oct 2 13:48:35 2002 UTC (21 years, 6 months ago) by nmav
Branch: MAIN
File MIME type: text/plain
Added compatibility function implementations such as scandir(), strstr() etc, in src/. Scandir implementation was replaced by the one in gnu libc.

1
2 #include "compat.h"
3
4 /*
5 * Name: strstr and strdup
6 *
7 * These are the standard library utilities. We define them here for
8 * systems that don't have them.
9 */
10
11 #ifndef HAVE_STRSTR
12 char *strstr(char *s1, char *s2)
13 { /* from libiberty */
14 char *p;
15 int len = strlen(s2);
16
17 if (*s2 == '\0') /* everything matches empty string */
18 return s1;
19 for (p = s1; (p = strchr(p, *s2)) != NULL; p = strchr(p + 1, *s2)) {
20 if (strncmp(p, s2, len) == 0)
21 return (p);
22 }
23 return NULL;
24 }
25 #endif
26
27 #ifndef HAVE_STRDUP
28 char *strdup(char *s)
29 {
30 char *retval;
31
32 retval = (char *) malloc(strlen(s) + 1);
33 if (retval == NULL) {
34 perror("Hydra: out of memory in strdup");
35 exit(1);
36 }
37 return strcpy(retval, s);
38 }
39 #endif

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26