From patchwork Sat Jun 20 19:18:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 5110 Return-Path: Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by open-mesh.net (Postfix) with SMTP id C03171543CE for ; Sat, 20 Jun 2009 19:38:22 +0000 (UTC) Received: (qmail invoked by alias); 20 Jun 2009 19:18:02 -0000 Received: from unknown (EHLO localhost) [89.246.219.40] by mail.gmx.net (mp027) with SMTP; 20 Jun 2009 21:18:02 +0200 X-Authenticated: #15668376 X-Provags-ID: V01U2FsdGVkX18l5513UR4la1cTRJyLz+jY2JQhm/N7hQVzLngoMN qDN+MVWkqAe6g3 From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.net Date: Sat, 20 Jun 2009 21:18:00 +0200 Message-Id: <1245525480-23538-1-git-send-email-sven.eckelmann@gmx.de> X-Mailer: git-send-email 1.6.3.1 X-Y-GMX-Trusted: 0 X-FuHaFi: 0.53 Subject: [B.A.T.M.A.N.] [PATCH] [batctl] Expand ~ in paths to host files X-BeenThere: b.a.t.m.a.n@lists.open-mesh.net X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jun 2009 19:38:24 -0000 Signed-off-by: Sven Eckelmann --- batctl/bat-hosts.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/batctl/bat-hosts.c b/batctl/bat-hosts.c index 95d105f..e997ad0 100644 --- a/batctl/bat-hosts.c +++ b/batctl/bat-hosts.c @@ -67,7 +67,6 @@ static void parse_hosts_file(struct hashtable_t *hash, const char path[]) struct hashtable_t *swaphash; name[0] = mac_str[0] = '\0'; - fd = fopen(path, "r"); if (fd == NULL) return; @@ -129,6 +128,9 @@ static void parse_hosts_file(struct hashtable_t *hash, const char path[]) void bat_hosts_init(void) { unsigned int i; +#define CONF_DIR_LEN 256 + char confdir[CONF_DIR_LEN]; + char *homedir; host_hash = hash_new(64, compare_mac, choose_mac); @@ -137,8 +139,21 @@ void bat_hosts_init(void) return; } - for (i = 0; i < sizeof(bat_hosts_path) / sizeof(char *); i++) - parse_hosts_file(host_hash, bat_hosts_path[i]); + homedir = getenv("HOME"); + + for (i = 0; i < sizeof(bat_hosts_path) / sizeof(char *); i++) { + strcpy(confdir, ""); + if (strlen(bat_hosts_path[i]) >= 2 + && bat_hosts_path[i][0] == '~' && bat_hosts_path[i][1] == '/') { + strncpy(confdir, homedir, CONF_DIR_LEN); + confdir[CONF_DIR_LEN - 1] = '\0'; + strncat(confdir, &bat_hosts_path[i][1], CONF_DIR_LEN - strlen(confdir)); + } else { + strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN); + confdir[CONF_DIR_LEN - 1] = '\0'; + } + parse_hosts_file(host_hash, confdir); + } } struct bat_host *bat_hosts_find_by_name(char *name)