1 /*
2 * This file is part of the bip project
3 * Copyright (C) 2016 Pierre-Louis Bonicoli
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file "COPYING" for the exact licensing terms.
10 */
11
12 #include "path_util.h"
13 #include "util.h"
14
15 #include <stdio.h>
16 #include <string.h>
17
default_path(const char * biphome,const char * filename,const char * desc)18 char *default_path(const char *biphome, const char *filename, const char *desc)
19 {
20 char *conf_file;
21 // '/' and \0
22 conf_file = bip_malloc(strlen(biphome) + strlen(filename) + 2);
23 strcpy(conf_file, biphome);
24 conf_file[strlen(biphome)] = '/';
25 conf_file[strlen(biphome) + 1] = '\0';
26 strcat(conf_file, filename);
27 mylog(LOG_INFO, "Default %s: %s", desc, conf_file);
28 return conf_file;
29 }
30
assert_path_exists(char * path)31 void assert_path_exists(char *path)
32 {
33 struct stat st_buf;
34
35 if (stat(path, &st_buf) != 0)
36 fatal("Path %s doesn't exist (%s)", path, strerror(errno));
37 }
38