From f5049d3a4cb2efecff125d13d98b370673196373 Mon Sep 17 00:00:00 2001
From: Vit Rosin <vit_r@list.ru>
Date: Wed, 17 Feb 2010 13:38:26 +0000
Subject: [PATCH] Unneeded goto in lib/vfs/mc-vfs/extfs.c
---
lib/vfs/mc-vfs/extfs.c | 98 +++++++++++++++++++++++++----------------------
1 files changed, 52 insertions(+), 46 deletions(-)
diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c
index a8f086c..5cca9ef 100644
a
|
b
|
extfs_stat_move (struct stat *buf, const struct inode *inode) |
959 | 959 | buf->st_ctime = inode->ctime; |
960 | 960 | } |
961 | 961 | |
| 962 | |
| 963 | static int |
| 964 | free_mpath (char **mpath, const int retval) |
| 965 | { |
| 966 | g_free (*mpath); |
| 967 | *mpath = NULL; |
| 968 | return retval; |
| 969 | } |
| 970 | |
962 | 971 | static int |
963 | 972 | extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, |
964 | 973 | gboolean resolve) |
… |
… |
extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, |
966 | 975 | struct archive *archive; |
967 | 976 | char *q, *mpath; |
968 | 977 | struct entry *entry; |
969 | | int result = -1; |
970 | 978 | |
971 | 979 | mpath = g_strdup (path); |
| 980 | if (mpath == NULL) |
| 981 | return (-1); |
972 | 982 | |
973 | 983 | q = extfs_get_path_mangle (me, mpath, &archive, FALSE); |
974 | 984 | if (q == NULL) |
975 | | goto cleanup; |
| 985 | return free_mpath (&mpath, (-1)); |
976 | 986 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
977 | 987 | if (entry == NULL) |
978 | | goto cleanup; |
| 988 | return free_mpath (&mpath, (-1)); |
979 | 989 | if (resolve) { |
980 | 990 | entry = extfs_resolve_symlinks (entry); |
981 | 991 | if (entry == NULL) |
982 | | goto cleanup; |
| 992 | return free_mpath (&mpath, (-1)); |
983 | 993 | } |
984 | 994 | extfs_stat_move (buf, entry->inode); |
985 | | result = 0; |
986 | | cleanup: |
987 | | g_free (mpath); |
988 | | return result; |
| 995 | return free_mpath (&mpath, 0); |
989 | 996 | } |
990 | 997 | |
991 | 998 | static int |
… |
… |
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) |
1019 | 1026 | int result = -1; |
1020 | 1027 | |
1021 | 1028 | mpath = g_strdup (path); |
| 1029 | if (mpath == NULL) |
| 1030 | return (-1); |
1022 | 1031 | |
1023 | 1032 | q = extfs_get_path_mangle (me, mpath, &archive, FALSE); |
1024 | 1033 | if (q == NULL) |
1025 | | goto cleanup; |
| 1034 | return free_mpath (&mpath, result); |
1026 | 1035 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
1027 | 1036 | if (entry == NULL) |
1028 | | goto cleanup; |
| 1037 | return free_mpath (&mpath, result); |
1029 | 1038 | if (!S_ISLNK (entry->inode->mode)) { |
1030 | 1039 | me->verrno = EINVAL; |
1031 | | goto cleanup; |
| 1040 | return free_mpath (&mpath, result); |
1032 | 1041 | } |
1033 | 1042 | len = strlen (entry->inode->linkname); |
1034 | 1043 | if (size < len) |
… |
… |
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) |
1036 | 1045 | /* readlink() does not append a NUL character to buf */ |
1037 | 1046 | result = len; |
1038 | 1047 | memcpy (buf, entry->inode->linkname, result); |
1039 | | cleanup: |
1040 | | g_free (mpath); |
1041 | | return result; |
| 1048 | return free_mpath (&mpath, result); |
1042 | 1049 | } |
1043 | 1050 | |
1044 | 1051 | static int |
… |
… |
extfs_unlink (struct vfs_class *me, const char *file) |
1075 | 1082 | struct archive *archive; |
1076 | 1083 | char *q, *mpath; |
1077 | 1084 | struct entry *entry; |
1078 | | int result = -1; |
1079 | 1085 | |
1080 | 1086 | mpath = g_strdup (file); |
| 1087 | if (mpath == NULL) |
| 1088 | return (-1); |
1081 | 1089 | |
1082 | 1090 | q = extfs_get_path_mangle (me, mpath, &archive, FALSE); |
1083 | 1091 | if (q == NULL) |
1084 | | goto cleanup; |
| 1092 | return free_mpath (&mpath, (-1)); |
1085 | 1093 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
1086 | 1094 | if (entry == NULL) |
1087 | | goto cleanup; |
| 1095 | return free_mpath (&mpath, (-1)); |
1088 | 1096 | entry = extfs_resolve_symlinks (entry); |
1089 | 1097 | if (entry == NULL) |
1090 | | goto cleanup; |
| 1098 | return free_mpath (&mpath, (-1)); |
1091 | 1099 | if (S_ISDIR (entry->inode->mode)) { |
1092 | 1100 | me->verrno = EISDIR; |
1093 | | goto cleanup; |
| 1101 | return free_mpath (&mpath, (-1)); |
1094 | 1102 | } |
1095 | 1103 | if (extfs_cmd (" rm ", archive, entry, "")) { |
1096 | 1104 | my_errno = EIO; |
1097 | | goto cleanup; |
| 1105 | return free_mpath (&mpath, (-1)); |
1098 | 1106 | } |
1099 | 1107 | extfs_remove_entry (entry); |
1100 | | result = 0; |
1101 | | cleanup: |
1102 | | g_free (mpath); |
1103 | | return result; |
| 1108 | return free_mpath (&mpath, 0); |
1104 | 1109 | } |
1105 | 1110 | |
1106 | 1111 | static int |
… |
… |
extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) |
1109 | 1114 | struct archive *archive; |
1110 | 1115 | char *q, *mpath; |
1111 | 1116 | struct entry *entry; |
1112 | | int result = -1; |
1113 | 1117 | |
1114 | 1118 | (void) mode; |
1115 | 1119 | |
1116 | 1120 | mpath = g_strdup (path); |
| 1121 | if (mpath == NULL) |
| 1122 | return (-1); |
1117 | 1123 | |
1118 | 1124 | q = extfs_get_path_mangle (me, mpath, &archive, FALSE); |
1119 | 1125 | if (q == NULL) |
1120 | | goto cleanup; |
| 1126 | return free_mpath (&mpath, (-1)); |
| 1127 | |
1121 | 1128 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
1122 | 1129 | if (entry != NULL) { |
1123 | 1130 | me->verrno = EEXIST; |
1124 | | goto cleanup; |
| 1131 | return free_mpath (&mpath, (-1)); |
1125 | 1132 | } |
1126 | 1133 | entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE); |
1127 | 1134 | if (entry == NULL) |
1128 | | goto cleanup; |
| 1135 | return free_mpath (&mpath, (-1)); |
| 1136 | |
1129 | 1137 | entry = extfs_resolve_symlinks (entry); |
1130 | 1138 | if (entry == NULL) |
1131 | | goto cleanup; |
| 1139 | return free_mpath (&mpath, (-1)); |
| 1140 | |
1132 | 1141 | if (!S_ISDIR (entry->inode->mode)) { |
1133 | 1142 | me->verrno = ENOTDIR; |
1134 | | goto cleanup; |
| 1143 | return free_mpath (&mpath, (-1)); |
1135 | 1144 | } |
1136 | 1145 | |
1137 | 1146 | if (extfs_cmd (" mkdir ", archive, entry, "")) { |
1138 | 1147 | my_errno = EIO; |
1139 | 1148 | extfs_remove_entry (entry); |
1140 | | goto cleanup; |
| 1149 | return free_mpath (&mpath, (-1)); |
1141 | 1150 | } |
1142 | | result = 0; |
1143 | | cleanup: |
1144 | | g_free (mpath); |
1145 | | return result; |
| 1151 | return free_mpath (&mpath, 0); |
1146 | 1152 | } |
1147 | 1153 | |
1148 | 1154 | static int |
… |
… |
extfs_rmdir (struct vfs_class *me, const char *path) |
1151 | 1157 | struct archive *archive; |
1152 | 1158 | char *q, *mpath; |
1153 | 1159 | struct entry *entry; |
1154 | | int result = -1; |
1155 | 1160 | |
1156 | 1161 | mpath = g_strdup (path); |
| 1162 | if (mpath == NULL) |
| 1163 | return (-1); |
1157 | 1164 | |
1158 | 1165 | q = extfs_get_path_mangle (me, mpath, &archive, FALSE); |
1159 | 1166 | if (q == NULL) |
1160 | | goto cleanup; |
| 1167 | return free_mpath (&mpath, (-1)); |
| 1168 | |
1161 | 1169 | entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); |
1162 | 1170 | if (entry == NULL) |
1163 | | goto cleanup; |
| 1171 | return free_mpath (&mpath, (-1)); |
| 1172 | |
1164 | 1173 | entry = extfs_resolve_symlinks (entry); |
1165 | 1174 | if (entry == NULL) |
1166 | | goto cleanup; |
| 1175 | return free_mpath (&mpath, (-1)); |
| 1176 | |
1167 | 1177 | if (!S_ISDIR (entry->inode->mode)) { |
1168 | 1178 | me->verrno = ENOTDIR; |
1169 | | goto cleanup; |
| 1179 | return free_mpath (&mpath, (-1)); |
1170 | 1180 | } |
1171 | | |
1172 | 1181 | if (extfs_cmd (" rmdir ", archive, entry, "")) { |
1173 | 1182 | my_errno = EIO; |
1174 | | goto cleanup; |
| 1183 | return free_mpath (&mpath, (-1)); |
1175 | 1184 | } |
1176 | 1185 | extfs_remove_entry (entry); |
1177 | | result = 0; |
1178 | | cleanup: |
1179 | | g_free (mpath); |
1180 | | return result; |
| 1186 | return free_mpath (&mpath, 0); |
1181 | 1187 | } |
1182 | 1188 | |
1183 | 1189 | static int |