From 91d4db762934f01e4ba0e32e94bf4e7aa7680db1 Mon Sep 17 00:00:00 2001 From: David Shen Date: Sat, 14 Aug 2010 13:28:12 +0800 Subject: [PATCH] fix_trim_left_space --- ssmtp.c | 34 ++++++++++++++++++++++++++++------ 1 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ssmtp.c b/ssmtp.c index 9d9a7f3..4bd053f 100644 --- a/ssmtp.c +++ b/ssmtp.c @@ -850,6 +850,32 @@ char *firsttok(char **s, const char *delim) } /* + * This is a simple trim function that only trim the space on the left of the string. + * It will not duplicate the original string. It returns a pointer of the original string which is not a space + * Args: + * char *str: + * Address of the pointer to the string we are going to trim. + * Return value: + * The pointer to the first none space character in the original string. + * You do not need to free this pointer. + */ +char *trimleft(char *str) { + if(str == (char *)NULL) + return NULL; + + while(str != (char *)NULL) { + if(isspace(*str)) { + str++; + continue; + } + + break; + } + + return str; +} + +/* read_config() -- Open and parse config file and extract values of variables */ bool_t read_config() @@ -869,15 +895,11 @@ bool_t read_config() } while(fgets(buf, sizeof(buf), fp)) { - char *begin=buf; + char *begin=trimleft(buf); char *rightside; - /* Make comments invisible */ - if((p = strchr(buf, '#'))) { - *p = (char)NULL; - } /* Ignore malformed lines and comments */ - if(strchr(buf, '=') == (char *)NULL) continue; + if(*begin == '#' || strchr(buf, '=') == (char *)NULL) continue; /* Parse out keywords */ p=firsttok(&begin, "= \t\n"); -- 1.7.2