From ff547aeebbfc7c5a91dda9793a5253eb15f81030 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 6 Nov 2012 19:00:00 +0100 Subject: [PATCH] ptp4l: ignore empty lines and comments in config. Signed-off-by: Miroslav Lichvar --- config.c | 15 +++++++++++++-- ptp4l.8 | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index 6444108..e0d87d5 100644 --- a/config.c +++ b/config.c @@ -18,6 +18,7 @@ */ #include #include +#include #include "config.h" #include "ether.h" #include "print.h" @@ -318,7 +319,7 @@ int config_read(char *name, struct config *cfg) { enum config_section current_section = GLOBAL_SECTION; FILE *fp; - char line[1024]; + char buf[1024], *line; int current_port; fp = 0 == strncmp(name, "-", 2) ? stdin : fopen(name, "r"); @@ -328,7 +329,17 @@ int config_read(char *name, struct config *cfg) return -1; } - while (fgets(line, sizeof(line), fp)) { + while (fgets(buf, sizeof(buf), fp)) { + line = buf; + + /* skip whitespace characters */ + while (isspace(line[0])) + line++; + + /* ignore empty lines and comments */ + if (line[0] == '#' || line[0] == '\n' || line[0] == '\0') + continue; + if (scan_mode(line, ¤t_section) ) { if (current_section == PORT_SECTION) { char port[17]; diff --git a/ptp4l.8 b/ptp4l.8 index f496ede..1114b34 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -113,7 +113,8 @@ Display a help message. The configuration file is divided into sections. Each section starts with a line containing its name enclosed in brackets and it follows with settings. Each setting is placed on a separate line, it contains the name of the -option and the value separated by whitespace characters. +option and the value separated by whitespace characters. Empty lines and lines +starting with # are ignored. The global section (indicated as .BR [global] )