Ticket #3269: mc-3269-use-meaningful-errno-or-0.patch

File mc-3269-use-meaningful-errno-or-0.patch, 11.2 KB (added by and, 9 years ago)
  • lib/event/event.c

    From 585d598d8ebfabd4831cca9967d47804a0f885df Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sun, 3 Jan 2016 11:13:02 +0000
    Subject: [PATCH] fix #3269 use meaningful errno or 0
    
    use real errno or set it to 0
    when no meaningful error code exists
    for current user error message
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/event/event.c           |  6 +++---
     lib/event/manage.c          |  6 +++---
     lib/serialize.c             | 12 ++++++------
     lib/vfs/path.c              |  6 +++---
     src/filemanager/ext.c       |  6 +++---
     src/vfs/sftpfs/connection.c | 14 +++++++-------
     src/vfs/sftpfs/file.c       |  2 +-
     7 files changed, 26 insertions(+), 26 deletions(-)
    
    diff --git a/lib/event/event.c b/lib/event/event.c
    index 426dd30..4f4b830 100644
    a b mc_event_init (GError ** mcerror) 
    5454 
    5555    if (mc_event_grouplist != NULL) 
    5656    { 
    57         mc_propagate_error (mcerror, 1, "%s", _("Event system already initialized")); 
     57        mc_propagate_error (mcerror, 0, "%s", _("Event system already initialized")); 
    5858        return FALSE; 
    5959    } 
    6060 
    mc_event_init (GError ** mcerror) 
    6464 
    6565    if (mc_event_grouplist == NULL) 
    6666    { 
    67         mc_propagate_error (mcerror, 2, "%s", _("Failed to initialize event system")); 
     67        mc_propagate_error (mcerror, 0, "%s", _("Failed to initialize event system")); 
    6868        return FALSE; 
    6969    } 
    7070 
    mc_event_deinit (GError ** mcerror) 
    8080 
    8181    if (mc_event_grouplist == NULL) 
    8282    { 
    83         mc_propagate_error (mcerror, 3, "%s", _("Event system not initialized")); 
     83        mc_propagate_error (mcerror, 0, "%s", _("Event system not initialized")); 
    8484        return FALSE; 
    8585    } 
    8686 
  • lib/event/manage.c

    diff --git a/lib/event/manage.c b/lib/event/manage.c
    index 9d216b8..118a16e 100644
    a b mc_event_add (const gchar * event_group_name, const gchar * event_name, 
    7474    if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL 
    7575        || event_callback == NULL) 
    7676    { 
    77         mc_propagate_error (mcerror, 1, "%s", _("Check input data! Some of parameters are NULL!")); 
     77        mc_propagate_error (mcerror, 0, "%s", _("Check input data! Some of parameters are NULL!")); 
    7878        return FALSE; 
    7979    } 
    8080 
    mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean creat 
    172172                             (GDestroyNotify) mc_event_group_destroy_value); 
    173173        if (event_group == NULL) 
    174174        { 
    175             mc_propagate_error (mcerror, 1, _("Unable to create group '%s' for events!"), 
     175            mc_propagate_error (mcerror, 0, _("Unable to create group '%s' for events!"), 
    176176                                event_group_name); 
    177177            return NULL; 
    178178        } 
    mc_event_get_event_by_name (GTree * event_group, const gchar * event_name, gbool 
    197197        callbacks = g_ptr_array_new (); 
    198198        if (callbacks == NULL) 
    199199        { 
    200             mc_propagate_error (mcerror, 1, _("Unable to create event '%s'!"), event_name); 
     200            mc_propagate_error (mcerror, 0, _("Unable to create event '%s'!"), event_name); 
    201201            return NULL; 
    202202        } 
    203203        g_tree_insert (event_group, g_strdup (event_name), (gpointer) callbacks); 
  • lib/serialize.c

    diff --git a/lib/serialize.c b/lib/serialize.c
    index 96b946f..27909eb 100644
    a b mc_serialize_str (const char prefix, const char *data, GError ** error) 
    110110{ 
    111111    if (data == NULL) 
    112112    { 
    113         g_set_error (error, MC_ERROR, -1, "mc_serialize_str(): Input data is NULL."); 
     113        g_set_error (error, MC_ERROR, 0, "mc_serialize_str(): Input data is NULL."); 
    114114        return NULL; 
    115115    } 
    116116    return g_strdup_printf ("%c%zd" SRLZ_DELIM_S "%s", prefix, strlen (data), data); 
    mc_deserialize_str (const char prefix, const char *data, GError ** error) 
    135135 
    136136    if ((data == NULL) || (strlen (data) == 0)) 
    137137    { 
    138         g_set_error (error, MC_ERROR, -1, FUNC_NAME ": Input data is NULL or empty."); 
     138        g_set_error (error, MC_ERROR, 0, FUNC_NAME ": Input data is NULL or empty."); 
    139139        return NULL; 
    140140    } 
    141141 
    142142    if (*data != prefix) 
    143143    { 
    144         g_set_error (error, MC_ERROR, -2, FUNC_NAME ": String prefix doesn't equal to '%c'", 
     144        g_set_error (error, MC_ERROR, 0, FUNC_NAME ": String prefix doesn't equal to '%c'", 
    145145                     prefix); 
    146146        return NULL; 
    147147    } 
    mc_deserialize_str (const char prefix, const char *data, GError ** error) 
    154154        semi_ptr = strchr (data + 1, SRLZ_DELIM_C); 
    155155        if (semi_ptr == NULL) 
    156156        { 
    157             g_set_error (error, MC_ERROR, -3, 
     157            g_set_error (error, MC_ERROR, 0, 
    158158                         FUNC_NAME ": Length delimiter '%c' doesn't exists", SRLZ_DELIM_C); 
    159159            return NULL; 
    160160        } 
    161161        semi_offset = semi_ptr - (data + 1); 
    162162        if (semi_offset >= BUF_TINY) 
    163163        { 
    164             g_set_error (error, MC_ERROR, -3, FUNC_NAME ": Too big string length"); 
     164            g_set_error (error, MC_ERROR, 0, FUNC_NAME ": Too big string length"); 
    165165            return NULL; 
    166166        } 
    167167        strncpy (buffer, data + 1, semi_offset); 
    mc_deserialize_str (const char prefix, const char *data, GError ** error) 
    172172 
    173173    if (data_len > strlen (data)) 
    174174    { 
    175         g_set_error (error, MC_ERROR, -3, 
     175        g_set_error (error, MC_ERROR, 0, 
    176176                     FUNC_NAME 
    177177                     ": Specified data length (%zd) is greater than actual data length (%zd)", 
    178178                     data_len, strlen (data)); 
  • lib/vfs/path.c

    diff --git a/lib/vfs/path.c b/lib/vfs/path.c
    index 5f64850..7c90eb0 100644
    a b vfs_path_serialize (const vfs_path_t * vpath, GError ** mcerror) 
    10941094 
    10951095    if ((vpath == NULL) || (vfs_path_elements_count (vpath) == 0)) 
    10961096    { 
    1097         mc_propagate_error (mcerror, -1, "%s", "vpath object is empty"); 
     1097        mc_propagate_error (mcerror, 0, "%s", "vpath object is empty"); 
    10981098        return NULL; 
    10991099 
    11001100    } 
    vfs_path_deserialize (const char *data, GError ** mcerror) 
    11771177        { 
    11781178            g_free (element); 
    11791179            vfs_path_free (vpath); 
    1180             g_set_error (mcerror, MC_ERROR, -1, "Unable to find VFS class by name '%s'", cfg_value); 
     1180            g_set_error (mcerror, MC_ERROR, 0, "Unable to find VFS class by name '%s'", cfg_value); 
    11811181            g_free (cfg_value); 
    11821182            mc_config_deinit (cpath); 
    11831183            return NULL; 
    vfs_path_deserialize (const char *data, GError ** mcerror) 
    12091209    if (vfs_path_elements_count (vpath) == 0) 
    12101210    { 
    12111211        vfs_path_free (vpath); 
    1212         g_set_error (mcerror, MC_ERROR, -1, "No any path elements found"); 
     1212        g_set_error (mcerror, MC_ERROR, 0, "No any path elements found"); 
    12131213        return NULL; 
    12141214    } 
    12151215    vpath->str = vfs_path_to_str_flags (vpath, 0, VPF_NONE); 
  • src/filemanager/ext.c

    diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c
    index 44bc387..f7466c8 100644
    a b regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c 
    648648        localfile_vpath = mc_getlocalcopy (filename_vpath); 
    649649        if (localfile_vpath == NULL) 
    650650        { 
    651             mc_propagate_error (mcerror, -1, _("Cannot fetch a local copy of %s"), 
     651            mc_propagate_error (mcerror, 0, _("Cannot fetch a local copy of %s"), 
    652652                                vfs_path_as_str (filename_vpath)); 
    653653            return FALSE; 
    654654        } 
    regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c 
    715715 
    716716    if (got_data == -1) 
    717717    { 
    718         mc_propagate_error (mcerror, -1, "%s", _("Pipe failed")); 
     718        mc_propagate_error (mcerror, 0, "%s", _("Pipe failed")); 
    719719        return FALSE; 
    720720    } 
    721721 
    regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c 
    733733        } 
    734734        else 
    735735        { 
    736             mc_propagate_error (mcerror, -1, "%s", _("Regular expression error")); 
     736            mc_propagate_error (mcerror, 0, "%s", _("Regular expression error")); 
    737737        } 
    738738    } 
    739739 
  • src/vfs/sftpfs/connection.c

    diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c
    index fceb961..f573346 100644
    a b sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror) 
    7575 
    7676    if (super->path_element->host == NULL || *super->path_element->host == '\0') 
    7777    { 
    78         mc_propagate_error (mcerror, -1, "%s", _("sftp: Invalid host name.")); 
     78        mc_propagate_error (mcerror, 0, "%s", _("sftp: Invalid host name.")); 
    7979        return -1; 
    8080    } 
    8181 
    sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror) 
    107107 
    108108    if (e != 0) 
    109109    { 
    110         mc_propagate_error (mcerror, -1, _("sftp: %s"), gai_strerror (e)); 
     110        mc_propagate_error (mcerror, 0, _("sftp: %s"), gai_strerror (e)); 
    111111        my_socket = -1; 
    112112        goto ret; 
    113113    } 
    sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror) 
    134134        close (my_socket); 
    135135 
    136136        if (errno == EINTR && tty_got_interrupt ()) 
    137             mc_propagate_error (mcerror, -1, "%s", _("sftp: connection interrupted by user")); 
     137            mc_propagate_error (mcerror, 0, "%s", _("sftp: connection interrupted by user")); 
    138138        else if (res->ai_next == NULL) 
    139             mc_propagate_error (mcerror, -1, _("sftp: connection to server failed: %s"), 
     139            mc_propagate_error (mcerror, 0, _("sftp: connection to server failed: %s"), 
    140140                                unix_error_string (errno)); 
    141141        else 
    142142            continue; 
    sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** mcerror) 
    276276    g_free (p); 
    277277 
    278278    if (passwd == NULL) 
    279         mc_propagate_error (mcerror, -1, "%s", _("sftp: Passphrase is empty.")); 
     279        mc_propagate_error (mcerror, 0, "%s", _("sftp: Passphrase is empty.")); 
    280280    else 
    281281    { 
    282282        ret_value = (libssh2_userauth_publickey_fromfile (super_data->session, 
    sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** mcerro 
    327327    g_free (p); 
    328328 
    329329    if (passwd == NULL) 
    330         mc_propagate_error (mcerror, -1, "%s", _("sftp: Password is empty.")); 
     330        mc_propagate_error (mcerror, 0, "%s", _("sftp: Password is empty.")); 
    331331    else 
    332332    { 
    333333        while ((rc = libssh2_userauth_password (super_data->session, super->path_element->user, 
    sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) 
    387387    rc = libssh2_session_startup (super_data->session, super_data->socket_handle); 
    388388    if (rc != 0) 
    389389    { 
    390         mc_propagate_error (mcerror, -1, _("sftp: Failure establishing SSH session: (%d)"), rc); 
     390        mc_propagate_error (mcerror, 0, _("sftp: Failure establishing SSH session: (%d)"), rc); 
    391391        return (-1); 
    392392    } 
    393393 
  • src/vfs/sftpfs/file.c

    diff --git a/src/vfs/sftpfs/file.c b/src/vfs/sftpfs/file.c
    index 1af0a44..d95de9b 100644
    a b sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, 
    248248 
    249249    if (file_handler == NULL || file_handler->data == NULL) 
    250250    { 
    251         mc_propagate_error (mcerror, -1, "%s", 
     251        mc_propagate_error (mcerror, 0, "%s", 
    252252                            _("sftp: No file handler data present for reading file")); 
    253253        return -1; 
    254254    }