masqmail-0.2
diff src/libident/support.c @ 0:08114f7dcc23
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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/libident/support.c Fri Sep 26 17:05:23 2008 +0200 1.3 @@ -0,0 +1,86 @@ 1.4 +/* 1.5 +** support.c 1.6 +** 1.7 +** Author: Pr Emanuelsson <pell@lysator.liu.se> 1.8 +** Hacked by: Peter Eriksson <pen@lysator.liu.se> 1.9 +*/ 1.10 +#include <stdio.h> 1.11 +#include <ctype.h> 1.12 + 1.13 +#ifdef HAVE_ANSIHEADERS 1.14 +# include <stdlib.h> 1.15 +# include <string.h> 1.16 +#else 1.17 +# define strchr(str, c) index(str, c) 1.18 +#endif 1.19 + 1.20 +#define IN_LIBIDENT_SRC 1.21 +#include "ident.h" 1.22 + 1.23 + 1.24 +char *id_strdup __P1(char *, str) 1.25 +{ 1.26 + char *cp; 1.27 + 1.28 + cp = (char *) malloc(strlen(str)+1); 1.29 + if (cp == NULL) 1.30 + { 1.31 +#ifdef DEBUG 1.32 + perror("libident: malloc"); 1.33 +#endif 1.34 + return NULL; 1.35 + } 1.36 + 1.37 + strcpy(cp, str); 1.38 + 1.39 + return cp; 1.40 +} 1.41 + 1.42 + 1.43 +char *id_strtok __P3(char *, cp, 1.44 + char *, cs, 1.45 + char *, dc) 1.46 +{ 1.47 + static char *bp = 0; 1.48 + 1.49 + if (cp) 1.50 + bp = cp; 1.51 + 1.52 + /* 1.53 + ** No delimitor cs - return whole buffer and point at end 1.54 + */ 1.55 + if (!cs) 1.56 + { 1.57 + while (*bp) 1.58 + bp++; 1.59 + return cs; 1.60 + } 1.61 + 1.62 + /* 1.63 + ** Skip leading spaces 1.64 + */ 1.65 + while (isspace(*bp)) 1.66 + bp++; 1.67 + 1.68 + /* 1.69 + ** No token found? 1.70 + */ 1.71 + if (!*bp) 1.72 + return 0; 1.73 + 1.74 + cp = bp; 1.75 + while (*bp && !strchr(cs, *bp)) 1.76 + bp++; 1.77 + 1.78 + /* 1.79 + ** Remove trailing spaces 1.80 + */ 1.81 + *dc = *bp; 1.82 + for (dc = bp-1; dc > cp && isspace(*dc); dc--) 1.83 + ; 1.84 + *++dc = '\0'; 1.85 + 1.86 + bp++; 1.87 + 1.88 + return cp; 1.89 +}