mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 12:56:51 +03:00
Merge branch '2085_deprecated_glib_functions'
* 2085_deprecated_glib_functions: g_strncasecmp() function is deprecated. g_strup() function is deprecated. g_ascii_strup() is used instead. g_strcasecmp() function is deprecated. g_strdown() function is deprecated. g_string_sprintf() is deprecated. Ticket #2085: replacement of deprecated GLib functions.
This commit is contained in:
commit
7d000ad5e5
@ -161,6 +161,7 @@ AC_CHECK_FUNCS([\
|
||||
setreuid statfs sysconf \
|
||||
tcgetattr tcsetattr truncate \
|
||||
strverscmp \
|
||||
strncasecmp \
|
||||
realpath
|
||||
])
|
||||
|
||||
|
@ -574,6 +574,24 @@ str_8bit_release_search_needle (char *needle, int case_sen)
|
||||
(void) needle;
|
||||
}
|
||||
|
||||
static char *
|
||||
str_8bit_strdown (const char *str)
|
||||
{
|
||||
char *rets;
|
||||
|
||||
rets = g_strdup (str);
|
||||
if (rets == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*rets != '\0')
|
||||
{
|
||||
*rets = char_tolower (*rets);
|
||||
rets++;
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
str_8bit_search_first (const char *text, const char *search, int case_sen)
|
||||
{
|
||||
@ -582,8 +600,8 @@ str_8bit_search_first (const char *text, const char *search, int case_sen)
|
||||
const char *match;
|
||||
size_t offsset;
|
||||
|
||||
fold_text = (case_sen) ? (char *) text : g_strdown (g_strdup (text));
|
||||
fold_search = (case_sen) ? (char *) search : g_strdown (g_strdup (search));
|
||||
fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text);
|
||||
fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search);
|
||||
|
||||
match = g_strstr_len (fold_text, -1, fold_search);
|
||||
if (match != NULL)
|
||||
@ -609,8 +627,8 @@ str_8bit_search_last (const char *text, const char *search, int case_sen)
|
||||
const char *match;
|
||||
size_t offsset;
|
||||
|
||||
fold_text = (case_sen) ? (char *) text : g_strdown (g_strdup (text));
|
||||
fold_search = (case_sen) ? (char *) search : g_strdown (g_strdup (search));
|
||||
fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text);
|
||||
fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search);
|
||||
|
||||
match = g_strrstr_len (fold_text, -1, fold_search);
|
||||
if (match != NULL)
|
||||
@ -641,15 +659,74 @@ str_8bit_ncompare (const char *t1, const char *t2)
|
||||
}
|
||||
|
||||
static int
|
||||
str_8bit_casecmp (const char *t1, const char *t2)
|
||||
str_8bit_casecmp (const char *s1, const char *s2)
|
||||
{
|
||||
return g_strcasecmp (t1, t2);
|
||||
/* code from GLib */
|
||||
|
||||
#ifdef HAVE_STRCASECMP
|
||||
g_return_val_if_fail (s1 != NULL, 0);
|
||||
g_return_val_if_fail (s2 != NULL, 0);
|
||||
|
||||
return strcasecmp (s1, s2);
|
||||
#else
|
||||
gint c1, c2;
|
||||
|
||||
g_return_val_if_fail (s1 != NULL, 0);
|
||||
g_return_val_if_fail (s2 != NULL, 0);
|
||||
|
||||
while (*s1 != '\0' && *s2 != '\0')
|
||||
{
|
||||
/* According to A. Cox, some platforms have islower's that
|
||||
* don't work right on non-uppercase
|
||||
*/
|
||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
str_8bit_ncasecmp (const char *t1, const char *t2)
|
||||
str_8bit_ncasecmp (const char *s1, const char *s2)
|
||||
{
|
||||
return g_strncasecmp (t1, t2, min (strlen (t1), strlen (t2)));
|
||||
size_t n;
|
||||
|
||||
g_return_val_if_fail (s1 != NULL, 0);
|
||||
g_return_val_if_fail (s2 != NULL, 0);
|
||||
|
||||
n = min (strlen (s1), strlen (s2));
|
||||
|
||||
/* code from GLib */
|
||||
|
||||
#ifdef HAVE_STRNCASECMP
|
||||
return strncasecmp (s1, s2, n);
|
||||
#else
|
||||
gint c1, c2;
|
||||
|
||||
while (n != 0 && *s1 != '\0' && *s2 != '\0')
|
||||
{
|
||||
n -= 1;
|
||||
/* According to A. Cox, some platforms have islower's that
|
||||
* don't work right on non-uppercase
|
||||
*/
|
||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
if (n != 0)
|
||||
return (((gint) (guchar) *s1) - ((gint) (guchar) *s2));
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
@ -681,7 +758,7 @@ str_8bit_fix_string (char *text)
|
||||
static char *
|
||||
str_8bit_create_key (const char *text, int case_sen)
|
||||
{
|
||||
return (case_sen) ? (char *) text : g_strdown (g_strdup (text));
|
||||
return (case_sen) ? (char *) text : str_8bit_strdown (text);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -535,8 +535,12 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
|
||||
|
||||
if (ftpfs_get_reply (me, SUP.sock, reply_string, sizeof (reply_string) - 1) == COMPLETE)
|
||||
{
|
||||
g_strup (reply_string);
|
||||
SUP.remote_is_amiga = strstr (reply_string, "AMIGA") != 0;
|
||||
char *reply_up;
|
||||
|
||||
reply_up = g_ascii_strup (reply_string, -1);
|
||||
SUP.remote_is_amiga = strstr (reply_up, "AMIGA") != 0;
|
||||
g_free (reply_up);
|
||||
|
||||
if (MEDATA->logfile)
|
||||
{
|
||||
fprintf (MEDATA->logfile, "MC -- remote_is_amiga = %d\n", SUP.remote_is_amiga);
|
||||
@ -682,7 +686,7 @@ ftpfs_check_proxy (const char *host)
|
||||
if (!ld)
|
||||
return 0;
|
||||
}
|
||||
else if (!g_strcasecmp (host, domain))
|
||||
else if (g_ascii_strcasecmp (host, domain) == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2153,7 +2157,7 @@ ftpfs_find_machine (const char *host, const char *domain)
|
||||
if (ftpfs_netrc_next () == NETRC_NONE)
|
||||
break;
|
||||
|
||||
if (g_strcasecmp (host, buffer))
|
||||
if (g_ascii_strcasecmp (host, buffer) != 0)
|
||||
{
|
||||
/* Try adding our domain to short names in .netrc */
|
||||
const char *host_domain = strchr (host, '.');
|
||||
@ -2161,11 +2165,11 @@ ftpfs_find_machine (const char *host, const char *domain)
|
||||
continue;
|
||||
|
||||
/* Compare domain part */
|
||||
if (g_strcasecmp (host_domain, domain))
|
||||
if (g_ascii_strcasecmp (host_domain, domain) != 0)
|
||||
continue;
|
||||
|
||||
/* Compare local part */
|
||||
if (g_strncasecmp (host, buffer, host_domain - host))
|
||||
if (g_ascii_strncasecmp (host, buffer, host_domain - host) != 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -330,14 +330,16 @@ edit_load_file_fast (WEdit * edit, const char *filename)
|
||||
|
||||
edit->curs2 = edit->last_byte;
|
||||
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
|
||||
edit->utf8 = 0;
|
||||
|
||||
file = mc_open (filename, O_RDONLY | O_BINARY);
|
||||
if (file == -1)
|
||||
{
|
||||
GString *errmsg = g_string_new (NULL);
|
||||
g_string_sprintf (errmsg, _("Cannot open %s for reading"), filename);
|
||||
edit_error_dialog (_("Error"), get_sys_error (errmsg->str));
|
||||
g_string_free (errmsg, TRUE);
|
||||
gchar *errmsg;
|
||||
|
||||
errmsg = g_strdup_printf (_("Cannot open %s for reading"), filename);
|
||||
edit_error_dialog (_("Error"), errmsg);
|
||||
g_free (errmsg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -627,7 +629,7 @@ static int
|
||||
check_file_access (WEdit * edit, const char *filename, struct stat *st)
|
||||
{
|
||||
int file;
|
||||
GString *errmsg = (GString *) 0;
|
||||
gchar *errmsg = NULL;
|
||||
|
||||
/* Try opening an existing file */
|
||||
file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
|
||||
@ -635,14 +637,13 @@ check_file_access (WEdit * edit, const char *filename, struct stat *st)
|
||||
if (file < 0)
|
||||
{
|
||||
/*
|
||||
* Try creating the file. O_EXCL prevents following broken links
|
||||
* Try creating the file. O_EXCL prevents following broken links
|
||||
* and opening existing files.
|
||||
*/
|
||||
file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
|
||||
if (file < 0)
|
||||
{
|
||||
g_string_sprintf (errmsg = g_string_new (NULL),
|
||||
_("Cannot open %s for reading"), filename);
|
||||
errmsg = g_strdup_printf (_("Cannot open %s for reading"), filename);
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
@ -655,15 +656,14 @@ check_file_access (WEdit * edit, const char *filename, struct stat *st)
|
||||
/* Check what we have opened */
|
||||
if (mc_fstat (file, st) < 0)
|
||||
{
|
||||
g_string_sprintf (errmsg = g_string_new (NULL),
|
||||
_("Cannot get size/permissions for %s"), filename);
|
||||
errmsg = g_strdup_printf (_("Cannot get size/permissions for %s"), filename);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* We want to open regular files only */
|
||||
if (!S_ISREG (st->st_mode))
|
||||
{
|
||||
g_string_sprintf (errmsg = g_string_new (NULL), _("\"%s\" is not a regular file"), filename);
|
||||
errmsg = g_strdup_printf (_("\"%s\" is not a regular file"), filename);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -672,21 +672,18 @@ check_file_access (WEdit * edit, const char *filename, struct stat *st)
|
||||
* O_EXCL should prevent it, but let's be on the safe side.
|
||||
*/
|
||||
if (st->st_size > 0)
|
||||
{
|
||||
edit->delete_file = 0;
|
||||
}
|
||||
|
||||
if (st->st_size >= SIZE_LIMIT)
|
||||
{
|
||||
g_string_sprintf (errmsg = g_string_new (NULL), _("File \"%s\" is too large"), filename);
|
||||
}
|
||||
errmsg = g_strdup_printf (_("File \"%s\" is too large"), filename);
|
||||
|
||||
cleanup:
|
||||
(void) mc_close (file);
|
||||
if (errmsg)
|
||||
|
||||
if (errmsg != NULL)
|
||||
{
|
||||
edit_error_dialog (_("Error"), errmsg->str);
|
||||
g_string_free (errmsg, TRUE);
|
||||
edit_error_dialog (_("Error"), errmsg);
|
||||
g_free (errmsg);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -134,7 +134,7 @@ mc_defines_destroy (gpointer key, gpointer value, gpointer data)
|
||||
static void
|
||||
destroy_defines (GTree ** defines)
|
||||
{
|
||||
g_tree_traverse (*defines, mc_defines_destroy, G_POST_ORDER, NULL);
|
||||
g_tree_foreach (*defines, mc_defines_destroy, NULL);
|
||||
g_tree_destroy (*defines);
|
||||
*defines = NULL;
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
while (*profile_keys != NULL)
|
||||
{
|
||||
/* copy=other causes all keys from [terminal:other] to be loaded. */
|
||||
if (g_strcasecmp (*profile_keys, "copy") == 0)
|
||||
if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
|
||||
{
|
||||
valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
|
||||
load_keys_from_section (valcopy, cfg);
|
||||
@ -647,7 +647,7 @@ setup__load_panel_state (const char *section)
|
||||
buffer = mc_config_get_string (mc_panels_config, section, "display", "listing");
|
||||
|
||||
for (i = 0; panel_types[i].opt_name != NULL; i++)
|
||||
if (g_strcasecmp (panel_types[i].opt_name, buffer) == 0)
|
||||
if (g_ascii_strcasecmp (panel_types[i].opt_name, buffer) == 0)
|
||||
{
|
||||
mode = panel_types[i].opt_type;
|
||||
break;
|
||||
@ -1123,7 +1123,7 @@ panel_load_setup (WPanel * panel, const char *section)
|
||||
buffer = mc_config_get_string (mc_panels_config, section, "list_mode", "full");
|
||||
panel->list_type = list_full;
|
||||
for (i = 0; list_types[i].key != NULL; i++)
|
||||
if (g_strcasecmp (list_types[i].key, buffer) == 0)
|
||||
if (g_ascii_strcasecmp (list_types[i].key, buffer) == 0)
|
||||
{
|
||||
panel->list_type = list_types[i].list_type;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user