home *** CD-ROM | disk | FTP | other *** search
- /* $Id: string.c 2.1 91/02/28 11:16:33 cthuang Exp $
- *
- * Some string handling routines
- */
- #include <stdio.h>
- #include "config.h"
-
- /* Copy the string into an allocated memory block.
- * Return a pointer to the copy.
- */
- char *
- strdup (s)
- char *s;
- {
- char *dest;
-
- if ((dest = malloc((unsigned)(strlen(s)+1))) == NULL) {
- fprintf(stderr, "No memory to duplicate string.\n");
- exit(1);
- }
- strcpy(dest, s);
- return dest;
- }
-
- /* Return a pointer to the first occurence of the substring
- * within the string, or NULL if not found.
- */
- char *
- strstr (src, key)
- char *src, *key;
- {
- char *s;
- int keylen;
-
- keylen = strlen(key);
- s = index(src, *key);
- while (s != NULL) {
- if (strncmp(s, key, keylen) == 0)
- return s;
- s = index(s+1, *key);
- }
- return NULL;
- }
-