masqmail-0.2

view src/libident/support.c @ 58:6ab62592cac4

install docs and examples too
author meillo@marmaro.de
date Sat, 29 May 2010 22:33:10 +0200
parents 08114f7dcc23
children
line source
1 /*
2 ** support.c
3 **
4 ** Author: Pr Emanuelsson <pell@lysator.liu.se>
5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
6 */
7 #include <stdio.h>
8 #include <ctype.h>
10 #ifdef HAVE_ANSIHEADERS
11 # include <stdlib.h>
12 # include <string.h>
13 #else
14 # define strchr(str, c) index(str, c)
15 #endif
17 #define IN_LIBIDENT_SRC
18 #include "ident.h"
21 char*
22 id_strdup __P1(char *, str)
23 {
24 char *cp;
26 cp = (char *) malloc(strlen(str) + 1);
27 if (cp == NULL) {
28 #ifdef DEBUG
29 perror("libident: malloc");
30 #endif
31 return NULL;
32 }
34 strcpy(cp, str);
36 return cp;
37 }
40 char*
41 id_strtok __P3(char *, cp, char *, cs, char *, dc)
42 {
43 static char *bp = 0;
45 if (cp)
46 bp = cp;
48 /*
49 ** No delimitor cs - return whole buffer and point at end
50 */
51 if (!cs) {
52 while (*bp)
53 bp++;
54 return cs;
55 }
57 /*
58 ** Skip leading spaces
59 */
60 while (isspace(*bp))
61 bp++;
63 /*
64 ** No token found?
65 */
66 if (!*bp)
67 return 0;
69 cp = bp;
70 while (*bp && !strchr(cs, *bp))
71 bp++;
73 /*
74 ** Remove trailing spaces
75 */
76 *dc = *bp;
77 for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
78 *++dc = '\0';
80 bp++;
82 return cp;
83 }