1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Open configuration file. Up to five directories are searched.
9
If all attempts fail, return NULL.
12
(1) Environment variable HOME used.
18
(1) File pointer, if file found.
19
(2) NULL, if all attempts to find file failed.
21
========includes:============================================================*/
28
/*======try to find and open .garlicrc file:=================================*/
30
FILE *OpenConfigFile_ (void)
33
char tildaA[10] = "~";
36
char config_file_nameA[STRINGSIZE];
38
/* The first attempt - try to find .garlicrc file in current directory: */
39
if ((fileP = fopen (".garlicrc", "r")) != NULL) return fileP;
41
/* The second attempt - try to find .garlicrc file in users home directory: */
42
/** Prepare file name: **/
45
if ((home_dirP = getenv ("HOME")) != NULL) break;
46
if ((home_dirP = getenv ("home")) != NULL) break;
50
strncpy (config_file_nameA, home_dirP, n);
51
config_file_nameA[n] = '\0';
52
strncat (config_file_nameA, "/.garlicrc", 11);
53
config_file_nameA[STRINGSIZE - 1] = '\0';
55
/** Try to open file: **/
56
if ((fileP = fopen (config_file_nameA, "r")) != NULL) return fileP;
58
/* The third attempt - try to find personal file in $HOME/garlic directory: */
60
strncpy (config_file_nameA, home_dirP, n);
61
config_file_nameA[n] = '\0';
62
strncat (config_file_nameA, "/garlic/.garlicrc", 18);
63
config_file_nameA[STRINGSIZE - 1] = '\0';
65
/** Try to open file: **/
66
if ((fileP = fopen (config_file_nameA, "r")) != NULL) return fileP;
68
/* The fourth attempt - try with public .garlicrc file: */
69
if ((fileP = fopen ("/usr/local/lib/garlic/.garlicrc", "r")) != NULL)
74
/* The last (fifth) attempt (try to find public .garlicrc file): */
75
if ((fileP = fopen ("/usr/lib/garlic/.garlicrc", "r")) != NULL) return fileP;
77
/* If this point is reached, all five attempts to open file failed: */
81
/*===========================================================================*/