comparison mcabber/src/settings.c @ 1383:d9606bd03144

Small code cleanup
author Mikael Berthe <mikael@lilotux.net>
date Sun, 02 Dec 2007 13:38:44 +0100
parents 7daf906fbcdc
children d431cd75eb53
comparison
equal deleted inserted replaced
1382:1447c5296977 1383:d9606bd03144
95 int err = 0; 95 int err = 0;
96 96
97 if (!filename) { 97 if (!filename) {
98 // Use default config file locations 98 // Use default config file locations
99 char *home; 99 char *home;
100 GString *sfilename;
100 101
101 if (!mainfile) { 102 if (!mainfile) {
102 scr_LogPrint(LPRINT_LOGNORM, "No file name provided"); 103 scr_LogPrint(LPRINT_LOGNORM, "No file name provided");
103 return -1; 104 return -1;
104 } 105 }
108 scr_LogPrint(LPRINT_LOG, "Can't find home dir!"); 109 scr_LogPrint(LPRINT_LOG, "Can't find home dir!");
109 fprintf(stderr, "Can't find home dir!\n"); 110 fprintf(stderr, "Can't find home dir!\n");
110 err = -1; 111 err = -1;
111 goto cfg_read_file_return; 112 goto cfg_read_file_return;
112 } 113 }
113 filename = g_new(char, strlen(home)+24); 114 sfilename = g_string_new("");
114 sprintf(filename, "%s/.mcabber/mcabberrc", home); 115 g_string_printf(sfilename, "%s/.mcabber/mcabberrc", home);
115 if ((fp = fopen(filename, "r")) == NULL) { 116 if ((fp = fopen(sfilename->str, "r")) == NULL) {
116 // 2nd try... 117 // 2nd try...
117 sprintf(filename, "%s/.mcabberrc", home); 118 g_string_printf(sfilename, "%s/.mcabberrc", home);
118 if ((fp = fopen(filename, "r")) == NULL) { 119 if ((fp = fopen(sfilename->str, "r")) == NULL) {
119 fprintf(stderr, "Cannot open config file!\n"); 120 fprintf(stderr, "Cannot open config file!\n");
120 g_free(filename); 121 g_string_free(sfilename, TRUE);
121 err = -1; 122 err = -1;
122 goto cfg_read_file_return; 123 goto cfg_read_file_return;
123 } 124 }
124 } 125 }
125 // Check configuration file permissions 126 // Check configuration file permissions
126 // As it could contain sensitive data, we make it user-readable only. 127 // As it could contain sensitive data, we make it user-readable only.
127 checkset_perm(filename, TRUE); 128 checkset_perm(sfilename->str, TRUE);
128 scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); 129 scr_LogPrint(LPRINT_LOGNORM, "Reading %s", sfilename->str);
129 // Check mcabber dir. Here we just warn, we don't change the modes. 130 // Check mcabber dir. Here we just warn, we don't change the modes.
130 sprintf(filename, "%s/.mcabber/", home); 131 g_string_printf(sfilename, "%s/.mcabber/", home);
131 checkset_perm(filename, FALSE); 132 checkset_perm(sfilename->str, FALSE);
132 g_free(filename); 133 g_string_free(sfilename, TRUE);
133 filename = NULL;
134 } else { 134 } else {
135 // filename was specified
135 if ((fp = fopen(filename, "r")) == NULL) { 136 if ((fp = fopen(filename, "r")) == NULL) {
136 const char *msg = "Cannot open configuration file"; 137 const char *msg = "Cannot open configuration file";
137 if (mainfile) 138 if (mainfile)
138 perror(msg); 139 perror(msg);
139 else 140 else