Ticket #2033: 2033-Unneeded-goto-in-lib-vfs-mc-vfs-extfs.c.2.patch

File 2033-Unneeded-goto-in-lib-vfs-mc-vfs-extfs.c.2.patch, 6.1 KB (added by vit_r, 14 years ago)
  • lib/vfs/mc-vfs/extfs.c

    From 3509b2581604dbfb477ecb1730b9f49cc754e14d Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Sat, 20 Mar 2010 14:04:16 +0000
    Subject: [PATCH]  getting rid of goto in lib/vfs/mc-vfs/extfs.c
    
    ---
     lib/vfs/mc-vfs/extfs.c |  141 +++++++++++++++++++++++-------------------------
     1 files changed, 67 insertions(+), 74 deletions(-)
    
    diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c
    index c567bc6..2be42b9 100644
    a b extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, g 
    10141014    struct archive *archive; 
    10151015    char *q, *mpath; 
    10161016    struct entry *entry; 
    1017     int result = -1; 
    10181017 
    10191018    mpath = g_strdup (path); 
    10201019 
    10211020    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    1022     if (q == NULL) 
    1023         goto cleanup; 
    1024     entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
     1021    if (q == NULL) { 
     1022        g_free (mpath); 
     1023        return -1; 
     1024    } 
     1025    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE);     
     1026    g_free (mpath); 
    10251027    if (entry == NULL) 
    1026         goto cleanup; 
    1027     if (resolve) 
    1028     { 
     1028        return -1; 
     1029 
     1030    if (resolve) { 
    10291031        entry = extfs_resolve_symlinks (entry); 
    10301032        if (entry == NULL) 
    1031             goto cleanup; 
     1033            return -1; 
    10321034    } 
    10331035    extfs_stat_move (buf, entry->inode); 
    1034     result = 0; 
    1035   cleanup: 
    1036     g_free (mpath); 
    1037     return result; 
     1036    return 0; 
    10381037} 
    10391038 
    10401039static int 
    extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) 
    10651064    char *q, *mpath; 
    10661065    size_t len; 
    10671066    struct entry *entry; 
    1068     int result = -1; 
    10691067 
    10701068    mpath = g_strdup (path); 
    10711069 
    10721070    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    1073     if (q == NULL) 
    1074         goto cleanup; 
     1071    if (q == NULL) { 
     1072        g_free (mpath); 
     1073        return -1; 
     1074    } 
    10751075    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
     1076    g_free (mpath); 
    10761077    if (entry == NULL) 
    1077         goto cleanup; 
    1078     if (!S_ISLNK (entry->inode->mode)) 
    1079     { 
     1078        return -1; 
     1079 
     1080    if (!S_ISLNK (entry->inode->mode)) { 
    10801081        me->verrno = EINVAL; 
    1081         goto cleanup; 
     1082        return -1; 
    10821083    } 
    10831084    len = strlen (entry->inode->linkname); 
    10841085    if (size < len) 
    10851086        len = size; 
    10861087    /* readlink() does not append a NUL character to buf */ 
    1087     result = len; 
    1088     memcpy (buf, entry->inode->linkname, result); 
    1089   cleanup: 
    1090     g_free (mpath); 
    1091     return result; 
     1088    memcpy (buf, entry->inode->linkname, len); 
     1089    return len; 
    10921090} 
    10931091 
    10941092static int 
    extfs_unlink (struct vfs_class *me, const char *file) 
    11251123    struct archive *archive; 
    11261124    char *q, *mpath; 
    11271125    struct entry *entry; 
    1128     int result = -1; 
    11291126 
    11301127    mpath = g_strdup (file); 
    11311128 
    11321129    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    1133     if (q == NULL) 
    1134         goto cleanup; 
     1130    if (q == NULL) { 
     1131        g_free (mpath); 
     1132        return -1; 
     1133    } 
    11351134    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
     1135    g_free (mpath); 
    11361136    if (entry == NULL) 
    1137         goto cleanup; 
     1137        return -1; 
     1138 
    11381139    entry = extfs_resolve_symlinks (entry); 
    11391140    if (entry == NULL) 
    1140         goto cleanup; 
    1141     if (S_ISDIR (entry->inode->mode)) 
    1142     { 
     1141        return -1; 
     1142 
     1143    if (S_ISDIR (entry->inode->mode)) { 
    11431144        me->verrno = EISDIR; 
    1144         goto cleanup; 
     1145        return -1; 
    11451146    } 
    1146     if (extfs_cmd (" rm ", archive, entry, "")) 
    1147     { 
     1147    if (extfs_cmd (" rm ", archive, entry, "")) { 
    11481148        my_errno = EIO; 
    1149         goto cleanup; 
     1149        return -1; 
    11501150    } 
    11511151    extfs_remove_entry (entry); 
    1152     result = 0; 
    1153   cleanup: 
    1154     g_free (mpath); 
    1155     return result; 
     1152    return 0; 
    11561153} 
    11571154 
    11581155static int 
    extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) 
    11611158    struct archive *archive; 
    11621159    char *q, *mpath; 
    11631160    struct entry *entry; 
    1164     int result = -1; 
    11651161 
    11661162    (void) mode; 
    11671163 
    11681164    mpath = g_strdup (path); 
    11691165 
    11701166    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    1171     if (q == NULL) 
    1172         goto cleanup; 
     1167    if (q == NULL) { 
     1168        g_free (mpath); 
     1169        return -1; 
     1170    } 
    11731171    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    1174     if (entry != NULL) 
    1175     { 
     1172    if (entry != NULL) { 
     1173        g_free (mpath); 
    11761174        me->verrno = EEXIST; 
    1177         goto cleanup; 
     1175        return -1; 
    11781176    } 
    11791177    entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE); 
     1178    g_free (mpath); 
    11801179    if (entry == NULL) 
    1181         goto cleanup; 
     1180        return -1; 
     1181 
    11821182    entry = extfs_resolve_symlinks (entry); 
    11831183    if (entry == NULL) 
    1184         goto cleanup; 
    1185     if (!S_ISDIR (entry->inode->mode)) 
    1186     { 
     1184        return -1; 
     1185 
     1186    if (!S_ISDIR (entry->inode->mode)) { 
    11871187        me->verrno = ENOTDIR; 
    1188         goto cleanup; 
     1188        return -1; 
    11891189    } 
    1190  
    1191     if (extfs_cmd (" mkdir ", archive, entry, "")) 
    1192     { 
     1190    if (extfs_cmd (" mkdir ", archive, entry, "")) { 
    11931191        my_errno = EIO; 
    11941192        extfs_remove_entry (entry); 
    1195         goto cleanup; 
     1193        return -1; 
    11961194    } 
    1197     result = 0; 
    1198   cleanup: 
    1199     g_free (mpath); 
    1200     return result; 
     1195    return 0; 
    12011196} 
    12021197 
    12031198static int 
    extfs_rmdir (struct vfs_class *me, const char *path) 
    12061201    struct archive *archive; 
    12071202    char *q, *mpath; 
    12081203    struct entry *entry; 
    1209     int result = -1; 
    12101204 
    12111205    mpath = g_strdup (path); 
    12121206 
    12131207    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    1214     if (q == NULL) 
    1215         goto cleanup; 
     1208    if (q == NULL) { 
     1209        g_free (mpath); 
     1210        return -1; 
     1211    } 
    12161212    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
     1213    g_free (mpath); 
    12171214    if (entry == NULL) 
    1218         goto cleanup; 
     1215        return -1; 
     1216 
    12191217    entry = extfs_resolve_symlinks (entry); 
    12201218    if (entry == NULL) 
    1221         goto cleanup; 
    1222     if (!S_ISDIR (entry->inode->mode)) 
    1223     { 
     1219        return -1; 
     1220 
     1221    if (!S_ISDIR (entry->inode->mode)) { 
    12241222        me->verrno = ENOTDIR; 
    1225         goto cleanup; 
     1223        return -1; 
    12261224    } 
    1227  
    1228     if (extfs_cmd (" rmdir ", archive, entry, "")) 
    1229     { 
     1225    if (extfs_cmd (" rmdir ", archive, entry, "")) { 
    12301226        my_errno = EIO; 
    1231         goto cleanup; 
     1227        return -1; 
    12321228    } 
    12331229    extfs_remove_entry (entry); 
    1234     result = 0; 
    1235   cleanup: 
    1236     g_free (mpath); 
    1237     return result; 
     1230    return 0; 
    12381231} 
    12391232 
    12401233static int