1
1

Merge branch '2069_memory_leaks'

* 2069_memory_leaks:
  Applied MC indentation policy.
  Ticket #2119: Fixed memory leaks in command_completion_function() function.
  Ticket #2108: Fixed memory leak in fish_linear_start() function.
  lib/util.c: Fixed memleak  in load_mc_home_file() function
  Fixed memory leak in mc_search__cond_struct_new_regex_accum_append().
  Free FS info before closing panel.
  Fixed memory leaks in viewer.
  Destroy converter before quit from editor.
  Fixed memory leaks in edit_search_cmd().
  Fixed memory leak in mc_closedir().
  Fixed memory leak in vfs_free_handle().
  Fixed memory leak in vfs_s_getlocalcopy().
  Ticket #2069: fixed memory leaks.
Этот коммит содержится в:
Andrew Borodin 2010-03-30 16:22:47 +04:00
родитель afa93bbb36 5b68413e62
Коммит a5be507432
15 изменённых файлов: 5116 добавлений и 4259 удалений

Просмотреть файл

@ -44,8 +44,7 @@ mc_config_t *mc_panels_config;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
static gboolean
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
GError **error)
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error)
{
gchar *data, *written_data;
gsize len, total_written;
@ -54,7 +53,8 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
ssize_t cur_written;
data = g_key_file_to_data (mc_config->handle, &len, NULL);
if (!exist_file (ini_path)) {
if (!exist_file (ini_path))
{
ret = g_file_set_contents (ini_path, data, len, error);
g_free (data);
return ret;
@ -62,9 +62,12 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
mc_util_make_backup_if_possible (ini_path, "~");
fd = mc_open (ini_path, O_WRONLY | O_TRUNC | O_SYNC, 0);
if (fd == -1) {
g_propagate_error (error, g_error_new (mc_main_error_quark() ,0, "%s", unix_error_string (errno)));
g_free(data);
if (fd == -1)
{
g_propagate_error (error,
g_error_new (mc_main_error_quark (), 0, "%s",
unix_error_string (errno)));
g_free (data);
return FALSE;
}
@ -74,9 +77,12 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
mc_close (fd);
g_free (data);
if (cur_written == -1) {
if (cur_written == -1)
{
mc_util_restore_from_backup_if_possible (ini_path, "~");
g_propagate_error (error, g_error_new (mc_main_error_quark() ,0, "%s", unix_error_string (errno)));
g_propagate_error (error,
g_error_new (mc_main_error_quark (), 0, "%s",
unix_error_string (errno)));
return FALSE;
}
@ -100,15 +106,18 @@ mc_config_init (const gchar * ini_path)
return NULL;
mc_config->handle = g_key_file_new ();
if (mc_config->handle == NULL) {
if (mc_config->handle == NULL)
{
g_free (mc_config);
return NULL;
}
if (!ini_path || !exist_file (ini_path)) {
if (!ini_path || !exist_file (ini_path))
{
return mc_config;
}
if (!mc_stat (ini_path, &st) && st.st_size) {
if (!mc_stat (ini_path, &st) && st.st_size)
{
/* file present and not empty */
g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
}
@ -195,7 +204,8 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path)
gchar **keys, **curr_key;
gchar *value;
if (mc_config == NULL) {
if (mc_config == NULL)
{
return FALSE;
}
@ -206,11 +216,16 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path)
groups = mc_config_get_groups (tmp_config, NULL);
if (groups == NULL)
{
mc_config_deinit (tmp_config);
return FALSE;
}
for (curr_grp = groups; *curr_grp != NULL; curr_grp++) {
for (curr_grp = groups; *curr_grp != NULL; curr_grp++)
{
keys = mc_config_get_keys (tmp_config, *curr_grp, NULL);
for (curr_key = keys; *curr_key != NULL; curr_key++) {
for (curr_key = keys; *curr_key != NULL; curr_key++)
{
value = g_key_file_get_value (tmp_config->handle, *curr_grp, *curr_key, NULL);
if (value == NULL)
continue;
@ -228,9 +243,10 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_save_file (mc_config_t * mc_config, GError **error)
mc_config_save_file (mc_config_t * mc_config, GError ** error)
{
if (mc_config == NULL || mc_config->ini_path == NULL) {
if (mc_config == NULL || mc_config->ini_path == NULL)
{
return FALSE;
}
return mc_config_new_or_override_file (mc_config, mc_config->ini_path, error);
@ -239,10 +255,10 @@ mc_config_save_file (mc_config_t * mc_config, GError **error)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean
mc_config_save_to_file (mc_config_t * mc_config, const gchar * ini_path, GError **error)
mc_config_save_to_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error)
{
if (mc_config == NULL) {
if (mc_config == NULL)
{
return FALSE;
}
return mc_config_new_or_override_file (mc_config, ini_path, error);

Просмотреть файл

@ -44,7 +44,8 @@
/*** file scope type declarations ****************************************************************/
typedef enum {
typedef enum
{
REPLACE_T_NO_TRANSFORM = 0,
REPLACE_T_UPP_TRANSFORM_CHAR = 1,
REPLACE_T_LOW_TRANSFORM_CHAR = 2,
@ -81,18 +82,24 @@ mc_search__regex_str_append_if_special (GString * copy_to, GString * regex_str,
tmp_regex_str = &(regex_str->str[*offset]);
while (*spec_chr) {
while (*spec_chr)
{
spec_chr_len = strlen (*spec_chr);
if (!strncmp (tmp_regex_str, *spec_chr, spec_chr_len)) {
if (!strutils_is_char_escaped (regex_str->str, tmp_regex_str)) {
if (!strncmp ("\\x", *spec_chr, spec_chr_len)) {
if (*(tmp_regex_str + spec_chr_len) == '{') {
if (!strncmp (tmp_regex_str, *spec_chr, spec_chr_len))
{
if (!strutils_is_char_escaped (regex_str->str, tmp_regex_str))
{
if (!strncmp ("\\x", *spec_chr, spec_chr_len))
{
if (*(tmp_regex_str + spec_chr_len) == '{')
{
while ((spec_chr_len < regex_str->len - *offset)
&& *(tmp_regex_str + spec_chr_len) != '}')
spec_chr_len++;
if (*(tmp_regex_str + spec_chr_len) == '}')
spec_chr_len++;
} else
}
else
spec_chr_len += 2;
}
g_string_append_len (copy_to, tmp_regex_str, spec_chr_len);
@ -118,16 +125,20 @@ mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
upp = mc_search__toupper_case_str (charset, one_char, str_len);
low = mc_search__tolower_case_str (charset, one_char, str_len);
for (loop = 0; loop < upp->len; loop++) {
for (loop = 0; loop < upp->len; loop++)
{
if (loop < low->len) {
if (loop < low->len)
{
if (upp->str[loop] == low->str[loop])
tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
else
tmp_str =
g_strdup_printf ("[\\x%02X\\x%02X]", (unsigned char) upp->str[loop],
(unsigned char) low->str[loop]);
} else {
}
else
{
tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
}
g_string_append (str_to, tmp_str);
@ -144,31 +155,34 @@ mc_search__cond_struct_new_regex_accum_append (const char *charset, GString * st
GString * str_from)
{
GString *recoded_part;
gsize loop = 0;
recoded_part = g_string_sized_new (32);
while (loop < str_from->len)
{
gchar *one_char;
gsize loop;
gsize one_char_len;
gboolean just_letters;
loop = 0;
recoded_part = g_string_new ("");
while (loop < str_from->len) {
one_char =
mc_search__get_one_symbol (charset, &(str_from->str[loop]),
(str_from->len - loop > 6) ? 6 : str_from->len - loop,
&just_letters);
if (!strlen (one_char)) {
min (str_from->len - loop, 6), &just_letters);
one_char_len = strlen (one_char);
if (one_char_len == 0)
loop++;
continue;
}
if (just_letters) {
else
{
loop += one_char_len;
if (just_letters)
mc_search__cond_struct_new_regex_hex_add (charset, recoded_part, one_char,
strlen (one_char));
} else {
g_string_append (recoded_part, one_char);
one_char_len);
else
g_string_append_len (recoded_part, one_char, one_char_len);
}
loop += strlen (one_char);
if (!strlen (one_char))
loop++;
g_free (one_char);
}
@ -193,20 +207,23 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
spec_char = g_string_new ("");
loop = 0;
while (loop <= str_len) {
if (mc_search__regex_str_append_if_special (spec_char, tmp, &loop)) {
while (loop <= str_len)
{
if (mc_search__regex_str_append_if_special (spec_char, tmp, &loop))
{
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
g_string_append_len (ret_str, spec_char->str, spec_char->len);
g_string_set_size (spec_char, 0);
continue;
}
if (tmp->str[loop] == '[' && !strutils_is_char_escaped (tmp->str, &(tmp->str[loop]))) {
if (tmp->str[loop] == '[' && !strutils_is_char_escaped (tmp->str, &(tmp->str[loop])))
{
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
while (loop < str_len && !(tmp->str[loop] == ']'
&& !strutils_is_char_escaped (tmp->str,
&(tmp->str[loop])))) {
&& !strutils_is_char_escaped (tmp->str, &(tmp->str[loop]))))
{
g_string_append_c (ret_str, tmp->str[loop]);
loop++;
@ -240,12 +257,15 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t *
if (!g_regex_match_full
(regex, search_str->str, -1, 0, G_REGEX_MATCH_NEWLINE_ANY, &lc_mc_search->regex_match_info,
&error)) {
&error))
{
g_match_info_free (lc_mc_search->regex_match_info);
lc_mc_search->regex_match_info = NULL;
if (error) {
if (error)
{
lc_mc_search->error = MC_SEARCH_E_REGEX;
lc_mc_search->error_str = str_conv_gerror_message (error, _(" Regular expression error "));
lc_mc_search->error_str =
str_conv_gerror_message (error, _(" Regular expression error "));
g_error_free (error);
return COND__FOUND_ERROR;
}
@ -254,9 +274,10 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t *
lc_mc_search->num_rezults = g_match_info_get_match_count (lc_mc_search->regex_match_info);
#else /* SEARCH_TYPE_GLIB */
lc_mc_search->num_rezults = pcre_exec (regex, lc_mc_search->regex_match_info,
search_str->str, search_str->len - 1, 0, 0, lc_mc_search->iovector,
MC_SEARCH__NUM_REPLACE_ARGS);
if (lc_mc_search->num_rezults < 0) {
search_str->str, search_str->len - 1, 0, 0,
lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS);
if (lc_mc_search->num_rezults < 0)
{
return COND__NOT_FOUND;
}
#endif /* SEARCH_TYPE_GLIB */
@ -273,13 +294,16 @@ mc_search__regex_found_cond (mc_search_t * lc_mc_search, GString * search_str)
mc_search_cond_t *mc_search_cond;
mc_search__found_cond_t ret;
for (loop1 = 0; loop1 < lc_mc_search->conditions->len; loop1++) {
for (loop1 = 0; loop1 < lc_mc_search->conditions->len; loop1++)
{
mc_search_cond = (mc_search_cond_t *) g_ptr_array_index (lc_mc_search->conditions, loop1);
if (!mc_search_cond->regex_handle)
continue;
ret = mc_search__regex_found_cond_one (lc_mc_search, mc_search_cond->regex_handle, search_str);
ret =
mc_search__regex_found_cond_one (lc_mc_search, mc_search_cond->regex_handle,
search_str);
if (ret != COND__NOT_FOUND)
return ret;
@ -294,15 +318,18 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
{
int max_token = 0;
gsize loop;
for (loop = 0; loop < len - 1; loop++) {
if (str[loop] == '\\' && (str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ ) {
for (loop = 0; loop < len - 1; loop++)
{
if (str[loop] == '\\' && (str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ )
{
if (strutils_is_char_escaped (str, &str[loop]))
continue;
if (max_token < str[loop + 1] - '0')
max_token = str[loop + 1] - '0';
continue;
}
if (str[loop] == '$' && str[loop + 1] == '{') {
if (str[loop] == '$' && str[loop + 1] == '{')
{
gsize tmp_len;
char *tmp_str;
int tmp_token;
@ -312,7 +339,8 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
for (tmp_len = 0;
loop + tmp_len + 2 < len && (str[loop + 2 + tmp_len] & (char) 0xf0) == 0x30;
tmp_len++);
if (str[loop + 2 + tmp_len] == '}') {
if (str[loop + 2 + tmp_len] == '}')
{
tmp_str = g_strndup (&str[loop + 2], tmp_len);
tmp_token = atoi (tmp_str);
if (max_token < tmp_token)
@ -359,8 +387,10 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
*skip_len = 0;
if (*curr_str == '$' && *(curr_str + 1) == '{' && (*(curr_str + 2) & (char) 0xf0) == 0x30) {
if (strutils_is_char_escaped (replace_str->str, curr_str)) {
if (*curr_str == '$' && *(curr_str + 1) == '{' && (*(curr_str + 2) & (char) 0xf0) == 0x30)
{
if (strutils_is_char_escaped (replace_str->str, curr_str))
{
*skip_len = 1;
return -1;
}
@ -383,20 +413,24 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
return ret;
}
if (*curr_str == '\\') {
if (strutils_is_char_escaped (replace_str->str, curr_str)) {
if (*curr_str == '\\')
{
if (strutils_is_char_escaped (replace_str->str, curr_str))
{
*skip_len = 1;
return -1;
}
if ((*(curr_str + 1) & (char) 0xf0) == 0x30) {
if ((*(curr_str + 1) & (char) 0xf0) == 0x30)
{
ret = *(curr_str + 1) - '0';
*skip_len = 2; /* \\ and one digit */
return ret;
}
ret = -2;
*skip_len += 2;
switch (*(curr_str + 1)) {
switch (*(curr_str + 1))
{
case 'U':
*replace_flags |= REPLACE_T_UPP_TRANSFORM;
*replace_flags &= ~REPLACE_T_LOW_TRANSFORM;
@ -430,39 +464,50 @@ mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize
char *tmp_str;
GString *tmp_string;
if (len == (gsize) -1)
if (len == (gsize) - 1)
len = strlen (from);
if (*replace_flags == REPLACE_T_NO_TRANSFORM) {
if (*replace_flags == REPLACE_T_NO_TRANSFORM)
{
g_string_append_len (dest_str, from, len);
return;
}
while (loop < len) {
while (loop < len)
{
tmp_str = mc_search__get_one_symbol (NULL, from + loop, len - loop, NULL);
char_len = strlen (tmp_str);
if (*replace_flags & REPLACE_T_UPP_TRANSFORM_CHAR) {
if (*replace_flags & REPLACE_T_UPP_TRANSFORM_CHAR)
{
*replace_flags &= !REPLACE_T_UPP_TRANSFORM_CHAR;
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
g_string_append (dest_str, tmp_string->str);
g_string_free (tmp_string, TRUE);
} else if (*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR) {
}
else if (*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR)
{
*replace_flags &= !REPLACE_T_LOW_TRANSFORM_CHAR;
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
g_string_append (dest_str, tmp_string->str);
g_string_free (tmp_string, TRUE);
} else if (*replace_flags & REPLACE_T_UPP_TRANSFORM) {
}
else if (*replace_flags & REPLACE_T_UPP_TRANSFORM)
{
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
g_string_append (dest_str, tmp_string->str);
g_string_free (tmp_string, TRUE);
} else if (*replace_flags & REPLACE_T_LOW_TRANSFORM) {
}
else if (*replace_flags & REPLACE_T_LOW_TRANSFORM)
{
tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len);
g_string_append (dest_str, tmp_string->str);
g_string_free (tmp_string, TRUE);
} else {
}
else
{
g_string_append (dest_str, tmp_str);
}
g_free (tmp_str);
@ -485,7 +530,8 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
int erroffset;
#endif /* SEARCH_TYPE_GLIB */
if (!lc_mc_search->is_case_sentitive) {
if (!lc_mc_search->is_case_sentitive)
{
tmp = g_string_new_len (mc_search_cond->str->str, mc_search_cond->str->len);
g_string_free (mc_search_cond->str, TRUE);
mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp->str, tmp->len);
@ -496,7 +542,8 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
g_regex_new (mc_search_cond->str->str, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_DOTALL, 0,
&error);
if (error != NULL) {
if (error != NULL)
{
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
lc_mc_search->error_str = str_conv_gerror_message (error, _(" Regular expression error "));
g_error_free (error);
@ -505,14 +552,17 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
#else /* SEARCH_TYPE_GLIB */
mc_search_cond->regex_handle =
pcre_compile (mc_search_cond->str->str, PCRE_EXTRA, &error, &erroffset, NULL);
if (mc_search_cond->regex_handle == NULL) {
if (mc_search_cond->regex_handle == NULL)
{
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
lc_mc_search->error_str = g_strdup (error);
return;
}
lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
if (lc_mc_search->regex_match_info == NULL) {
if (error) {
if (lc_mc_search->regex_match_info == NULL)
{
if (error)
{
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
lc_mc_search->error_str = g_strdup (error);
g_free (mc_search_cond->regex_handle);
@ -540,11 +590,13 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
lc_mc_search->regex_buffer = g_string_new ("");
virtual_pos = current_pos = start_search;
while (virtual_pos <= end_search) {
while (virtual_pos <= end_search)
{
g_string_set_size (lc_mc_search->regex_buffer, 0);
lc_mc_search->start_buffer = current_pos;
while (1) {
while (1)
{
current_chr = mc_search__get_char (lc_mc_search, user_data, current_pos);
if (current_chr == MC_SEARCH_CB_ABORT)
break;
@ -566,7 +618,8 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
break;
}
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer)) {
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer))
{
case COND__FOUND_OK:
#ifdef SEARCH_TYPE_GLIB
g_match_info_fetch_pos (lc_mc_search->regex_match_info, 0, &start_pos, &end_pos);
@ -587,8 +640,8 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
return FALSE;
break;
}
if (( lc_mc_search->update_fn != NULL ) &&
( (lc_mc_search->update_fn) (user_data, current_pos) == MC_SEARCH_CB_ABORT))
if ((lc_mc_search->update_fn != NULL) &&
((lc_mc_search->update_fn) (user_data, current_pos) == MC_SEARCH_CB_ABORT))
current_chr = MC_SEARCH_CB_ABORT;
if (current_chr == MC_SEARCH_CB_ABORT)
@ -626,7 +679,8 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
return g_string_new_len (replace_str->str, replace_str->len);
if (num_replace_tokens > lc_mc_search->num_rezults - 1
|| num_replace_tokens > MC_SEARCH__NUM_REPLACE_ARGS) {
|| num_replace_tokens > MC_SEARCH__NUM_REPLACE_ARGS)
{
lc_mc_search->error = MC_SEARCH_E_REGEX_REPLACE;
lc_mc_search->error_str = g_strdup (STR_E_RPL_NOT_EQ_TO_FOUND);
return NULL;
@ -634,11 +688,14 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
ret = g_string_new ("");
prev_str = replace_str->str;
for (loop = 0; loop < replace_str->len - 1; loop++) {
for (loop = 0; loop < replace_str->len - 1; loop++)
{
lc_index = mc_search_regex__process_replace_str (replace_str, loop, &len, &replace_flags);
if (lc_index == -1) {
if (len != 0) {
if (lc_index == -1)
{
if (len != 0)
{
mc_search_regex__process_append_str (ret, prev_str,
replace_str->str - prev_str + loop,
&replace_flags);
@ -650,7 +707,8 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
continue;
}
if (lc_index == -2) {
if (lc_index == -2)
{
if (loop)
mc_search_regex__process_append_str (ret, prev_str,
replace_str->str - prev_str + loop,
@ -660,7 +718,8 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
continue;
}
if (lc_index > lc_mc_search->num_rezults) {
if (lc_index > lc_mc_search->num_rezults)
{
g_string_free (ret, TRUE);
lc_mc_search->error = MC_SEARCH_E_REGEX_REPLACE;
lc_mc_search->error_str = g_strdup_printf (STR_E_RPL_INVALID_TOKEN, lc_index);

Просмотреть файл

@ -663,6 +663,7 @@ load_mc_home_file (const char *_mc_home, const char *_mc_home_alt, const char *f
/* Fall back to the two-letter language code */
if (lang[0] && lang[1])
lang[2] = 0;
g_free (hintfile);
hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
data = load_file (hintfile);

Просмотреть файл

@ -102,27 +102,34 @@ vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino)
vfs_die ("Don't pass NULL to me");
/* ==0 can happen if freshly created entry is deleted */
if (ino->st.st_nlink <= 1){
while (ino->subdir){
if (ino->st.st_nlink <= 1)
{
while (ino->subdir)
{
vfs_s_free_entry (me, ino->subdir);
}
CALL (free_inode) (me, ino);
g_free (ino->linkname);
if (ino->localname){
if (ino->localname)
{
unlink (ino->localname);
g_free(ino->localname);
g_free (ino->localname);
}
total_inodes--;
ino->super->ino_usage--;
g_free(ino);
} else ino->st.st_nlink--;
g_free (ino);
}
else
ino->st.st_nlink--;
}
void
vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent)
{
if (ent->prevp){ /* It is possible that we are deleting freshly created entry */
if (ent->prevp)
{
/* It is possible that we are deleting freshly created entry */
*ent->prevp = ent->next;
if (ent->next)
ent->next->prevp = ent->prevp;
@ -131,14 +138,15 @@ vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent)
g_free (ent->name);
ent->name = NULL;
if (ent->ino){
if (ent->ino)
{
ent->ino->ent = NULL;
vfs_s_free_inode (me, ent->ino);
ent->ino = NULL;
}
total_entries--;
g_free(ent);
g_free (ent);
}
void
@ -183,7 +191,8 @@ vfs_s_default_stat (struct vfs_class *me, mode_t mode)
}
struct vfs_s_entry *
vfs_s_generate_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *parent, mode_t mode)
vfs_s_generate_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *parent,
mode_t mode)
{
struct vfs_s_inode *inode;
struct stat *st;
@ -214,8 +223,7 @@ vfs_s_automake (struct vfs_class *me, struct vfs_s_inode *dir, char *path, int f
/* If the entry is a symlink, find the entry for its target */
static struct vfs_s_entry *
vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry,
int follow)
vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry, int follow)
{
char *linkname;
char *fullname = NULL;
@ -235,18 +243,18 @@ vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry,
ERRNOR (EFAULT, NULL);
/* make full path from relative */
if (*linkname != PATH_SEP) {
if (*linkname != PATH_SEP)
{
char *fullpath = vfs_s_fullpath (me, entry->dir);
if (fullpath) {
if (fullpath)
{
fullname = g_strconcat (fullpath, "/", linkname, (char *) NULL);
linkname = fullname;
g_free (fullpath);
}
}
target =
(MEDATA->find_entry) (me, entry->dir->super->root, linkname,
follow - 1, 0);
target = (MEDATA->find_entry) (me, entry->dir->super->root, linkname, follow - 1, 0);
g_free (fullname);
return target;
}
@ -261,17 +269,19 @@ vfs_s_find_entry_tree (struct vfs_class *me, struct vfs_s_inode *root,
{
size_t pseg;
struct vfs_s_entry *ent = NULL;
char * const pathref = g_strdup (a_path);
char *const pathref = g_strdup (a_path);
char *path = pathref;
/* canonicalize as well, but don't remove '../' from path */
custom_canonicalize_pathname (path, CANON_PATH_ALL & (~CANON_PATH_REMDOUBLEDOTS));
while (root) {
while (root)
{
while (*path == PATH_SEP) /* Strip leading '/' */
path++;
if (!path[0]) {
if (!path[0])
{
g_free (pathref);
return ent;
}
@ -279,30 +289,26 @@ vfs_s_find_entry_tree (struct vfs_class *me, struct vfs_s_inode *root,
for (pseg = 0; path[pseg] && path[pseg] != PATH_SEP; pseg++);
for (ent = root->subdir; ent != NULL; ent = ent->next)
if (strlen (ent->name) == pseg
&& (!strncmp (ent->name, path, pseg)))
if (strlen (ent->name) == pseg && (!strncmp (ent->name, path, pseg)))
/* FOUND! */
break;
if (!ent && (flags & (FL_MKFILE | FL_MKDIR)))
ent = vfs_s_automake (me, root, path, flags);
if (!ent) {
if (!ent)
{
me->verrno = ENOENT;
goto cleanup;
}
path += pseg;
/* here we must follow leading directories always;
only the actual file is optional */
ent =
vfs_s_resolve_symlink (me, ent,
strchr (path,
PATH_SEP) ? LINK_FOLLOW :
follow);
ent = vfs_s_resolve_symlink (me, ent, strchr (path, PATH_SEP) ? LINK_FOLLOW : follow);
if (!ent)
goto cleanup;
root = ent->ino;
}
cleanup:
cleanup:
g_free (pathref);
return NULL;
}
@ -315,11 +321,14 @@ split_dir_name (struct vfs_class *me, char *path, char **dir, char **name, char
(void) me;
s = strrchr (path, PATH_SEP);
if (s == NULL) {
if (s == NULL)
{
*save = NULL;
*name = path;
*dir = path + strlen(path); /* an empty string */
} else {
*dir = path + strlen (path); /* an empty string */
}
else
{
*save = s;
*dir = path;
*s++ = '\0';
@ -332,7 +341,7 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
const char *a_path, int follow, int flags)
{
struct vfs_s_entry *ent = NULL;
char * const path = g_strdup (a_path);
char *const path = g_strdup (a_path);
struct vfs_s_entry *retval = NULL;
if (root->super->root != root)
@ -341,13 +350,12 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
/* canonicalize as well, but don't remove '../' from path */
custom_canonicalize_pathname (path, CANON_PATH_ALL & (~CANON_PATH_REMDOUBLEDOTS));
if (!(flags & FL_DIR)) {
if (!(flags & FL_DIR))
{
char *dirname, *name, *save;
struct vfs_s_inode *ino;
split_dir_name (me, path, &dirname, &name, &save);
ino =
vfs_s_find_inode (me, root->super, dirname, follow,
flags | FL_DIR);
ino = vfs_s_find_inode (me, root->super, dirname, follow, flags | FL_DIR);
if (save)
*save = PATH_SEP;
retval = vfs_s_find_entry_tree (me, ino, name, follow, flags);
@ -359,7 +367,8 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
if (!strcmp (ent->name, path))
break;
if (ent && (!(MEDATA->dir_uptodate) (me, ent->ino))) {
if (ent && (!(MEDATA->dir_uptodate) (me, ent->ino)))
{
#if 1
print_vfs_message (_("Directory cache expired for %s"), path);
#endif
@ -367,14 +376,14 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
ent = NULL;
}
if (!ent) {
if (!ent)
{
struct vfs_s_inode *ino;
ino =
vfs_s_new_inode (me, root->super,
vfs_s_default_stat (me, S_IFDIR | 0755));
ino = vfs_s_new_inode (me, root->super, vfs_s_default_stat (me, S_IFDIR | 0755));
ent = vfs_s_new_entry (me, path, ino);
if ((MEDATA->dir_load) (me, ino, path) == -1) {
if ((MEDATA->dir_load) (me, ino, path) == -1)
{
vfs_s_free_entry (me, ent);
g_free (path);
return NULL;
@ -389,7 +398,8 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
vfs_die ("find_linear: success but directory is not there\n");
#if 0
if (!vfs_s_resolve_symlink (me, ent, follow)) {
if (!vfs_s_resolve_symlink (me, ent, follow))
{
g_free (path);
return NULL;
}
@ -438,7 +448,8 @@ vfs_s_insert_super (struct vfs_class *me, struct vfs_s_super *super)
static void
vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
{
if (super->root){
if (super->root)
{
vfs_s_free_inode (me, super->root);
super->root = NULL;
}
@ -447,14 +458,14 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
/* FIXME: We currently leak small ammount of memory, sometimes. Fix it if you can. */
if (super->ino_usage)
message (D_ERROR, " Direntry warning ",
"Super ino_usage is %d, memory leak",
super->ino_usage);
"Super ino_usage is %d, memory leak", super->ino_usage);
if (super->want_stale)
message (D_ERROR, " Direntry warning ", "Super has want_stale set");
#endif
if (super->prevp){
if (super->prevp)
{
*super->prevp = super->next;
if (super->next)
super->next->prevp = super->prevp;
@ -462,7 +473,7 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
CALL (free_archive) (me, super);
g_free (super->name);
g_free(super);
g_free (super);
}
@ -471,8 +482,7 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
* can be changed and the result may point inside the original string.
*/
const char *
vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
struct vfs_s_super **archive, int flags)
vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **archive, int flags)
{
const char *retval;
char *local, *op;
@ -489,10 +499,12 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
if (!(cookie = MEDATA->archive_check (me, archive_name, op)))
return NULL;
for (super = MEDATA->supers; super != NULL; super = super->next) {
for (super = MEDATA->supers; super != NULL; super = super->next)
{
/* 0 == other, 1 == same, return it, 2 == other but stop scanning */
int i = MEDATA->archive_same (me, super, archive_name, op, cookie);
if (i != 0) {
if (i != 0)
{
if (i == 1)
goto return_success;
else
@ -505,7 +517,8 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
super = vfs_s_new_super (me);
result = MEDATA->open_archive (me, super, archive_name, op);
if (result == -1) {
if (result == -1)
{
vfs_s_free_super (me, super);
ERRNOR (EIO, NULL);
}
@ -528,8 +541,7 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
* The result should be freed.
*/
static char *
vfs_s_get_path (struct vfs_class *me, const char *inname,
struct vfs_s_super **archive, int flags)
vfs_s_get_path (struct vfs_class *me, const char *inname, struct vfs_s_super **archive, int flags)
{
char *buf, *retval;
@ -542,7 +554,8 @@ vfs_s_get_path (struct vfs_class *me, const char *inname,
void
vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super)
{
if (!super->want_stale){
if (!super->want_stale)
{
vfs_s_free_inode (me, super->root);
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
}
@ -554,11 +567,13 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
if (!ino->ent)
ERRNOR (EAGAIN, NULL);
if (!(MEDATA->flags & VFS_S_REMOTE)) {
if (!(MEDATA->flags & VFS_S_REMOTE))
{
/* archives */
char *newpath;
char *path = g_strdup (ino->ent->name);
while (1) {
while (1)
{
ino = ino->ent->dir;
if (ino == ino->super->root)
break;
@ -573,8 +588,7 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
if ((!ino->ent->dir) || (!ino->ent->dir->ent))
return g_strdup (ino->ent->name);
return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR,
ino->ent->name, (char *) NULL);
return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR, ino->ent->name, (char *) NULL);
}
/* Support of archives */
@ -592,20 +606,19 @@ vfs_s_inode_from_path (struct vfs_class *me, const char *name, int flags)
ino =
vfs_s_find_inode (me, super, q,
flags & FL_FOLLOW ? LINK_FOLLOW : LINK_NO_FOLLOW,
flags & ~FL_FOLLOW);
flags & FL_FOLLOW ? LINK_FOLLOW : LINK_NO_FOLLOW, flags & ~FL_FOLLOW);
if ((!ino) && (!*q))
/* We are asking about / directory of ftp server: assume it exists */
ino =
vfs_s_find_inode (me, super, q,
flags & FL_FOLLOW ? LINK_FOLLOW :
LINK_NO_FOLLOW,
FL_DIR | (flags & ~FL_FOLLOW));
LINK_NO_FOLLOW, FL_DIR | (flags & ~FL_FOLLOW));
g_free (q);
return ino;
}
struct dirhandle {
struct dirhandle
{
struct vfs_s_entry *cur;
struct vfs_s_inode *dir;
};
@ -635,7 +648,7 @@ vfs_s_opendir (struct vfs_class *me, const char *dirname)
}
static void *
vfs_s_readdir(void *data)
vfs_s_readdir (void *data)
{
static union vfs_dirent dir;
struct dirhandle *info = (struct dirhandle *) data;
@ -643,13 +656,16 @@ vfs_s_readdir(void *data)
if (!(info->cur))
return NULL;
if (info->cur->name) {
if (info->cur->name)
{
g_strlcpy (dir.dent.d_name, info->cur->name, MC_MAXPATHLEN);
} else {
vfs_die("Null in structure-cannot happen");
}
else
{
vfs_die ("Null in structure-cannot happen");
}
compute_namelen(&dir.dent);
compute_namelen (&dir.dent);
info->cur = info->cur->next;
return (void *) &dir;
@ -744,18 +760,21 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
if ((q = vfs_s_get_path (me, file, &super, 0)) == NULL)
return NULL;
ino = vfs_s_find_inode (me, super, q, LINK_FOLLOW, FL_NONE);
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))) {
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)))
{
g_free (q);
ERRNOR (EEXIST, NULL);
}
if (!ino) {
if (!ino)
{
char *dirname, *name, *save;
struct vfs_s_entry *ent;
struct vfs_s_inode *dir;
int tmp_handle;
/* If the filesystem is read-only, disable file creation */
if (!(flags & O_CREAT) || !(me->write)) {
if (!(flags & O_CREAT) || !(me->write))
{
g_free (q);
return NULL;
}
@ -769,7 +788,8 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
ino = ent->ino;
vfs_s_insert_entry (me, dir, ent);
tmp_handle = vfs_mkstemps (&ino->localname, me->name, name);
if (tmp_handle == -1) {
if (tmp_handle == -1)
{
g_free (q);
return NULL;
}
@ -789,20 +809,25 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
fh->changed = was_changed;
fh->linear = 0;
if (IS_LINEAR (flags)) {
if (MEDATA->linear_start) {
if (IS_LINEAR (flags))
{
if (MEDATA->linear_start)
{
print_vfs_message (_("Starting linear transfer..."));
fh->linear = LS_LINEAR_PREOPEN;
}
} else if ((MEDATA->fh_open)
&& (MEDATA->fh_open (me, fh, flags, mode))) {
}
else if ((MEDATA->fh_open) && (MEDATA->fh_open (me, fh, flags, mode)))
{
g_free (fh);
return NULL;
}
if (fh->ino->localname) {
if (fh->ino->localname)
{
fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode);
if (fh->handle == -1) {
if (fh->handle == -1)
{
g_free (fh);
ERRNOR (errno, NULL);
}
@ -821,7 +846,8 @@ vfs_s_read (void *fh, char *buffer, int count)
int n;
struct vfs_class *me = FH_SUPER->me;
if (FH->linear == LS_LINEAR_PREOPEN) {
if (FH->linear == LS_LINEAR_PREOPEN)
{
if (!MEDATA->linear_start (me, FH, FH->pos))
return -1;
}
@ -832,7 +858,8 @@ vfs_s_read (void *fh, char *buffer, int count)
if (FH->linear == LS_LINEAR_OPEN)
return MEDATA->linear_read (me, FH, buffer, count);
if (FH->handle != -1){
if (FH->handle != -1)
{
n = read (FH->handle, buffer, count);
if (n < 0)
me->verrno = errno;
@ -852,7 +879,8 @@ vfs_s_write (void *fh, const char *buffer, int count)
vfs_die ("no writing to linear files, please");
FH->changed = 1;
if (FH->handle != -1){
if (FH->handle != -1)
{
n = write (FH->handle, buffer, count);
if (n < 0)
me->verrno = errno;
@ -870,18 +898,22 @@ vfs_s_lseek (void *fh, off_t offset, int whence)
if (FH->linear == LS_LINEAR_OPEN)
vfs_die ("cannot lseek() after linear_read!");
if (FH->handle != -1){ /* If we have local file opened, we want to work with it */
if (FH->handle != -1)
{ /* If we have local file opened, we want to work with it */
int retval = lseek (FH->handle, offset, whence);
if (retval == -1)
FH->ino->super->me->verrno = errno;
return retval;
}
switch (whence){
switch (whence)
{
case SEEK_CUR:
offset += FH->pos; break;
offset += FH->pos;
break;
case SEEK_END:
offset += size; break;
offset += size;
break;
}
if (offset < 0)
FH->pos = 0;
@ -906,11 +938,13 @@ vfs_s_close (void *fh)
MEDATA->linear_close (me, fh);
if (MEDATA->fh_close)
res = MEDATA->fh_close (me, fh);
if (FH->changed && MEDATA->file_store){
if (FH->changed && MEDATA->file_store)
{
char *s = vfs_s_fullpath (me, FH->ino);
if (!s)
res = -1;
else {
else
{
res = MEDATA->file_store (me, fh, s, FH->ino->localname);
g_free (s);
}
@ -931,19 +965,17 @@ vfs_s_print_stats (const char *fs_name, const char *action,
static const char *i18n_percent_transf_format = NULL;
static const char *i18n_transf_format = NULL;
if (i18n_percent_transf_format == NULL) {
i18n_percent_transf_format =
_("%s: %s: %s %3d%% (%lu bytes transferred)");
if (i18n_percent_transf_format == NULL)
{
i18n_percent_transf_format = _("%s: %s: %s %3d%% (%lu bytes transferred)");
i18n_transf_format = _("%s: %s: %s %lu bytes transferred");
}
if (need)
print_vfs_message (i18n_percent_transf_format, fs_name, action,
file_name, (int) ((double) have * 100 / need),
(unsigned long) have);
file_name, (int) ((double) have * 100 / need), (unsigned long) have);
else
print_vfs_message (i18n_transf_format, fs_name, action, file_name,
(unsigned long) have);
print_vfs_message (i18n_transf_format, fs_name, action, file_name, (unsigned long) have);
}
int
@ -962,7 +994,8 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
fh.handle = -1;
handle = vfs_mkstemps (&ino->localname, me->name, ino->ent->name);
if (handle == -1) {
if (handle == -1)
{
me->verrno = errno;
goto error_4;
}
@ -974,20 +1007,21 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
tty_got_interrupt ();
tty_enable_interrupt_key ();
while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer)))) {
while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer))))
{
int t;
if (n < 0)
goto error_1;
total += n;
vfs_s_print_stats (me->name, _("Getting file"), ino->ent->name,
total, stat_size);
vfs_s_print_stats (me->name, _("Getting file"), ino->ent->name, total, stat_size);
if (tty_got_interrupt ())
goto error_1;
t = write (handle, buffer, n);
if (t != n) {
if (t != n)
{
if (t == -1)
me->verrno = errno;
goto error_1;
@ -1019,10 +1053,11 @@ vfs_s_fill_names (struct vfs_class *me, fill_names_f func)
struct vfs_s_super *a = MEDATA->supers;
char *name;
while (a){
name = g_strconcat ( a->name, "#", me->prefix, "/",
while (a)
{
name = g_strconcat (a->name, "#", me->prefix, "/",
/* a->current_dir->name, */ (char *) NULL);
(*func)(name);
(*func) (name);
g_free (name);
a = a->next;
}
@ -1042,14 +1077,18 @@ static char *
vfs_s_getlocalcopy (struct vfs_class *me, const char *path)
{
struct vfs_s_fh *fh;
char *local;
char *local = NULL;
fh = vfs_s_open (me, path, O_RDONLY, 0);
if (!fh || !fh->ino || !fh->ino->localname)
return NULL;
if (fh != NULL)
{
if ((fh->ino != NULL) && (fh->ino->localname != NULL))
local = g_strdup (fh->ino->localname);
vfs_s_close (fh);
}
return local;
}
@ -1058,8 +1097,7 @@ vfs_s_getlocalcopy (struct vfs_class *me, const char *path)
* the cache will be removed when the archive is closed.
*/
static int
vfs_s_ungetlocalcopy (struct vfs_class *me, const char *path,
const char *local, int has_changed)
vfs_s_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
{
(void) me;
(void) path;
@ -1071,7 +1109,8 @@ vfs_s_ungetlocalcopy (struct vfs_class *me, const char *path,
static int
vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
{
switch (ctlop) {
switch (ctlop)
{
case VFS_SETCTL_STALE_DATA:
{
struct vfs_s_inode *ino = vfs_s_inode_from_path (me, path, 0);
@ -1080,7 +1119,8 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
return 0;
if (arg)
ino->super->want_stale = 1;
else {
else
{
ino->super->want_stale = 0;
vfs_s_invalidate (me, ino->super);
}
@ -1107,7 +1147,7 @@ vfs_s_getid (struct vfs_class *me, const char *path)
if (!(p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN)))
return NULL;
g_free(p);
g_free (p);
return (vfsid) archive;
}
@ -1122,7 +1162,7 @@ vfs_s_nothingisopen (vfsid id)
static void
vfs_s_free (vfsid id)
{
vfs_s_free_super (((struct vfs_s_super *)id)->me, (struct vfs_s_super *)id);
vfs_s_free_super (((struct vfs_s_super *) id)->me, (struct vfs_s_super *) id);
}
static int
@ -1130,12 +1170,13 @@ vfs_s_dir_uptodate (struct vfs_class *me, struct vfs_s_inode *ino)
{
struct timeval tim;
if (MEDATA->flush) {
if (MEDATA->flush)
{
MEDATA->flush = 0;
return 0;
}
gettimeofday(&tim, NULL);
gettimeofday (&tim, NULL);
if (tim.tv_sec < ino->timestamp.tv_sec)
return 1;
return 0;
@ -1150,7 +1191,8 @@ vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub)
vclass->open = vfs_s_open;
vclass->close = vfs_s_close;
vclass->read = vfs_s_read;
if (!(sub->flags & VFS_S_READONLY)) {
if (!(sub->flags & VFS_S_READONLY))
{
vclass->write = vfs_s_write;
}
vclass->opendir = vfs_s_opendir;
@ -1166,11 +1208,14 @@ vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub)
vclass->getid = vfs_s_getid;
vclass->nothingisopen = vfs_s_nothingisopen;
vclass->free = vfs_s_free;
if (sub->flags & VFS_S_REMOTE) {
if (sub->flags & VFS_S_REMOTE)
{
vclass->getlocalcopy = vfs_s_getlocalcopy;
vclass->ungetlocalcopy = vfs_s_ungetlocalcopy;
sub->find_entry = vfs_s_find_entry_linear;
} else {
}
else
{
sub->find_entry = vfs_s_find_entry_tree;
}
vclass->setctl = vfs_s_setctl;
@ -1210,14 +1255,17 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter
int i;
char c;
for (i = 0; i < buf_len - 1; i++, buf++){
if (read (sock, buf, sizeof(char)) <= 0)
for (i = 0; i < buf_len - 1; i++, buf++)
{
if (read (sock, buf, sizeof (char)) <= 0)
return 0;
if (logfile){
if (logfile)
{
fwrite (buf, 1, 1, logfile);
fflush (logfile);
}
if (*buf == term){
if (*buf == term)
{
*buf = 0;
return 1;
}
@ -1225,8 +1273,10 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter
/* Line is too long - terminate buffer and discard the rest of line */
*buf = 0;
while (read (sock, &c, sizeof (c)) > 0) {
if (logfile){
while (read (sock, &c, sizeof (c)) > 0)
{
if (logfile)
{
fwrite (&c, 1, 1, logfile);
fflush (logfile);
}
@ -1245,23 +1295,27 @@ vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int
(void) me;
tty_enable_interrupt_key ();
for (i = 0; i < size-1; i++){
n = read (fd, buffer+i, 1);
for (i = 0; i < size - 1; i++)
{
n = read (fd, buffer + i, 1);
tty_disable_interrupt_key ();
if (n == -1 && errno == EINTR){
buffer [i] = 0;
if (n == -1 && errno == EINTR)
{
buffer[i] = 0;
return EINTR;
}
if (n == 0){
buffer [i] = 0;
if (n == 0)
{
buffer[i] = 0;
return 0;
}
if (buffer [i] == '\n'){
buffer [i] = 0;
if (buffer[i] == '\n')
{
buffer[i] = 0;
return 1;
}
}
buffer [size-1] = 0;
buffer[size - 1] = 0;
return 0;
}
#endif /* USE_NETCODE */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -75,13 +75,15 @@
static struct vfs_class *current_vfs;
static char *current_dir;
struct vfs_openfile {
struct vfs_openfile
{
int handle;
struct vfs_class *vclass;
void *fsinfo;
};
struct vfs_dirinfo{
struct vfs_dirinfo
{
DIR *info;
GIConv converter;
};
@ -121,11 +123,14 @@ vfs_new_handle (struct vfs_class *vclass, void *fsinfo)
/* Allocate the first free handle */
h->handle = vfs_free_handle_list;
if (h->handle == -1) {
if (h->handle == -1)
{
/* No free allocated handles, allocate one */
h->handle = vfs_openfiles->len;
g_ptr_array_add (vfs_openfiles, h);
} else {
}
else
{
vfs_free_handle_list = (long) g_ptr_array_index (vfs_openfiles, vfs_free_handle_list);
g_ptr_array_index (vfs_openfiles, h->handle) = h;
}
@ -140,12 +145,10 @@ vfs_op (int handle)
{
struct vfs_openfile *h;
if (handle < VFS_FIRST_HANDLE ||
(guint)(handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
if (handle < VFS_FIRST_HANDLE || (guint) (handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return NULL;
h = (struct vfs_openfile *) g_ptr_array_index (
vfs_openfiles, handle - VFS_FIRST_HANDLE);
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE);
if (!h)
return NULL;
@ -160,12 +163,10 @@ vfs_info (int handle)
{
struct vfs_openfile *h;
if (handle < VFS_FIRST_HANDLE ||
(guint)(handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
if (handle < VFS_FIRST_HANDLE || (guint) (handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return NULL;
h = (struct vfs_openfile *) g_ptr_array_index (
vfs_openfiles, handle - VFS_FIRST_HANDLE);
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE);
if (!h)
return NULL;
@ -178,13 +179,17 @@ vfs_info (int handle)
static void
vfs_free_handle (int handle)
{
if (handle < VFS_FIRST_HANDLE ||
(guint)(handle - VFS_FIRST_HANDLE) >= vfs_openfiles->len)
return;
const int idx = handle - VFS_FIRST_HANDLE;
g_ptr_array_index (vfs_openfiles, handle - VFS_FIRST_HANDLE) =
(void *) vfs_free_handle_list;
vfs_free_handle_list = handle - VFS_FIRST_HANDLE;
if (handle >= VFS_FIRST_HANDLE && (guint) idx < vfs_openfiles->len)
{
struct vfs_openfile *h;
h = (struct vfs_openfile *) g_ptr_array_index (vfs_openfiles, idx);
g_free (h);
g_ptr_array_index (vfs_openfiles, idx) = (void *) vfs_free_handle_list;
vfs_free_handle_list = idx;
}
}
static struct vfs_class *vfs_list;
@ -193,7 +198,7 @@ int
vfs_register_class (struct vfs_class *vfs)
{
if (vfs->init) /* vfs has own initialization function */
if (!(*vfs->init)(vfs)) /* but it failed */
if (!(*vfs->init) (vfs)) /* but it failed */
return 0;
vfs->next = vfs_list;
@ -209,14 +214,15 @@ vfs_prefix_to_class (char *prefix)
struct vfs_class *vfs;
/* Avoid last class (localfs) that would accept any prefix */
for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
if (vfs->which) {
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
{
if (vfs->which)
{
if ((*vfs->which) (vfs, prefix) == -1)
continue;
return vfs;
}
if (vfs->prefix
&& !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
if (vfs->prefix && !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
return vfs;
}
return NULL;
@ -241,15 +247,17 @@ vfs_strip_suffix_from_filename (const char *filename)
return p;
/* Avoid last class (localfs) that would accept any prefix */
for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
if (vfs->which) {
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
{
if (vfs->which)
{
if ((*vfs->which) (vfs, semi + 1) == -1)
continue;
*semi = '\0'; /* Found valid suffix */
return p;
}
if (vfs->prefix
&& !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix))) {
if (vfs->prefix && !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)))
{
*semi = '\0'; /* Found valid suffix */
return p;
}
@ -262,7 +270,7 @@ path_magic (const char *path)
{
struct stat buf;
if (!stat(path, &buf))
if (!stat (path, &buf))
return 0;
return 1;
@ -287,10 +295,10 @@ vfs_split (char *path, char **inpath, char **op)
struct vfs_class *ret;
if (!path)
vfs_die("Cannot split NULL");
vfs_die ("Cannot split NULL");
semi = strrchr (path, '#');
if (!semi || !path_magic(path))
if (!semi || !path_magic (path))
return NULL;
slash = strchr (semi, PATH_SEP);
@ -305,7 +313,8 @@ vfs_split (char *path, char **inpath, char **op)
if (slash)
*slash = 0;
if ((ret = vfs_prefix_to_class (semi+1))){
if ((ret = vfs_prefix_to_class (semi + 1)))
{
if (op)
*op = semi + 1;
if (inpath)
@ -328,7 +337,7 @@ _vfs_get_class (char *path)
char *slash;
struct vfs_class *ret;
g_return_val_if_fail(path, NULL);
g_return_val_if_fail (path, NULL);
semi = strrchr (path, '#');
if (!semi || !path_magic (path))
@ -339,7 +348,7 @@ _vfs_get_class (char *path)
if (slash)
*slash = 0;
ret = vfs_prefix_to_class (semi+1);
ret = vfs_prefix_to_class (semi + 1);
if (slash)
*slash = PATH_SEP;
@ -376,16 +385,19 @@ vfs_get_encoding (const char *path)
work = g_strdup (path);
semi = g_strrstr (work, "#enc:");
if (semi != NULL) {
semi+= 5 * sizeof (char);
if (semi != NULL)
{
semi += 5 * sizeof (char);
slash = strchr (semi, PATH_SEP);
if (slash != NULL)
slash[0] = '\0';
g_strlcpy (result, semi, sizeof(result));
g_strlcpy (result, semi, sizeof (result));
g_free (work);
return result;
} else {
}
else
{
g_free (work);
return NULL;
}
@ -394,12 +406,14 @@ vfs_get_encoding (const char *path)
/* return if encoding can by used in vfs (is ascci full compactible) */
/* contains only a few encoding now */
static int
vfs_supported_enconding (const char *encoding) {
vfs_supported_enconding (const char *encoding)
{
int t;
int result = 0;
for (t = 0; supported_encodings[t] != NULL; t++) {
result+= (g_ascii_strncasecmp (encoding, supported_encodings[t],
for (t = 0; supported_encodings[t] != NULL; t++)
{
result += (g_ascii_strncasecmp (encoding, supported_encodings[t],
strlen (supported_encodings[t])) == 0);
}
@ -415,8 +429,7 @@ vfs_supported_enconding (const char *encoding) {
* buffer - used to store result of translation
*/
static estr_t
_vfs_translate_path (const char *path, int size,
GIConv defcnv, GString *buffer)
_vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer)
{
const char *semi;
const char *ps;
@ -426,18 +439,21 @@ _vfs_translate_path (const char *path, int size,
GIConv coder;
int ms;
if (size == 0) return 0;
size = ( size > 0) ? size : (signed int)strlen (path);
if (size == 0)
return 0;
size = (size > 0) ? size : (signed int) strlen (path);
/* try found #end: */
semi = g_strrstr_len (path, size, "#enc:");
if (semi != NULL) {
if (semi != NULL)
{
/* first must be translated part before #enc: */
ms = semi - path;
/* remove '/' before #enc */
ps = str_cget_prev_char (semi);
if (ps[0] == PATH_SEP) ms = ps - path;
if (ps[0] == PATH_SEP)
ms = ps - path;
state = _vfs_translate_path (path, ms, defcnv, buffer);
@ -445,32 +461,40 @@ _vfs_translate_path (const char *path, int size,
return state;
/* now can be translated part after #enc: */
semi+= 5;
semi += 5;
slash = strchr (semi, PATH_SEP);
/* ignore slashes after size; */
if (slash - path >= size) slash = NULL;
if (slash - path >= size)
slash = NULL;
ms = (slash != NULL) ? slash - semi : (int) strlen (semi);
ms = min ((unsigned int) ms, sizeof (encoding) - 1);
/* limit encoding size (ms) to path size (size) */
if (semi + ms > path + size) ms = path + size - semi;
if (semi + ms > path + size)
ms = path + size - semi;
memcpy (encoding, semi, ms);
encoding[ms] = '\0';
switch (vfs_supported_enconding (encoding)) {
switch (vfs_supported_enconding (encoding))
{
case 1:
coder = str_crt_conv_to (encoding);
if (coder != INVALID_CONV) {
if (slash != NULL) {
state = str_vfs_convert_to (coder, slash,
path + size - slash, buffer);
} else if (buffer->str[0] == '\0') {
if (coder != INVALID_CONV)
{
if (slash != NULL)
{
state = str_vfs_convert_to (coder, slash, path + size - slash, buffer);
}
else if (buffer->str[0] == '\0')
{
/* exmaple "/#enc:utf-8" */
g_string_append_c(buffer, PATH_SEP);
g_string_append_c (buffer, PATH_SEP);
}
str_close_conv (coder);
return state;
} else {
}
else
{
errno = EINVAL;
return ESTR_FAILURE;
}
@ -479,7 +503,9 @@ _vfs_translate_path (const char *path, int size,
errno = EINVAL;
return ESTR_FAILURE;
}
} else {
}
else
{
/* path can be translated whole at once */
state = str_vfs_convert_to (defcnv, path, size, buffer);
return state;
@ -493,7 +519,7 @@ vfs_translate_path (const char *path)
{
estr_t state;
g_string_set_size(vfs_str_buffer,0);
g_string_set_size (vfs_str_buffer, 0);
state = _vfs_translate_path (path, -1, str_cnv_from_term, vfs_str_buffer);
/*
strict version
@ -528,7 +554,7 @@ vfs_canon_and_translate (const char *path)
static int
ferrno (struct vfs_class *vfs)
{
return vfs->ferrno ? (*vfs->ferrno)(vfs) : E_UNKNOWN;
return vfs->ferrno ? (*vfs->ferrno) (vfs) : E_UNKNOWN;
/* Hope that error message is obscure enough ;-) */
}
@ -540,18 +566,22 @@ mc_open (const char *filename, int flags, ...)
va_list ap;
char *file = vfs_canon_and_translate (filename);
if (file != NULL) {
if (file != NULL)
{
struct vfs_class *vfs = vfs_get_class (file);
/* Get the mode flag */
if (flags & O_CREAT) {
if (flags & O_CREAT)
{
va_start (ap, flags);
mode = va_arg (ap, int);
va_end (ap);
} else
}
else
mode = 0;
if (!vfs->open) {
if (!vfs->open)
{
g_free (file);
errno = -EOPNOTSUPP;
return -1;
@ -559,13 +589,16 @@ mc_open (const char *filename, int flags, ...)
info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
g_free (file);
if (!info){
if (!info)
{
errno = ferrno (vfs);
return -1;
}
return vfs_new_handle (vfs, info);
} else return -1;
}
else
return -1;
}
@ -591,15 +624,13 @@ int mc_##name inarg \
MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode))
MC_NAMEOP (chown, (const char *path, uid_t owner, gid_t group), (vfs, mpath, owner, group))
MC_NAMEOP (utime, (const char *path, struct utimbuf *times), (vfs, mpath, times))
MC_NAMEOP (utime, (const char *path, struct utimbuf * times), (vfs, mpath, times))
MC_NAMEOP (readlink, (const char *path, char *buf, int bufsiz), (vfs, mpath, buf, bufsiz))
MC_NAMEOP (unlink, (const char *path), (vfs, mpath))
MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vfs, mpath, mode))
MC_NAMEOP (rmdir, (const char *path), (vfs, mpath))
MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode, dev))
int
mc_symlink (const char *name1, const char *path)
int mc_symlink (const char *name1, const char *path)
{
struct vfs_class *vfs;
int result;
@ -608,12 +639,14 @@ mc_symlink (const char *name1, const char *path)
char *tmp;
mpath = vfs_canon_and_translate (path);
if (mpath != NULL) {
if (mpath != NULL)
{
tmp = g_strdup (name1);
lpath = vfs_translate_path_n (tmp);
g_free (tmp);
if (lpath != NULL) {
if (lpath != NULL)
{
vfs = vfs_get_class (mpath);
result = vfs->symlink ? (*vfs->symlink) (vfs, lpath, mpath) : -1;
g_free (lpath);
@ -644,10 +677,8 @@ ssize_t mc_##name inarg \
return result; \
}
MC_HANDLEOP(read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count))
MC_HANDLEOP(write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
MC_HANDLEOP (read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count))
MC_HANDLEOP (write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
#define MC_RENAMEOP(name) \
int mc_##name (const char *fname1, const char *fname2) \
{ \
@ -677,20 +708,16 @@ int mc_##name (const char *fname1, const char *fname2) \
} \
} else return -1; \
}
MC_RENAMEOP (link)
MC_RENAMEOP (rename)
int
mc_ctl (int handle, int ctlop, void *arg)
MC_RENAMEOP (link) MC_RENAMEOP (rename)
int
mc_ctl (int handle, int ctlop, void *arg)
{
struct vfs_class *vfs = vfs_op (handle);
if (vfs == NULL)
return 0;
return vfs->ctl ? (*vfs->ctl)(vfs_info (handle), ctlop, arg) : 0;
return vfs->ctl ? (*vfs->ctl) (vfs_info (handle), ctlop, arg) : 0;
}
int
@ -701,15 +728,18 @@ mc_setctl (const char *path, int ctlop, void *arg)
char *mpath;
if (!path)
vfs_die("You don't want to pass NULL to mc_setctl.");
vfs_die ("You don't want to pass NULL to mc_setctl.");
mpath = vfs_canon_and_translate (path);
if (mpath != NULL) {
if (mpath != NULL)
{
vfs = vfs_get_class (mpath);
result = vfs->setctl ? (*vfs->setctl)(vfs, mpath, ctlop, arg) : 0;
result = vfs->setctl ? (*vfs->setctl) (vfs, mpath, ctlop, arg) : 0;
g_free (mpath);
return result;
} else return -1;
}
else
return -1;
}
int
@ -730,7 +760,7 @@ mc_close (int handle)
if (!vfs->close)
vfs_die ("VFS must support close.\n");
result = (*vfs->close)(vfs_info (handle));
result = (*vfs->close) (vfs_info (handle));
vfs_free_handle (handle);
if (result == -1)
errno = ferrno (vfs);
@ -752,12 +782,14 @@ mc_opendir (const char *dirname)
canon = vfs_canon (dirname);
dname = vfs_translate_path_n (canon);
if (dname != NULL) {
if (dname != NULL)
{
vfs = vfs_get_class (dname);
info = vfs->opendir ? (*vfs->opendir)(vfs, dname) : NULL;
info = vfs->opendir ? (*vfs->opendir) (vfs, dname) : NULL;
g_free (dname);
if (info == NULL) {
if (info == NULL)
{
errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP;
g_free (canon);
return NULL;
@ -768,25 +800,27 @@ mc_opendir (const char *dirname)
encoding = vfs_get_encoding (canon);
g_free (canon);
dirinfo->converter = (encoding != NULL) ? str_crt_conv_from (encoding) :
str_cnv_from_term;
if (dirinfo->converter == INVALID_CONV) dirinfo->converter =str_cnv_from_term;
dirinfo->converter = (encoding != NULL) ? str_crt_conv_from (encoding) : str_cnv_from_term;
if (dirinfo->converter == INVALID_CONV)
dirinfo->converter = str_cnv_from_term;
handle = vfs_new_handle (vfs, dirinfo);
handlep = g_new (int, 1);
*handlep = handle;
return (DIR *) handlep;
} else {
}
else
{
g_free (canon);
return NULL;
}
}
static struct dirent * mc_readdir_result = NULL;
static struct dirent *mc_readdir_result = NULL;
struct dirent *
mc_readdir (DIR *dirp)
mc_readdir (DIR * dirp)
{
int handle;
struct vfs_class *vfs;
@ -806,10 +840,11 @@ mc_readdir (DIR *dirp)
* structures, holding dirent size. But we don't use it in libc infrastructure.
* TODO: to make simpler homemade dirent-alike structure.
*/
mc_readdir_result = (struct dirent *) g_malloc (sizeof(struct dirent) + MAXNAMLEN + 1);
mc_readdir_result = (struct dirent *) g_malloc (sizeof (struct dirent) + MAXNAMLEN + 1);
}
if (!dirp) {
if (!dirp)
{
errno = EFAULT;
return NULL;
}
@ -820,41 +855,48 @@ mc_readdir (DIR *dirp)
return NULL;
dirinfo = vfs_info (handle);
if (vfs->readdir) {
if (vfs->readdir)
{
entry = (*vfs->readdir) (dirinfo->info);
if (entry == NULL) return NULL;
g_string_set_size(vfs_str_buffer,0);
state = str_vfs_convert_from (dirinfo->converter,
entry->d_name, vfs_str_buffer);
if (entry == NULL)
return NULL;
g_string_set_size (vfs_str_buffer, 0);
state = str_vfs_convert_from (dirinfo->converter, entry->d_name, vfs_str_buffer);
mc_readdir_result->d_ino = entry->d_ino;
g_strlcpy (mc_readdir_result->d_name, vfs_str_buffer->str, MAXNAMLEN + 1);
}
if (entry == NULL) errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
if (entry == NULL)
errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
return (entry != NULL) ? mc_readdir_result : NULL;
}
int
mc_closedir (DIR *dirp)
mc_closedir (DIR * dirp)
{
int handle = *(int *) dirp;
struct vfs_class *vfs = vfs_op (handle);
int result;
struct vfs_class *vfs;
int result = -1;
vfs = vfs_op (handle);
if (vfs != NULL)
{
struct vfs_dirinfo *dirinfo;
if (vfs == NULL)
return -1;
dirinfo = vfs_info (handle);
if (dirinfo->converter != str_cnv_from_term) str_close_conv (dirinfo->converter);
if (dirinfo->converter != str_cnv_from_term)
str_close_conv (dirinfo->converter);
result = vfs->closedir ? (*vfs->closedir)(dirinfo->info) : -1;
result = vfs->closedir ? (*vfs->closedir) (dirinfo->info) : -1;
vfs_free_handle (handle);
g_free (dirinfo);
}
g_free (dirp);
return result;
}
int mc_stat (const char *filename, struct stat *buf) {
int
mc_stat (const char *filename, struct stat *buf)
{
struct vfs_class *vfs;
int result;
char *path;
@ -866,7 +908,8 @@ int mc_stat (const char *filename, struct stat *buf) {
vfs = vfs_get_class (path);
if (vfs == NULL) {
if (vfs == NULL)
{
g_free (path);
return -1;
}
@ -880,7 +923,9 @@ int mc_stat (const char *filename, struct stat *buf) {
return result;
}
int mc_lstat (const char *filename, struct stat *buf) {
int
mc_lstat (const char *filename, struct stat *buf)
{
struct vfs_class *vfs;
int result;
char *path;
@ -891,7 +936,8 @@ int mc_lstat (const char *filename, struct stat *buf) {
return -1;
vfs = vfs_get_class (path);
if (vfs == NULL) {
if (vfs == NULL)
{
g_free (path);
return -1;
}
@ -903,7 +949,9 @@ int mc_lstat (const char *filename, struct stat *buf) {
return result;
}
int mc_fstat (int handle, struct stat *buf) {
int
mc_fstat (int handle, struct stat *buf)
{
struct vfs_class *vfs;
int result;
@ -931,14 +979,17 @@ _vfs_get_cwd (void)
trans = vfs_translate_path_n (current_dir);
if (_vfs_get_class (trans) == NULL) {
if (_vfs_get_class (trans) == NULL)
{
const char *encoding = vfs_get_encoding (current_dir);
if (encoding == NULL) {
if (encoding == NULL)
{
char *tmp;
tmp = g_get_current_dir ();
if (tmp != NULL) { /* One of the directories in the path is not readable */
if (tmp != NULL)
{ /* One of the directories in the path is not readable */
estr_t state;
char *sys_cwd;
@ -947,16 +998,17 @@ _vfs_get_cwd (void)
g_free (tmp);
sys_cwd = (state == ESTR_SUCCESS) ? g_strdup (vfs_str_buffer->str) : NULL;
if (sys_cwd != NULL) {
if (sys_cwd != NULL)
{
struct stat my_stat, my_stat2;
/* Check if it is O.K. to use the current_dir */
if (cd_symlinks
&& mc_stat (sys_cwd, &my_stat) == 0
&& mc_stat (current_dir, &my_stat2) == 0
&& my_stat.st_ino == my_stat2.st_ino
&& my_stat.st_dev == my_stat2.st_dev)
&& my_stat.st_ino == my_stat2.st_ino && my_stat.st_dev == my_stat2.st_dev)
g_free (sys_cwd);
else {
else
{
g_free (current_dir);
current_dir = sys_cwd;
}
@ -1003,7 +1055,8 @@ vfs_get_current_dir (void)
return current_dir;
}
off_t mc_lseek (int fd, off_t offset, int whence)
off_t
mc_lseek (int fd, off_t offset, int whence)
{
struct vfs_class *vfs;
int result;
@ -1015,7 +1068,7 @@ off_t mc_lseek (int fd, off_t offset, int whence)
if (vfs == NULL)
return -1;
result = vfs->lseek ? (*vfs->lseek)(vfs_info (fd), offset, whence) : -1;
result = vfs->lseek ? (*vfs->lseek) (vfs_info (fd), offset, whence) : -1;
if (result == -1)
errno = vfs->lseek ? ferrno (vfs) : E_NOTSUPP;
return result;
@ -1031,10 +1084,11 @@ char *
vfs_canon (const char *path)
{
if (!path)
vfs_die("Cannot canonicalize NULL");
vfs_die ("Cannot canonicalize NULL");
/* Relative to current directory */
if (*path != PATH_SEP){
if (*path != PATH_SEP)
{
char *local, *result;
local = concat_dir_and_file (current_dir, path);
@ -1070,9 +1124,11 @@ mc_chdir (const char *path)
new_dir = vfs_canon (path);
trans_dir = vfs_translate_path_n (new_dir);
if (trans_dir != NULL) {
if (trans_dir != NULL)
{
new_vfs = vfs_get_class (trans_dir);
if (!new_vfs->chdir) {
if (!new_vfs->chdir)
{
g_free (new_dir);
g_free (trans_dir);
return -1;
@ -1080,7 +1136,8 @@ mc_chdir (const char *path)
result = (*new_vfs->chdir) (new_vfs, trans_dir);
if (result == -1) {
if (result == -1)
{
errno = ferrno (new_vfs);
g_free (new_dir);
g_free (trans_dir);
@ -1099,7 +1156,8 @@ mc_chdir (const char *path)
vfs_stamp_create (old_vfs, old_vfsid);
/* Sometimes we assume no trailing slash on cwd */
if (*current_dir) {
if (*current_dir)
{
char *p;
p = strchr (current_dir, 0) - 1;
if (*p == PATH_SEP && p > current_dir)
@ -1108,7 +1166,9 @@ mc_chdir (const char *path)
g_free (trans_dir);
return 0;
} else {
}
else
{
g_free (new_dir);
return -1;
}
@ -1129,11 +1189,14 @@ vfs_file_class_flags (const char *filename)
char *fname;
fname = vfs_canon_and_translate (filename);
if (fname != NULL) {
if (fname != NULL)
{
vfs = vfs_get_class (fname);
g_free (fname);
return vfs->flags;
} else return -1;
}
else
return -1;
}
static char *
@ -1153,7 +1216,8 @@ mc_def_getlocalcopy (const char *filename)
if (fdout == -1)
goto fail;
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0) {
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0)
{
if (write (fdout, buffer, i) != i)
goto fail;
}
@ -1163,12 +1227,14 @@ mc_def_getlocalcopy (const char *filename)
fdin = -1;
if (i == -1)
goto fail;
if (close (fdout) == -1) {
if (close (fdout) == -1)
{
fdout = -1;
goto fail;
}
if (mc_stat (filename, &mystat) != -1) {
if (mc_stat (filename, &mystat) != -1)
{
chmod (tmp, mystat.st_mode);
}
return tmp;
@ -1189,16 +1255,18 @@ mc_getlocalcopy (const char *pathname)
char *path;
path = vfs_canon_and_translate (pathname);
if (path != NULL) {
if (path != NULL)
{
struct vfs_class *vfs = vfs_get_class (path);
result = vfs->getlocalcopy ? (*vfs->getlocalcopy)(vfs, path) :
mc_def_getlocalcopy (path);
result = vfs->getlocalcopy ? (*vfs->getlocalcopy) (vfs, path) : mc_def_getlocalcopy (path);
g_free (path);
if (!result)
errno = ferrno (vfs);
return result;
} else return NULL;
}
else
return NULL;
}
static int
@ -1206,7 +1274,8 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
const char *local, int has_changed)
{
int fdin = -1, fdout = -1, i;
if (has_changed) {
if (has_changed)
{
char buffer[8192];
if (!vfs->write)
@ -1218,19 +1287,22 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
fdout = mc_open (filename, O_WRONLY | O_TRUNC);
if (fdout == -1)
goto failed;
while ((i = read (fdin, buffer, sizeof (buffer))) > 0) {
while ((i = read (fdin, buffer, sizeof (buffer))) > 0)
{
if (mc_write (fdout, buffer, i) != i)
goto failed;
}
if (i == -1)
goto failed;
if (close (fdin) == -1) {
if (close (fdin) == -1)
{
fdin = -1;
goto failed;
}
fdin = -1;
if (mc_close (fdout) == -1) {
if (mc_close (fdout) == -1)
{
fdout = -1;
goto failed;
}
@ -1255,15 +1327,18 @@ mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
char *path;
path = vfs_canon_and_translate (pathname);
if (path != NULL) {
if (path != NULL)
{
struct vfs_class *vfs = vfs_get_class (path);
return_value = vfs->ungetlocalcopy ?
(*vfs->ungetlocalcopy)(vfs, path, local, has_changed) :
(*vfs->ungetlocalcopy) (vfs, path, local, has_changed) :
mc_def_ungetlocalcopy (vfs, path, local, has_changed);
g_free (path);
return return_value;
} else return -1;
}
else
return -1;
}
@ -1273,9 +1348,9 @@ vfs_init (void)
/* create the VFS handle array */
vfs_openfiles = g_ptr_array_new ();
vfs_str_buffer = g_string_new("");
vfs_str_buffer = g_string_new ("");
/* localfs needs to be the first one */
init_localfs();
init_localfs ();
/* fallback value for vfs_get_class() */
localfs_class = vfs_list;
@ -1329,7 +1404,7 @@ vfs_fill_names (fill_names_f func)
{
struct vfs_class *vfs;
for (vfs=vfs_list; vfs; vfs=vfs->next)
for (vfs = vfs_list; vfs; vfs = vfs->next)
if (vfs->fill_names)
(*vfs->fill_names) (vfs, func);
}
@ -1339,16 +1414,21 @@ vfs_fill_names (fill_names_f func)
* not recognized as url, g_strdup(url) is returned.
*/
static const struct {
static const struct
{
const char *name;
size_t name_len;
const char *substitute;
} url_table[] = { {"ftp://", 6, "/#ftp:"},
{"mc://", 5, "/#mc:"},
{"smb://", 6, "/#smb:"},
{"sh://", 5, "/#sh:"},
{"ssh://", 6, "/#sh:"},
{"a:", 2, "/#a"}
} url_table[] =
{
/* *INDENT-OFF* */
{ "ftp://", 6, "/#ftp:" },
{ "mc://", 5, "/#mc:" },
{ "smb://", 6, "/#smb:" },
{ "sh://", 5, "/#sh:" },
{ "ssh://", 6, "/#sh:" },
{ "a:", 2, "/#a" }
/* *INDENT-ON* */
};
char *
@ -1356,14 +1436,16 @@ vfs_translate_url (const char *url)
{
size_t i;
for (i = 0; i < sizeof (url_table)/sizeof (url_table[0]); i++)
for (i = 0; i < sizeof (url_table) / sizeof (url_table[0]); i++)
if (strncmp (url, url_table[i].name, url_table[i].name_len) == 0)
return g_strconcat (url_table[i].substitute, url + url_table[i].name_len, (char*) NULL);
return g_strconcat (url_table[i].substitute, url + url_table[i].name_len,
(char *) NULL);
return g_strdup (url);
}
int vfs_file_is_local (const char *filename)
int
vfs_file_is_local (const char *filename)
{
return vfs_file_class_flags (filename) & VFSF_LOCAL;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1881,7 +1881,6 @@ void
edit_search_cmd (WEdit * edit, int again)
{
char *search_string = NULL, *search_string_dup = NULL;
gsize len = 0;
if (!edit)
@ -1910,36 +1909,45 @@ edit_search_cmd (WEdit * edit, int again)
{
#ifdef HAVE_CHARSET
GString *tmp;
if (search_string && *search_string)
{
tmp = str_convert_to_display (search_string);
g_free (search_string_dup);
search_string_dup = NULL;
if (tmp && tmp->len)
search_string = search_string_dup = tmp->str;
g_string_free (tmp, FALSE);
if (tmp != NULL)
{
if (tmp->len == 0)
g_string_free (tmp, TRUE);
else
{
g_free (search_string);
search_string = search_string_dup = g_string_free (tmp, FALSE);
}
}
}
#endif /* HAVE_CHARSET */
editcmd_dialog_search_show (edit, &search_string);
g_free (search_string_dup);
search_string_dup = NULL;
#ifdef HAVE_CHARSET
if (search_string && *search_string)
{
tmp = str_convert_to_input (search_string);
if (tmp && tmp->len)
search_string = tmp->str;
g_string_free (tmp, FALSE);
if (search_string_dup)
g_free (search_string_dup);
if (tmp != NULL)
{
if (tmp->len == 0)
g_string_free (tmp, TRUE);
else
{
g_free (search_string);
search_string = g_string_free (tmp, FALSE);
}
}
}
#endif /* HAVE_CHARSET */
edit_push_action (edit, KEY_PRESS + edit->start_display);
if (!search_string)
if (search_string == NULL)
{
edit->force |= REDRAW_COMPLETELY;
edit_scroll_screen_over_cursor (edit);
@ -1959,8 +1967,10 @@ edit_search_cmd (WEdit * edit, int again)
if (edit->search == NULL)
{
edit->search_start = edit->curs1;
g_free (search_string);
return;
}
edit->search->search_type = edit_search_options.type;
edit->search->is_all_charsets = edit_search_options.all_codepages;
edit->search->is_case_sentitive = edit_search_options.case_sens;
@ -1968,6 +1978,8 @@ edit_search_cmd (WEdit * edit, int again)
edit->search->search_fn = edit_search_cmd_callback;
}
g_free (search_string);
if (search_create_bookmark)
{
edit_search_cmd_search_create_bookmark (edit);

Просмотреть файл

@ -93,7 +93,7 @@ void
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
/*@out@ */ char **search_text, /*@out@ */ char **replace_text)
{
if (*search_default == '\0')
if ((search_default == NULL) || (*search_default == '\0'))
search_default = INPUT_LAST_TEXT;
{
@ -162,7 +162,7 @@ editcmd_dialog_search_show (WEdit * edit, char **search_text)
{
(void) edit;
if (*search_text == '\0')
if (*search_text == NULL)
*search_text = INPUT_LAST_TEXT;
{

Просмотреть файл

@ -151,7 +151,8 @@ static int get_fs_usage (char *path, struct fs_usage *fsp);
static struct mount_entry *mount_list = NULL;
static void free_mount_entry (struct mount_entry *me)
static void
free_mount_entry (struct mount_entry *me)
{
if (!me)
return;
@ -169,12 +170,14 @@ static void free_mount_entry (struct mount_entry *me)
No prefix (like '0x') or suffix (like 'h') is expected to be
part of CP. */
static int xatoi (const char *cp)
static int
xatoi (const char *cp)
{
int val;
val = 0;
while (*cp) {
while (*cp)
{
if (*cp >= 'a' && *cp <= 'f')
val = val * 16 + *cp - 'a' + 10;
else if (*cp >= 'A' && *cp <= 'F')
@ -192,9 +195,11 @@ static int xatoi (const char *cp)
#ifdef MOUNTED_GETMNTINFO
#ifndef HAVE_STRUCT_STATFS_F_FSTYPENAME
static char *fstype_to_string (short t)
static char *
fstype_to_string (short t)
{
switch (t) {
switch (t)
{
#ifdef MOUNT_PC
case MOUNT_PC:
return "pc";
@ -217,67 +222,67 @@ static char *fstype_to_string (short t)
#endif
#ifdef MOUNT_UFS
case MOUNT_UFS:
return "ufs" ;
return "ufs";
#endif
#ifdef MOUNT_NFS
case MOUNT_NFS:
return "nfs" ;
return "nfs";
#endif
#ifdef MOUNT_MSDOS
case MOUNT_MSDOS:
return "msdos" ;
return "msdos";
#endif
#ifdef MOUNT_LFS
case MOUNT_LFS:
return "lfs" ;
return "lfs";
#endif
#ifdef MOUNT_LOFS
case MOUNT_LOFS:
return "lofs" ;
return "lofs";
#endif
#ifdef MOUNT_FDESC
case MOUNT_FDESC:
return "fdesc" ;
return "fdesc";
#endif
#ifdef MOUNT_PORTAL
case MOUNT_PORTAL:
return "portal" ;
return "portal";
#endif
#ifdef MOUNT_NULL
case MOUNT_NULL:
return "null" ;
return "null";
#endif
#ifdef MOUNT_UMAP
case MOUNT_UMAP:
return "umap" ;
return "umap";
#endif
#ifdef MOUNT_KERNFS
case MOUNT_KERNFS:
return "kernfs" ;
return "kernfs";
#endif
#ifdef MOUNT_PROCFS
case MOUNT_PROCFS:
return "procfs" ;
return "procfs";
#endif
#ifdef MOUNT_AFS
case MOUNT_AFS:
return "afs" ;
return "afs";
#endif
#ifdef MOUNT_CD9660
case MOUNT_CD9660:
return "cd9660" ;
return "cd9660";
#endif
#ifdef MOUNT_UNION
case MOUNT_UNION:
return "union" ;
return "union";
#endif
#ifdef MOUNT_DEVFS
case MOUNT_DEVFS:
return "devfs" ;
return "devfs";
#endif
#ifdef MOUNT_EXT2FS
case MOUNT_EXT2FS:
return "ext2fs" ;
return "ext2fs";
#endif
default:
return "?";
@ -334,9 +339,9 @@ read_filesystem_list (int need_fs_type, int all_fs)
if (fp == NULL)
return NULL;
while ((mnt = getmntent (fp))) {
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
|| !strcmp (mnt->mnt_type, "auto")))
while ((mnt = getmntent (fp)))
{
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore") || !strcmp (mnt->mnt_type, "auto")))
continue;
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
@ -344,12 +349,14 @@ read_filesystem_list (int need_fs_type, int all_fs)
me->me_mountdir = strdup (mnt->mnt_dir);
me->me_type = strdup (mnt->mnt_type);
devopt = strstr (mnt->mnt_opts, "dev=");
if (devopt) {
if (devopt)
{
if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
me->me_dev = xatoi (devopt + 6);
else
me->me_dev = xatoi (devopt + 4);
} else
}
else
me->me_dev = -1; /* Magic; means not known yet. */
me->me_next = NULL;
@ -372,7 +379,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
entries = getmntinfo (&fsp, MNT_NOWAIT);
if (entries < 0)
return NULL;
while (entries-- > 0) {
while (entries-- > 0)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup (fsp->f_mntfromname);
me->me_mountdir = strdup (fsp->f_mntonname);
@ -400,12 +408,13 @@ read_filesystem_list (int need_fs_type, int all_fs)
entries = getmntinfo (&fsp, MNT_NOWAIT);
if (entries < 0)
return NULL;
for (; entries-- > 0; fsp++) {
for (; entries-- > 0; fsp++)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup (fsp->f_mntfromname);
me->me_mountdir = strdup (fsp->f_mntonname);
me->me_type = strdup (fsp->f_fstypename);
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
me->me_dev = (dev_t) - 1; /* Magic; means not known yet. */
/* Add to the linked list. */
mtail->me_next = me;
@ -420,8 +429,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
int val;
struct fs_data fsd;
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
NULL)) > 0) {
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, NULL)) > 0)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup (fsd.fd_req.devname);
me->me_mountdir = strdup (fsd.fd_req.path);
@ -451,11 +460,13 @@ read_filesystem_list (int need_fs_type, int all_fs)
stats = (struct statfs *) malloc (bufsize);
numsys = getfsstat (stats, bufsize, MNT_WAIT);
if (numsys < 0) {
if (numsys < 0)
{
free (stats);
return (NULL);
}
for (counter = 0; counter < numsys; counter++) {
for (counter = 0; counter < numsys; counter++)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup (stats[counter].f_mntfromname);
me->me_mountdir = strdup (stats[counter].f_mntonname);
@ -482,7 +493,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
if (fp == NULL)
return NULL;
while (fread (&mnt, sizeof mnt, 1, fp) > 0) {
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
#ifdef GETFSTYP /* SVR3. */
me->me_devname = strdup (mnt.mt_dev);
@ -495,7 +507,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
me->me_dev = -1; /* Magic; means not known yet. */
me->me_type = "";
#ifdef GETFSTYP /* SVR3. */
if (need_fs_type) {
if (need_fs_type)
{
struct statfs fsd;
char typebuf[FSTYPSZ];
@ -519,7 +532,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */
{
struct mntent **mnttbl = getmnttbl (), **ent;
for (ent = mnttbl; *ent; ent++) {
for (ent = mnttbl; *ent; ent++)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup ((*ent)->mt_resource);
me->me_mountdir = strdup ((*ent)->mt_directory);
@ -546,7 +560,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
if (fp == NULL)
return NULL;
while ((ret = getmntent (fp, &mnt)) == 0) {
while ((ret = getmntent (fp, &mnt)) == 0)
{
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
me->me_devname = strdup (mnt.mnt_special);
me->me_mountdir = strdup (mnt.mnt_mountp);
@ -578,11 +593,12 @@ read_filesystem_list (int need_fs_type, int all_fs)
/* Get the list of mounted filesystems. */
mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
for (thisent = entries; thisent < entries + bufsize;
thisent += vmp->vmt_length) {
for (thisent = entries; thisent < entries + bufsize; thisent += vmp->vmt_length)
{
vmp = (struct vmount *) thisent;
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
if (vmp->vmt_flags & MNT_REMOTE) {
if (vmp->vmt_flags & MNT_REMOTE)
{
char *host, *path;
/* Prepend the remote pathname. */
@ -592,9 +608,10 @@ read_filesystem_list (int need_fs_type, int all_fs)
strcpy (me->me_devname, host);
strcat (me->me_devname, ":");
strcat (me->me_devname, path);
} else {
me->me_devname = strdup (thisent +
vmp->vmt_data[VMT_OBJECT].vmt_off);
}
else
{
me->me_devname = strdup (thisent + vmp->vmt_data[VMT_OBJECT].vmt_off);
}
me->me_mountdir = strdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
me->me_type = strdup (fstype_to_string (vmp->vmt_gfstype));
@ -619,15 +636,15 @@ read_filesystem_list (int need_fs_type, int all_fs)
#ifdef HAVE_INFOMOUNT_QNX
/*
** QNX has no [gs]etmnt*(), [gs]etfs*(), or /etc/mnttab, but can do
** this via the following code.
** Note that, as this is based on CWD, it only fills one mount_entry
** structure. See my_statfs() in utilunix.c for the "other side" of
** this hack.
*/
** QNX has no [gs]etmnt*(), [gs]etfs*(), or /etc/mnttab, but can do
** this via the following code.
** Note that, as this is based on CWD, it only fills one mount_entry
** structure. See my_statfs() in utilunix.c for the "other side" of
** this hack.
*/
static struct mount_entry *
read_filesystem_list(int need_fs_type, int all_fs)
read_filesystem_list (int need_fs_type, int all_fs)
{
struct _disk_entry de;
struct statfs fs;
@ -638,49 +655,73 @@ read_filesystem_list(int need_fs_type, int all_fs)
if (me)
{
if (me->me_devname) free(me->me_devname);
if (me->me_mountdir) free(me->me_mountdir);
if (me->me_type) free(me->me_type);
if (me->me_devname)
free (me->me_devname);
if (me->me_mountdir)
free (me->me_mountdir);
if (me->me_type)
free (me->me_type);
}
else
me = (struct mount_entry *)malloc(sizeof(struct mount_entry));
me = (struct mount_entry *) malloc (sizeof (struct mount_entry));
if (!getcwd(dir, _POSIX_PATH_MAX)) return (NULL);
if (!getcwd (dir, _POSIX_PATH_MAX))
return (NULL);
if ((fd = open(dir, O_RDONLY)) == -1) return (NULL);
if ((fd = open (dir, O_RDONLY)) == -1)
return (NULL);
i = disk_get_entry(fd, &de);
i = disk_get_entry (fd, &de);
close(fd);
close (fd);
if (i == -1) return (NULL);
if (i == -1)
return (NULL);
switch (de.disk_type)
{
case _UNMOUNTED: tp = "unmounted"; break;
case _FLOPPY: tp = "Floppy"; break;
case _HARD: tp = "Hard"; break;
case _RAMDISK: tp = "Ram"; break;
case _REMOVABLE: tp = "Removable"; break;
case _TAPE: tp = "Tape"; break;
case _CDROM: tp = "CDROM"; break;
default: tp = "unknown";
case _UNMOUNTED:
tp = "unmounted";
break;
case _FLOPPY:
tp = "Floppy";
break;
case _HARD:
tp = "Hard";
break;
case _RAMDISK:
tp = "Ram";
break;
case _REMOVABLE:
tp = "Removable";
break;
case _TAPE:
tp = "Tape";
break;
case _CDROM:
tp = "CDROM";
break;
default:
tp = "unknown";
}
if (fsys_get_mount_dev(dir, &dev) == -1) return (NULL);
if (fsys_get_mount_dev (dir, &dev) == -1)
return (NULL);
if (fsys_get_mount_pt(dev, &dir) == -1) return (NULL);
if (fsys_get_mount_pt (dev, &dir) == -1)
return (NULL);
me->me_devname = strdup(dev);
me->me_mountdir = strdup(dir);
me->me_type = strdup(tp);
me->me_devname = strdup (dev);
me->me_mountdir = strdup (dir);
me->me_type = strdup (tp);
me->me_dev = de.disk_type;
#ifdef DEBUG
fprintf(stderr, "disk_get_entry():\n\tdisk_type=%d (%s)\n\tdriver_name='%-*.*s'\n\tdisk_drv=%d\n",
fprintf (stderr,
"disk_get_entry():\n\tdisk_type=%d (%s)\n\tdriver_name='%-*.*s'\n\tdisk_drv=%d\n",
de.disk_type, tp, _DRIVER_NAME_LEN, _DRIVER_NAME_LEN, de.driver_name, de.disk_drv);
fprintf(stderr, "fsys_get_mount_dev():\n\tdevice='%s'\n", dev);
fprintf(stderr, "fsys_get_mount_pt():\n\tmount point='%s'\n", dir);
fprintf (stderr, "fsys_get_mount_dev():\n\tdevice='%s'\n", dev);
fprintf (stderr, "fsys_get_mount_pt():\n\tmount point='%s'\n", dir);
#endif /* DEBUG */
return (me);
@ -688,15 +729,25 @@ read_filesystem_list(int need_fs_type, int all_fs)
#endif /* HAVE_INFOMOUNT_QNX */
void
init_my_statfs (void)
free_my_statfs (void)
{
#ifdef HAVE_INFOMOUNT_LIST
while (mount_list) {
while (mount_list)
{
struct mount_entry *next = mount_list->me_next;
free_mount_entry (mount_list);
mount_list = next;
}
mount_list = NULL;
#endif /* HAVE_INFOMOUNT_LIST */
}
void
init_my_statfs (void)
{
#ifdef HAVE_INFOMOUNT_LIST
free_my_statfs ();
mount_list = read_filesystem_list (1, 1);
#endif /* HAVE_INFOMOUNT_LIST */
}
@ -710,17 +761,20 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
struct mount_entry *temp = mount_list;
struct fs_usage fs_use;
while (temp){
while (temp)
{
i = strlen (temp->me_mountdir);
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
if (!entry || (path [i] == PATH_SEP || path [i] == 0)){
if (!entry || (path[i] == PATH_SEP || path[i] == 0))
{
len = i;
entry = temp;
}
temp = temp->me_next;
}
if (entry){
if (entry)
{
memset (&fs_use, 0, sizeof (struct fs_usage));
get_fs_usage (entry->me_mountdir, &fs_use);
@ -728,26 +782,27 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
myfs_stats->typename = entry->me_type;
myfs_stats->mpoint = entry->me_mountdir;
myfs_stats->device = entry->me_devname;
myfs_stats->avail = getuid () ? fs_use.fsu_bavail/2 : fs_use.fsu_bfree/2;
myfs_stats->total = fs_use.fsu_blocks/2;
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
myfs_stats->total = fs_use.fsu_blocks / 2;
myfs_stats->nfree = fs_use.fsu_ffree;
myfs_stats->nodes = fs_use.fsu_files;
} else
}
else
#endif /* HAVE_INFOMOUNT_LIST */
#ifdef HAVE_INFOMOUNT_QNX
/*
** This is the "other side" of the hack to read_filesystem_list() in
** mountlist.c.
** It's not the most efficient approach, but consumes less memory. It
** also accomodates QNX's ability to mount filesystems on the fly.
*/
/*
** This is the "other side" of the hack to read_filesystem_list() in
** mountlist.c.
** It's not the most efficient approach, but consumes less memory. It
** also accomodates QNX's ability to mount filesystems on the fly.
*/
struct mount_entry *entry;
struct fs_usage fs_use;
if ((entry = read_filesystem_list(0, 0)) != NULL)
if ((entry = read_filesystem_list (0, 0)) != NULL)
{
get_fs_usage(entry->me_mountdir, &fs_use);
get_fs_usage (entry->me_mountdir, &fs_use);
myfs_stats->type = entry->me_dev;
myfs_stats->typename = entry->me_type;
@ -796,7 +851,8 @@ fs_adjust_blocks (fsblkcnt_t blocks, int fromsize, int tosize)
#if defined(_AIX) && defined(_I386)
/* AIX PS/2 does not supply statfs. */
static int aix_statfs (char *path, struct statfs *fsb)
static int
aix_statfs (char *path, struct statfs *fsb)
{
struct stat stats;
struct dustat fsd;
@ -816,6 +872,7 @@ static int aix_statfs (char *path, struct statfs *fsb)
fsb->f_fsid.val[1] = fsd.du_pckno;
return 0;
}
#define statfs(path,fsb) aix_statfs(path,fsb)
#endif /* _AIX && _I386 */

Просмотреть файл

@ -23,7 +23,8 @@
#define MC_MOUNTLIST_H
/* Filesystem status */
struct my_statfs {
struct my_statfs
{
int type;
char *typename;
const char *mpoint;
@ -36,5 +37,6 @@ struct my_statfs {
void init_my_statfs (void);
void my_statfs (struct my_statfs *myfs_stats, const char *path);
void free_my_statfs (void);
#endif

Просмотреть файл

@ -3100,6 +3100,7 @@ panel_callback (Widget * w, widget_msg_t msg, int parm)
case WIDGET_DESTROY:
panel_destroy (panel);
free_my_statfs ();
return MSG_HANDLED;
default:

Просмотреть файл

@ -138,11 +138,7 @@ mcview_dialog_search (mcview_t * view)
g_free (view->last_search_string);
view->last_search_string = exp;
if (view->search_nroff_seq != NULL)
mcview_nroff_seq_free (&(view->search_nroff_seq));
if (view->search != NULL)
mcview_nroff_seq_free (&view->search_nroff_seq);
mc_search_free (view->search);
view->search = mc_search_new (view->last_search_string, -1);

Просмотреть файл

@ -191,12 +191,20 @@ mcview_done (mcview_t * view)
coord_cache_free (view->coord_cache), view->coord_cache = NULL;
if (!(view->converter == INVALID_CONV || view->converter != str_cnv_from_term))
if (view->converter == INVALID_CONV)
view->converter = str_cnv_from_term;
if (view->converter != str_cnv_from_term)
{
str_close_conv (view->converter);
view->converter = str_cnv_from_term;
}
mc_search_free (view->search);
view->search = NULL;
g_free (view->last_search_string);
view->last_search_string = NULL;
mcview_nroff_seq_free (&view->search_nroff_seq);
mcview_hexedit_free_change_list (view);
}