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 |
1014 | 1014 | struct archive *archive; |
1015 | 1015 | char *q, *mpath; |
1016 | 1016 | struct entry *entry; |
1017 | | int result = -1; |
1018 | 1017 | |
1019 | 1018 | mpath = g_strdup (path); |
1020 | 1019 | |
1021 | 1020 | 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); |
1025 | 1027 | if (entry == NULL) |
1026 | | goto cleanup; |
1027 | | if (resolve) |
1028 | | { |
| 1028 | return -1; |
| 1029 | |
| 1030 | if (resolve) { |
1029 | 1031 | entry = extfs_resolve_symlinks (entry); |
1030 | 1032 | if (entry == NULL) |
1031 | | goto cleanup; |
| 1033 | return -1; |
1032 | 1034 | } |
1033 | 1035 | extfs_stat_move (buf, entry->inode); |
1034 | | result = 0; |
1035 | | cleanup: |
1036 | | g_free (mpath); |
1037 | | return result; |
| 1036 | return 0; |
1038 | 1037 | } |
1039 | 1038 | |
1040 | 1039 | static int |
… |
… |
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) |
1065 | 1064 | char *q, *mpath; |
1066 | 1065 | size_t len; |
1067 | 1066 | struct entry *entry; |
1068 | | int result = -1; |
1069 | 1067 | |
1070 | 1068 | mpath = g_strdup (path); |
1071 | 1069 | |
1072 | 1070 | 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 | } |
1075 | 1075 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
| 1076 | g_free (mpath); |
1076 | 1077 | 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)) { |
1080 | 1081 | me->verrno = EINVAL; |
1081 | | goto cleanup; |
| 1082 | return -1; |
1082 | 1083 | } |
1083 | 1084 | len = strlen (entry->inode->linkname); |
1084 | 1085 | if (size < len) |
1085 | 1086 | len = size; |
1086 | 1087 | /* 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; |
1092 | 1090 | } |
1093 | 1091 | |
1094 | 1092 | static int |
… |
… |
extfs_unlink (struct vfs_class *me, const char *file) |
1125 | 1123 | struct archive *archive; |
1126 | 1124 | char *q, *mpath; |
1127 | 1125 | struct entry *entry; |
1128 | | int result = -1; |
1129 | 1126 | |
1130 | 1127 | mpath = g_strdup (file); |
1131 | 1128 | |
1132 | 1129 | 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 | } |
1135 | 1134 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
| 1135 | g_free (mpath); |
1136 | 1136 | if (entry == NULL) |
1137 | | goto cleanup; |
| 1137 | return -1; |
| 1138 | |
1138 | 1139 | entry = extfs_resolve_symlinks (entry); |
1139 | 1140 | 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)) { |
1143 | 1144 | me->verrno = EISDIR; |
1144 | | goto cleanup; |
| 1145 | return -1; |
1145 | 1146 | } |
1146 | | if (extfs_cmd (" rm ", archive, entry, "")) |
1147 | | { |
| 1147 | if (extfs_cmd (" rm ", archive, entry, "")) { |
1148 | 1148 | my_errno = EIO; |
1149 | | goto cleanup; |
| 1149 | return -1; |
1150 | 1150 | } |
1151 | 1151 | extfs_remove_entry (entry); |
1152 | | result = 0; |
1153 | | cleanup: |
1154 | | g_free (mpath); |
1155 | | return result; |
| 1152 | return 0; |
1156 | 1153 | } |
1157 | 1154 | |
1158 | 1155 | static int |
… |
… |
extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) |
1161 | 1158 | struct archive *archive; |
1162 | 1159 | char *q, *mpath; |
1163 | 1160 | struct entry *entry; |
1164 | | int result = -1; |
1165 | 1161 | |
1166 | 1162 | (void) mode; |
1167 | 1163 | |
1168 | 1164 | mpath = g_strdup (path); |
1169 | 1165 | |
1170 | 1166 | 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 | } |
1173 | 1171 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
1174 | | if (entry != NULL) |
1175 | | { |
| 1172 | if (entry != NULL) { |
| 1173 | g_free (mpath); |
1176 | 1174 | me->verrno = EEXIST; |
1177 | | goto cleanup; |
| 1175 | return -1; |
1178 | 1176 | } |
1179 | 1177 | entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE); |
| 1178 | g_free (mpath); |
1180 | 1179 | if (entry == NULL) |
1181 | | goto cleanup; |
| 1180 | return -1; |
| 1181 | |
1182 | 1182 | entry = extfs_resolve_symlinks (entry); |
1183 | 1183 | 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)) { |
1187 | 1187 | me->verrno = ENOTDIR; |
1188 | | goto cleanup; |
| 1188 | return -1; |
1189 | 1189 | } |
1190 | | |
1191 | | if (extfs_cmd (" mkdir ", archive, entry, "")) |
1192 | | { |
| 1190 | if (extfs_cmd (" mkdir ", archive, entry, "")) { |
1193 | 1191 | my_errno = EIO; |
1194 | 1192 | extfs_remove_entry (entry); |
1195 | | goto cleanup; |
| 1193 | return -1; |
1196 | 1194 | } |
1197 | | result = 0; |
1198 | | cleanup: |
1199 | | g_free (mpath); |
1200 | | return result; |
| 1195 | return 0; |
1201 | 1196 | } |
1202 | 1197 | |
1203 | 1198 | static int |
… |
… |
extfs_rmdir (struct vfs_class *me, const char *path) |
1206 | 1201 | struct archive *archive; |
1207 | 1202 | char *q, *mpath; |
1208 | 1203 | struct entry *entry; |
1209 | | int result = -1; |
1210 | 1204 | |
1211 | 1205 | mpath = g_strdup (path); |
1212 | 1206 | |
1213 | 1207 | 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 | } |
1216 | 1212 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
| 1213 | g_free (mpath); |
1217 | 1214 | if (entry == NULL) |
1218 | | goto cleanup; |
| 1215 | return -1; |
| 1216 | |
1219 | 1217 | entry = extfs_resolve_symlinks (entry); |
1220 | 1218 | 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)) { |
1224 | 1222 | me->verrno = ENOTDIR; |
1225 | | goto cleanup; |
| 1223 | return -1; |
1226 | 1224 | } |
1227 | | |
1228 | | if (extfs_cmd (" rmdir ", archive, entry, "")) |
1229 | | { |
| 1225 | if (extfs_cmd (" rmdir ", archive, entry, "")) { |
1230 | 1226 | my_errno = EIO; |
1231 | | goto cleanup; |
| 1227 | return -1; |
1232 | 1228 | } |
1233 | 1229 | extfs_remove_entry (entry); |
1234 | | result = 0; |
1235 | | cleanup: |
1236 | | g_free (mpath); |
1237 | | return result; |
| 1230 | return 0; |
1238 | 1231 | } |
1239 | 1232 | |
1240 | 1233 | static int |