Mercurial > masqmail-0.2
comparison src/libident/support.c @ 0:08114f7dcc23 0.2.21
this is masqmail-0.2.21 from oliver kurth
author | meillo@marmaro.de |
---|---|
date | Fri, 26 Sep 2008 17:05:23 +0200 |
parents | |
children | 26e34ae9a3e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:08114f7dcc23 |
---|---|
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> | |
9 | |
10 #ifdef HAVE_ANSIHEADERS | |
11 # include <stdlib.h> | |
12 # include <string.h> | |
13 #else | |
14 # define strchr(str, c) index(str, c) | |
15 #endif | |
16 | |
17 #define IN_LIBIDENT_SRC | |
18 #include "ident.h" | |
19 | |
20 | |
21 char *id_strdup __P1(char *, str) | |
22 { | |
23 char *cp; | |
24 | |
25 cp = (char *) malloc(strlen(str)+1); | |
26 if (cp == NULL) | |
27 { | |
28 #ifdef DEBUG | |
29 perror("libident: malloc"); | |
30 #endif | |
31 return NULL; | |
32 } | |
33 | |
34 strcpy(cp, str); | |
35 | |
36 return cp; | |
37 } | |
38 | |
39 | |
40 char *id_strtok __P3(char *, cp, | |
41 char *, cs, | |
42 char *, dc) | |
43 { | |
44 static char *bp = 0; | |
45 | |
46 if (cp) | |
47 bp = cp; | |
48 | |
49 /* | |
50 ** No delimitor cs - return whole buffer and point at end | |
51 */ | |
52 if (!cs) | |
53 { | |
54 while (*bp) | |
55 bp++; | |
56 return cs; | |
57 } | |
58 | |
59 /* | |
60 ** Skip leading spaces | |
61 */ | |
62 while (isspace(*bp)) | |
63 bp++; | |
64 | |
65 /* | |
66 ** No token found? | |
67 */ | |
68 if (!*bp) | |
69 return 0; | |
70 | |
71 cp = bp; | |
72 while (*bp && !strchr(cs, *bp)) | |
73 bp++; | |
74 | |
75 /* | |
76 ** Remove trailing spaces | |
77 */ | |
78 *dc = *bp; | |
79 for (dc = bp-1; dc > cp && isspace(*dc); dc--) | |
80 ; | |
81 *++dc = '\0'; | |
82 | |
83 bp++; | |
84 | |
85 return cp; | |
86 } |