… | |
… | |
52 | #include <uudeview.h> |
52 | #include <uudeview.h> |
53 | #include <uuint.h> |
53 | #include <uuint.h> |
54 | #include <fptools.h> |
54 | #include <fptools.h> |
55 | #include <uustring.h> |
55 | #include <uustring.h> |
56 | |
56 | |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.2 2001/06/11 20:42:37 root Exp $"; |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.3 2002/02/10 22:47:18 root Exp $"; |
58 | |
58 | |
59 | /* for braindead systems */ |
59 | /* for braindead systems */ |
60 | #ifndef SEEK_SET |
60 | #ifndef SEEK_SET |
61 | #ifdef L_BEGIN |
61 | #ifdef L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
… | |
… | |
1137 | FILE *datain, *dataout; |
1137 | FILE *datain, *dataout; |
1138 | unsigned char r[8]; |
1138 | unsigned char r[8]; |
1139 | char *mode, *ntmp; |
1139 | char *mode, *ntmp; |
1140 | uufile *iter; |
1140 | uufile *iter; |
1141 | size_t bytes; |
1141 | size_t bytes; |
|
|
1142 | #ifdef HAVE_MKSTEMP |
|
|
1143 | int tmpfd; |
|
|
1144 | const char *tmpprefix = "uuXXXXXX"; |
|
|
1145 | char *tmpdir = NULL; |
|
|
1146 | #endif /* HAVE_MKSTEMP */ |
1142 | |
1147 | |
1143 | if (data == NULL || data->thisfile == NULL) |
1148 | if (data == NULL || data->thisfile == NULL) |
1144 | return UURET_ILLVAL; |
1149 | return UURET_ILLVAL; |
1145 | |
1150 | |
1146 | if (data->state & UUFILE_TMPFILE) |
1151 | if (data->state & UUFILE_TMPFILE) |
… | |
… | |
1155 | if (data->uudet == PT_ENCODED) |
1160 | if (data->uudet == PT_ENCODED) |
1156 | mode = "wt"; /* open text files in text mode */ |
1161 | mode = "wt"; /* open text files in text mode */ |
1157 | else |
1162 | else |
1158 | mode = "wb"; /* otherwise in binary */ |
1163 | mode = "wb"; /* otherwise in binary */ |
1159 | |
1164 | |
|
|
1165 | #ifdef HAVE_MKSTEMP |
|
|
1166 | if ((getuid()==geteuid()) && (getgid()==getegid())) { |
|
|
1167 | tmpdir=getenv("TMPDIR"); |
|
|
1168 | } |
|
|
1169 | |
|
|
1170 | if (!tmpdir) { |
|
|
1171 | tmpdir = "/tmp"; |
|
|
1172 | } |
|
|
1173 | data->binfile = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); |
|
|
1174 | |
|
|
1175 | if (!data->binfile) { |
|
|
1176 | #else |
1160 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
1177 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
|
|
1178 | #endif /* HAVE_MKSTEMP */ |
1161 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1179 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1162 | uustring (S_NO_TEMP_NAME)); |
1180 | uustring (S_NO_TEMP_NAME)); |
1163 | return UURET_NOMEM; |
1181 | return UURET_NOMEM; |
1164 | } |
1182 | } |
1165 | |
1183 | |
|
|
1184 | #ifdef HAVE_MKSTEMP |
|
|
1185 | strcpy(data->binfile, tmpdir); |
|
|
1186 | strcat(data->binfile, "/"); |
|
|
1187 | strcat(data->binfile, tmpprefix); |
|
|
1188 | |
|
|
1189 | if ((tmpfd = mkstemp(data->binfile)) == -1 || |
|
|
1190 | (dataout = fdopen(tmpfd, mode)) == NULL) { |
|
|
1191 | #else |
1166 | if ((dataout = fopen (data->binfile, mode)) == NULL) { |
1192 | if ((dataout = fopen (data->binfile, mode)) == NULL) { |
|
|
1193 | #endif /* HAVE_MKSTEMP */ |
1167 | /* |
1194 | /* |
1168 | * we couldn't create a temporary file. Usually this means that TMP |
1195 | * we couldn't create a temporary file. Usually this means that TMP |
1169 | * and TEMP aren't set |
1196 | * and TEMP aren't set |
1170 | */ |
1197 | */ |
1171 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1198 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1172 | uustring (S_WR_ERR_TARGET), |
1199 | uustring (S_WR_ERR_TARGET), |
1173 | data->binfile, strerror (uu_errno = errno)); |
1200 | data->binfile, strerror (uu_errno = errno)); |
|
|
1201 | #ifdef HAVE_MKSTEMP |
|
|
1202 | if (tmpfd != -1) { |
|
|
1203 | unlink(data->binfile); |
|
|
1204 | close(tmpfd); |
|
|
1205 | } |
|
|
1206 | #endif /* HAVE_MKSTEMP */ |
1174 | FP_free (data->binfile); |
1207 | FP_free (data->binfile); |
1175 | data->binfile = NULL; |
1208 | data->binfile = NULL; |
1176 | uu_errno = errno; |
1209 | uu_errno = errno; |
1177 | return UURET_IOERR; |
1210 | return UURET_IOERR; |
1178 | } |
1211 | } |
|
|
1212 | |
1179 | /* |
1213 | /* |
1180 | * we don't have begin lines in Base64 or plain text files. |
1214 | * we don't have begin lines in Base64 or plain text files. |
1181 | */ |
1215 | */ |
1182 | if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || |
1216 | if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || |
1183 | data->uudet == PT_ENCODED) |
1217 | data->uudet == PT_ENCODED) |
… | |
… | |
1317 | /* |
1351 | /* |
1318 | * If this was a BinHex file, we must extract its data or resource fork |
1352 | * If this was a BinHex file, we must extract its data or resource fork |
1319 | */ |
1353 | */ |
1320 | |
1354 | |
1321 | if (data->uudet == BH_ENCODED && data->binfile) { |
1355 | if (data->uudet == BH_ENCODED && data->binfile) { |
|
|
1356 | #ifdef HAVE_MKSTEMP |
|
|
1357 | ntmp = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); |
|
|
1358 | |
|
|
1359 | if (ntmp == NULL) { |
|
|
1360 | #else |
1322 | if ((ntmp = tempnam (NULL, "uu")) == NULL) { |
1361 | if ((ntmp = tempnam (NULL, "uu")) == NULL) { |
|
|
1362 | #endif /* HAVE_MKSTEMP */ |
1323 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1363 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1324 | uustring (S_NO_TEMP_NAME)); |
1364 | uustring (S_NO_TEMP_NAME)); |
1325 | progress.action = 0; |
1365 | progress.action = 0; |
1326 | return UURET_NOMEM; |
1366 | return UURET_NOMEM; |
1327 | } |
1367 | } |
… | |
… | |
1331 | data->binfile, strerror (uu_errno = errno)); |
1371 | data->binfile, strerror (uu_errno = errno)); |
1332 | progress.action = 0; |
1372 | progress.action = 0; |
1333 | free (ntmp); |
1373 | free (ntmp); |
1334 | return UURET_IOERR; |
1374 | return UURET_IOERR; |
1335 | } |
1375 | } |
|
|
1376 | #ifdef HAVE_MKSTEMP |
|
|
1377 | strcpy(ntmp, tmpdir); |
|
|
1378 | strcat(ntmp, "/"); |
|
|
1379 | strcat(ntmp, tmpprefix); |
|
|
1380 | if ((tmpfd = mkstemp(ntmp)) == -1 || |
|
|
1381 | (dataout = fdopen(tmpfd, "wb")) == NULL) { |
|
|
1382 | #else |
1336 | if ((dataout = fopen (ntmp, "wb")) == NULL) { |
1383 | if ((dataout = fopen (ntmp, "wb")) == NULL) { |
|
|
1384 | #endif /* HAVE_MKSTEMP */ |
1337 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1385 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1338 | uustring (S_NOT_OPEN_TARGET), |
1386 | uustring (S_NOT_OPEN_TARGET), |
1339 | ntmp, strerror (uu_errno = errno)); |
1387 | ntmp, strerror (uu_errno = errno)); |
1340 | progress.action = 0; |
1388 | progress.action = 0; |
1341 | fclose (datain); |
1389 | fclose (datain); |
|
|
1390 | #ifdef HAVE_MKSTEMP |
|
|
1391 | if (tmpfd != -1) { |
|
|
1392 | unlink(ntmp); |
|
|
1393 | close(tmpfd); |
|
|
1394 | } |
|
|
1395 | #endif /* HAVE_MKSTEMP */ |
1342 | free (ntmp); |
1396 | free (ntmp); |
1343 | return UURET_IOERR; |
1397 | return UURET_IOERR; |
1344 | } |
1398 | } |
|
|
1399 | |
1345 | /* |
1400 | /* |
1346 | * read fork lengths. remember they're in Motorola format |
1401 | * read fork lengths. remember they're in Motorola format |
1347 | */ |
1402 | */ |
1348 | r[0] = fgetc (datain); |
1403 | r[0] = fgetc (datain); |
1349 | hb = (int) r[0] + 22; |
1404 | hb = (int) r[0] + 22; |