Ticket #394: handle the empty ~/.mc/history file correctly.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
d5f1442438
Коммит
5a67008194
@ -19,8 +19,14 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#include "../../vfs/vfs.h" /* mc_stat */
|
||||
|
||||
#include "mcconfig.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
@ -42,6 +48,7 @@ mc_config_t *
|
||||
mc_config_init (const gchar * ini_path)
|
||||
{
|
||||
mc_config_t *mc_config;
|
||||
struct stat st;
|
||||
|
||||
mc_config = g_try_malloc0 (sizeof (mc_config_t));
|
||||
|
||||
@ -59,15 +66,18 @@ mc_config_init (const gchar * ini_path)
|
||||
return mc_config;
|
||||
}
|
||||
|
||||
if (!g_key_file_load_from_file
|
||||
(mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL))
|
||||
if (((mc_stat (ini_path, &st) == 0) && (st.st_size == 0))
|
||||
|| g_key_file_load_from_file
|
||||
(mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL))
|
||||
{
|
||||
g_key_file_free (mc_config->handle);
|
||||
g_free (mc_config);
|
||||
return NULL;
|
||||
/* file is empty or normal */
|
||||
mc_config->ini_path = g_strdup (ini_path);
|
||||
return mc_config;
|
||||
}
|
||||
mc_config->ini_path = g_strdup (ini_path);
|
||||
return mc_config;
|
||||
|
||||
g_key_file_free (mc_config->handle);
|
||||
g_free (mc_config);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user