masqmail
view src/libident/support.c @ 1:af25f5c39d90
added diff from debian (masqmail-0.2.21-4)
author | meillo@marmaro.de |
---|---|
date | Fri, 26 Sep 2008 20:56:23 +0200 |
parents | |
children | 26e34ae9a3e3 |
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 *id_strdup __P1(char *, str)
22 {
23 char *cp;
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 }
34 strcpy(cp, str);
36 return cp;
37 }
40 char *id_strtok __P3(char *, cp,
41 char *, cs,
42 char *, dc)
43 {
44 static char *bp = 0;
46 if (cp)
47 bp = cp;
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 }
59 /*
60 ** Skip leading spaces
61 */
62 while (isspace(*bp))
63 bp++;
65 /*
66 ** No token found?
67 */
68 if (!*bp)
69 return 0;
71 cp = bp;
72 while (*bp && !strchr(cs, *bp))
73 bp++;
75 /*
76 ** Remove trailing spaces
77 */
78 *dc = *bp;
79 for (dc = bp-1; dc > cp && isspace(*dc); dc--)
80 ;
81 *++dc = '\0';
83 bp++;
85 return cp;
86 }