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

Contents of /hydra/src/strutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Oct 2 15:17:42 2002 UTC (18 years, 11 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_0_6
Changes since 1.1: +10 -0 lines
File MIME type: text/plain
Moved alphasort.c to strutil.c.

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 */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26