aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c18
-rw-r--r--archival/bbunzip.c2
-rw-r--r--archival/dpkg.c29
-rw-r--r--archival/libarchive/decompress_gunzip.c6
-rw-r--r--archival/libarchive/open_transformer.c21
-rw-r--r--archival/libarchive/unsafe_symlink_target.c7
-rw-r--r--archival/rpm.c12
-rw-r--r--archival/tar.c45
-rw-r--r--archival/unzip.c10
9 files changed, 143 insertions, 7 deletions
diff --git a/archival/ar.c b/archival/ar.c
index f4edeb087..66930f0b8 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -163,6 +163,9 @@ static int write_ar_archive(archive_handle_t *handle)
163{ 163{
164 struct stat st; 164 struct stat st;
165 archive_handle_t *out_handle; 165 archive_handle_t *out_handle;
166#if ENABLE_PLATFORM_MINGW32
167 char *temp_fn = NULL;
168#endif
166 169
167 xfstat(handle->src_fd, &st, handle->ar__name); 170 xfstat(handle->src_fd, &st, handle->ar__name);
168 171
@@ -171,8 +174,14 @@ static int write_ar_archive(archive_handle_t *handle)
171 */ 174 */
172 if (st.st_size != 0) { 175 if (st.st_size != 0) {
173 out_handle = init_handle(); 176 out_handle = init_handle();
177#if !ENABLE_PLATFORM_MINGW32
174 xunlink(handle->ar__name); 178 xunlink(handle->ar__name);
175 out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); 179 out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC);
180#else
181 /* can't unlink open file, create temporary output file */
182 temp_fn = xasprintf("%sXXXXXX", handle->ar__name);
183 out_handle->src_fd = xmkstemp(temp_fn);
184#endif
176 out_handle->accept = handle->accept; 185 out_handle->accept = handle->accept;
177 } else { 186 } else {
178 out_handle = handle; 187 out_handle = handle;
@@ -194,12 +203,19 @@ static int write_ar_archive(archive_handle_t *handle)
194 continue; 203 continue;
195 204
196 /* optional, since we exit right after we return */ 205 /* optional, since we exit right after we return */
197 if (ENABLE_FEATURE_CLEAN_UP) { 206 if (ENABLE_FEATURE_CLEAN_UP || ENABLE_PLATFORM_MINGW32) {
198 close(handle->src_fd); 207 close(handle->src_fd);
199 if (out_handle->src_fd != handle->src_fd) 208 if (out_handle->src_fd != handle->src_fd)
200 close(out_handle->src_fd); 209 close(out_handle->src_fd);
201 } 210 }
202 211
212#if ENABLE_PLATFORM_MINGW32
213 if ( temp_fn != NULL ) {
214 xrename(temp_fn, handle->ar__name);
215 free(temp_fn);
216 }
217#endif
218
203 return EXIT_SUCCESS; 219 return EXIT_SUCCESS;
204} 220}
205#endif /* FEATURE_AR_CREATE */ 221#endif /* FEATURE_AR_CREATE */
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 93f30d324..bf99656e2 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -178,6 +178,8 @@ int FAST_FUNC bbunpack(char **argv,
178 if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */ 178 if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
179 del = NULL; 179 del = NULL;
180 } 180 }
181 if (ENABLE_PLATFORM_MINGW32)
182 xclose(STDIN_FILENO);
181 if (del) 183 if (del)
182 xunlink(del); 184 xunlink(del);
183 free_name: 185 free_name:
diff --git a/archival/dpkg.c b/archival/dpkg.c
index ddb5daf09..08f15ad44 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -149,6 +149,11 @@ enum edge_type_e {
149 EDGE_RECOMMENDS = 13, 149 EDGE_RECOMMENDS = 13,
150 EDGE_ENHANCES = 15 150 EDGE_ENHANCES = 15
151}; 151};
152#if ENABLE_PLATFORM_MINGW32
153#undef VER_EQUAL
154#undef VER_LESS
155#undef VER_LESS_EQUAL
156#endif
152enum operator_e { 157enum operator_e {
153 VER_NULL = 0, 158 VER_NULL = 0,
154 VER_EQUAL = 1, 159 VER_EQUAL = 1,
@@ -1747,6 +1752,10 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
1747 int state_status; 1752 int state_status;
1748 int status_num; 1753 int status_num;
1749 int i; 1754 int i;
1755#if ENABLE_PLATFORM_MINGW32
1756 char **ptr, *path;
1757 int fd;
1758#endif
1750#if ENABLE_LONG_OPTS 1759#if ENABLE_LONG_OPTS
1751 static const char dpkg_longopts[] ALIGN1 = 1760 static const char dpkg_longopts[] ALIGN1 =
1752// FIXME: we use -C non-compatibly, should be: 1761// FIXME: we use -C non-compatibly, should be:
@@ -1791,6 +1800,26 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
1791 bb_show_usage(); 1800 bb_show_usage();
1792 } 1801 }
1793 1802
1803#if ENABLE_PLATFORM_MINGW32
1804 if (opt & OPT_install) {
1805 /* add system drive prefix to filenames, if necessary */
1806 for (ptr = argv; *ptr; ++ptr) {
1807 *ptr = xabsolute_path(*ptr);
1808 }
1809 }
1810
1811 chdir_system_drive();
1812
1813 /* initialise data store */
1814 path = xstrdup("/var/lib/dpkg/info");
1815 bb_make_directory(path, -1, FILEUTILS_RECUR);
1816 free(path);
1817
1818 fd = open("/var/lib/dpkg/status", O_RDWR|O_CREAT, 0666);
1819 if (fd >= 0)
1820 xclose(fd);
1821#endif
1822
1794/* puts("(Reading database ... xxxxx files and directories installed.)"); */ 1823/* puts("(Reading database ... xxxxx files and directories installed.)"); */
1795 index_status_file("/var/lib/dpkg/status"); 1824 index_status_file("/var/lib/dpkg/status");
1796 1825
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 7f9046b82..32fcb6b51 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -1123,6 +1123,9 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
1123 return res; 1123 return res;
1124} 1124}
1125 1125
1126#if ENABLE_PLATFORM_MINGW32 && __GNUC__
1127#pragma pack(2)
1128#endif
1126static int check_header_gzip(STATE_PARAM transformer_state_t *xstate) 1129static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
1127{ 1130{
1128 union { 1131 union {
@@ -1194,6 +1197,9 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
1194 } 1197 }
1195 return 1; 1198 return 1;
1196} 1199}
1200#if ENABLE_PLATFORM_MINGW32 && __GNUC__
1201#pragma pack()
1202#endif
1197 1203
1198IF_DESKTOP(long long) int FAST_FUNC 1204IF_DESKTOP(long long) int FAST_FUNC
1199unpack_gz_stream(transformer_state_t *xstate) 1205unpack_gz_stream(transformer_state_t *xstate)
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index a90f42a45..3a0fc4712 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -64,6 +64,7 @@ ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *bu
64 return nwrote; 64 return nwrote;
65} 65}
66 66
67#if !ENABLE_PLATFORM_MINGW32
67void check_errors_in_children(int signo) 68void check_errors_in_children(int signo)
68{ 69{
69 int status; 70 int status;
@@ -150,6 +151,26 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
150 close(fd_pipe.wr); /* don't want to write to the child */ 151 close(fd_pipe.wr); /* don't want to write to the child */
151 xmove_fd(fd_pipe.rd, fd); 152 xmove_fd(fd_pipe.rd, fd);
152} 153}
154#else /* ENABLE_PLATFORM_MINGW */
155void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
156{
157 char *cmd;
158 int fd1;
159
160 if (find_applet_by_name(transform_prog) >= 0) {
161 cmd = xasprintf("%s --busybox %s -cf -", bb_busybox_exec_path,
162 transform_prog);
163 }
164 else {
165 cmd = xasprintf("%s -cf -", transform_prog);
166 }
167 if ( (fd1=mingw_popen_fd(cmd, "r", fd, NULL)) == -1 ) {
168 bb_perror_msg_and_die("can't execute '%s'", transform_prog);
169 }
170 free(cmd);
171 xmove_fd(fd1, fd);
172}
173#endif
153 174
154 175
155#if SEAMLESS_COMPRESSION 176#if SEAMLESS_COMPRESSION
diff --git a/archival/libarchive/unsafe_symlink_target.c b/archival/libarchive/unsafe_symlink_target.c
index f8dc8033d..ff96991f5 100644
--- a/archival/libarchive/unsafe_symlink_target.c
+++ b/archival/libarchive/unsafe_symlink_target.c
@@ -10,6 +10,7 @@ void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
10 const char *linkname, 10 const char *linkname,
11 int hard_link) 11 int hard_link)
12{ 12{
13#if !ENABLE_PLATFORM_MINGW32
13 if (hard_link || target[0] == '/' || strstr(target, "..")) { 14 if (hard_link || target[0] == '/' || strstr(target, "..")) {
14 llist_add_to_end(link_placeholders, 15 llist_add_to_end(link_placeholders,
15 xasprintf("%c%s%c%s", hard_link, linkname, '\0', target) 16 xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
@@ -22,8 +23,13 @@ void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
22 "sym", linkname, target 23 "sym", linkname, target
23 ); 24 );
24 } 25 }
26#else
27 /* symlink isn't implemented for WIN32, just issue a warning */
28 bb_perror_msg("can't create %slink '%s' to '%s'", "sym", linkname, target);
29#endif
25} 30}
26 31
32#if !ENABLE_PLATFORM_MINGW32
27void FAST_FUNC create_links_from_list(llist_t *list) 33void FAST_FUNC create_links_from_list(llist_t *list)
28{ 34{
29 while (list) { 35 while (list) {
@@ -40,3 +46,4 @@ void FAST_FUNC create_links_from_list(llist_t *list)
40 list = list->link; 46 list = list->link;
41 } 47 }
42} 48}
49#endif
diff --git a/archival/rpm.c b/archival/rpm.c
index 95b2531e8..c9e8785e2 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -140,6 +140,7 @@ static int rpm_gettags(const char *filename)
140 } 140 }
141 G.mytags = tags; 141 G.mytags = tags;
142 142
143#if !ENABLE_PLATFORM_MINGW32
143 /* Map the store */ 144 /* Map the store */
144 storepos = (storepos + G.pagesize) & -(int)G.pagesize; 145 storepos = (storepos + G.pagesize) & -(int)G.pagesize;
145 /* remember size for munmap */ 146 /* remember size for munmap */
@@ -148,6 +149,14 @@ static int rpm_gettags(const char *filename)
148 G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0); 149 G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
149 if (G.map == MAP_FAILED) 150 if (G.map == MAP_FAILED)
150 bb_perror_msg_and_die("mmap '%s'", filename); 151 bb_perror_msg_and_die("mmap '%s'", filename);
152#else
153# undef munmap
154# define munmap(p, l) free(p)
155 /* Allocate memory for the store */
156 G.map = xmalloc(storepos);
157 xlseek(fd, 0, SEEK_SET);
158 full_read(fd, G.map, storepos);
159#endif
151 160
152 return fd; 161 return fd;
153} 162}
@@ -294,6 +303,9 @@ static void extract_cpio(int fd, const char *source_rpm)
294 303
295 if (source_rpm != NULL) { 304 if (source_rpm != NULL) {
296 /* Binary rpm (it was built from some SRPM), install to root */ 305 /* Binary rpm (it was built from some SRPM), install to root */
306#if ENABLE_PLATFORM_MINGW32
307 if (chdir_system_drive())
308#endif
297 xchdir("/"); 309 xchdir("/");
298 } /* else: SRPM, install to current dir */ 310 } /* else: SRPM, install to current dir */
299 311
diff --git a/archival/tar.c b/archival/tar.c
index 3ef89fb0a..54961ff07 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -161,11 +161,13 @@ typedef struct TarBallInfo {
161# endif 161# endif
162 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */ 162 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
163 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */ 163 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
164#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
164//TODO: save only st_dev + st_ino 165//TODO: save only st_dev + st_ino
165 struct stat tarFileStatBuf; /* Stat info for the tarball, letting 166 struct stat tarFileStatBuf; /* Stat info for the tarball, letting
166 * us know the inode and device that the 167 * us know the inode and device that the
167 * tarball lives, so we can avoid trying 168 * tarball lives, so we can avoid trying
168 * to include the tarball into itself */ 169 * to include the tarball into itself */
170#endif
169} TarBallInfo; 171} TarBallInfo;
170 172
171/* A nice enum with all the possible tar file content types */ 173/* A nice enum with all the possible tar file content types */
@@ -527,15 +529,21 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
527 } 529 }
528 } 530 }
529 531
532#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
530 /* It is a bad idea to store the archive we are in the process of creating, 533 /* It is a bad idea to store the archive we are in the process of creating,
531 * so check the device and inode to be sure that this particular file isn't 534 * so check the device and inode to be sure that this particular file isn't
532 * the new tarball */ 535 * the new tarball */
533 if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev 536 if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev
534 && tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino 537 && tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino
538# if ENABLE_FEATURE_EXTRA_FILE_DATA
539 /* ignore invalid inode numbers */
540 && statbuf->st_ino != 0
541# endif
535 ) { 542 ) {
536 bb_error_msg("%s: file is the archive; skipping", fileName); 543 bb_error_msg("%s: file is the archive; skipping", fileName);
537 return TRUE; 544 return TRUE;
538 } 545 }
546#endif
539 547
540 if (exclude_file(tbInfo->excludeList, header_name)) 548 if (exclude_file(tbInfo->excludeList, header_name))
541 return SKIP; 549 return SKIP;
@@ -592,7 +600,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
592 return TRUE; 600 return TRUE;
593} 601}
594 602
595# if SEAMLESS_COMPRESSION 603#if SEAMLESS_COMPRESSION
604#if !ENABLE_PLATFORM_MINGW32
596/* Don't inline: vfork scares gcc and pessimizes code */ 605/* Don't inline: vfork scares gcc and pessimizes code */
597static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) 606static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
598{ 607{
@@ -661,7 +670,28 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
661 bb_perror_msg_and_die("can't execute '%s'", gzip); 670 bb_perror_msg_and_die("can't execute '%s'", gzip);
662 } 671 }
663} 672}
664# endif /* SEAMLESS_COMPRESSION */ 673#else
674static pid_t vfork_compressor(int tar_fd, const char *gzip)
675{
676 char *cmd;
677 int fd1;
678 pid_t pid;
679
680 if (find_applet_by_name(gzip) >= 0) {
681 cmd = xasprintf("%s --busybox %s -cf -", bb_busybox_exec_path, gzip);
682 }
683 else {
684 cmd = xasprintf("%s -cf -", gzip);
685 }
686 if ( (fd1=mingw_popen_fd(cmd, "w", tar_fd, &pid)) == -1 ) {
687 bb_perror_msg_and_die("can't execute '%s'", gzip);
688 }
689 free(cmd);
690 xmove_fd(fd1, tar_fd);
691 return pid;
692}
693#endif /* ENABLE_PLATFORM_MINGW32 */
694#endif /* SEAMLESS_COMPRESSION */
665 695
666 696
667# if !SEAMLESS_COMPRESSION 697# if !SEAMLESS_COMPRESSION
@@ -677,17 +707,20 @@ static NOINLINE int writeTarFile(
677 const char *gzip) 707 const char *gzip)
678{ 708{
679 int errorFlag = FALSE; 709 int errorFlag = FALSE;
710 IF_PLATFORM_MINGW32(pid_t pid = 0;)
680 711
681 /*tbInfo->hlInfoHead = NULL; - already is */ 712 /*tbInfo->hlInfoHead = NULL; - already is */
682 713
714#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
683 /* Store the stat info for the tarball's file, so 715 /* Store the stat info for the tarball's file, so
684 * can avoid including the tarball into itself.... */ 716 * can avoid including the tarball into itself.... */
685 xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file"); 717 xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file");
718#endif
686 719
687# if SEAMLESS_COMPRESSION 720# if SEAMLESS_COMPRESSION
688 if (gzip) 721 if (gzip)
689 vfork_compressor(tbInfo->tarFd, gzip); 722 IF_PLATFORM_MINGW32(pid = )vfork_compressor(tbInfo->tarFd, gzip);
690# endif 723#endif
691 724
692 /* Read the directory/files and iterate over them one at a time */ 725 /* Read the directory/files and iterate over them one at a time */
693 while (filelist) { 726 while (filelist) {
@@ -720,7 +753,11 @@ static NOINLINE int writeTarFile(
720# if SEAMLESS_COMPRESSION 753# if SEAMLESS_COMPRESSION
721 if (gzip) { 754 if (gzip) {
722 int status; 755 int status;
756#if !ENABLE_PLATFORM_MINGW32
723 if (safe_waitpid(-1, &status, 0) == -1) 757 if (safe_waitpid(-1, &status, 0) == -1)
758#else
759 if (safe_waitpid(pid, &status, 0) == -1)
760#endif
724 bb_perror_msg("waitpid"); 761 bb_perror_msg("waitpid");
725 else if (!WIFEXITED(status) || WEXITSTATUS(status)) 762 else if (!WIFEXITED(status) || WEXITSTATUS(status))
726 /* gzip was killed or has exited with nonzero! */ 763 /* gzip was killed or has exited with nonzero! */
diff --git a/archival/unzip.c b/archival/unzip.c
index 466794031..4e8ed0eae 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -70,6 +70,9 @@
70 70
71#include "libbb.h" 71#include "libbb.h"
72#include "bb_archive.h" 72#include "bb_archive.h"
73#if ENABLE_PLATFORM_MINGW32 && __GNUC__
74#pragma pack(2)
75#endif
73 76
74#if 0 77#if 0
75# define dbg(...) bb_error_msg(__VA_ARGS__) 78# define dbg(...) bb_error_msg(__VA_ARGS__)
@@ -345,6 +348,9 @@ static void unzip_create_leading_dirs(const char *fn)
345} 348}
346 349
347#if ENABLE_FEATURE_UNZIP_CDF 350#if ENABLE_FEATURE_UNZIP_CDF
351#if ENABLE_PLATFORM_MINGW32
352#define unzip_extract_symlink(s, z, d) unzip_extract_symlink(z, d)
353#endif
348static void unzip_extract_symlink(llist_t **symlink_placeholders, 354static void unzip_extract_symlink(llist_t **symlink_placeholders,
349 zip_header_t *zip, 355 zip_header_t *zip,
350 const char *dst_fn) 356 const char *dst_fn)
@@ -489,7 +495,7 @@ int unzip_main(int argc, char **argv)
489 llist_t *zaccept = NULL; 495 llist_t *zaccept = NULL;
490 llist_t *zreject = NULL; 496 llist_t *zreject = NULL;
491 char *base_dir = NULL; 497 char *base_dir = NULL;
492#if ENABLE_FEATURE_UNZIP_CDF 498#if ENABLE_FEATURE_UNZIP_CDF && !ENABLE_PLATFORM_MINGW32
493 llist_t *symlink_placeholders = NULL; 499 llist_t *symlink_placeholders = NULL;
494#endif 500#endif
495 int i; 501 int i;
@@ -596,7 +602,7 @@ int unzip_main(int argc, char **argv)
596 } 602 }
597 } 603 }
598 604
599#ifndef __GLIBC__ 605#if !defined(__GLIBC__) && !ENABLE_PLATFORM_MINGW32
600 /* 606 /*
601 * This code is needed for non-GNU getopt 607 * This code is needed for non-GNU getopt
602 * which doesn't understand "-" in option string. 608 * which doesn't understand "-" in option string.