(load_mc_home_file): return data length.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-01-11 16:17:08 +03:00
parent e3e4382612
commit 28ce7e566e
4 changed files with 10 additions and 9 deletions

View File

@ -583,7 +583,8 @@ extension (const char *filename)
/* --------------------------------------------------------------------------------------------- */
char *
load_mc_home_file (const char *from, const char *filename, char **allocated_filename)
load_mc_home_file (const char *from, const char *filename, char **allocated_filename,
size_t * length)
{
char *hintfile_base, *hintfile;
char *lang;
@ -593,18 +594,18 @@ load_mc_home_file (const char *from, const char *filename, char **allocated_file
lang = guess_message_value ();
hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
if (!g_file_get_contents (hintfile, &data, NULL, NULL))
if (!g_file_get_contents (hintfile, &data, length, NULL))
{
/* Fall back to the two-letter language code */
if (lang[0] != '\0' && lang[1] != '\0')
lang[2] = '\0';
g_free (hintfile);
hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
if (!g_file_get_contents (hintfile, &data, NULL, NULL))
if (!g_file_get_contents (hintfile, &data, length, NULL))
{
g_free (hintfile);
hintfile = hintfile_base;
g_file_get_contents (hintfile_base, &data, NULL, NULL);
g_file_get_contents (hintfile_base, &data, length, NULL);
}
}

View File

@ -172,7 +172,8 @@ char *diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
/* Returns the basename of fname. The result is a pointer into fname. */
const char *x_basename (const char *fname);
char *load_mc_home_file (const char *from, const char *filename, char **allocated_filename);
char *load_mc_home_file (const char *from, const char *filename, char **allocated_filename,
size_t * length);
/* uid/gid managing */
void init_groups (void);

View File

@ -1337,7 +1337,7 @@ char *
get_random_hint (int force)
{
char *data, *result = NULL, *eop;
int len;
size_t len;
int start;
static int last_sec;
static struct timeval tv;
@ -1349,13 +1349,12 @@ get_random_hint (int force)
return g_strdup ("");
last_sec = tv.tv_sec;
data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL);
data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL, &len);
if (data == NULL)
return NULL;
/* get a random entry */
srand (tv.tv_sec);
len = strlen (data);
start = rand () % (len - 1);
/* Search the start of paragraph */

View File

@ -1080,7 +1080,7 @@ help_interactive_display (const gchar * event_group_name, const gchar * event_na
if (event_data->filename != NULL)
g_file_get_contents (event_data->filename, &filedata, NULL, NULL);
else
filedata = load_mc_home_file (mc_global.share_data_dir, MC_HELP, &hlpfile);
filedata = load_mc_home_file (mc_global.share_data_dir, MC_HELP, &hlpfile, NULL);
if (filedata == NULL)
message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"),