diff options
Diffstat (limited to 'archival/ar.c')
-rw-r--r-- | archival/ar.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/archival/ar.c b/archival/ar.c index 320cbae72..16bb33227 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -30,12 +30,12 @@ | |||
30 | //config:config FEATURE_AR_LONG_FILENAMES | 30 | //config:config FEATURE_AR_LONG_FILENAMES |
31 | //config: bool "Support long filenames (not needed for debs)" | 31 | //config: bool "Support long filenames (not needed for debs)" |
32 | //config: default y | 32 | //config: default y |
33 | //config: depends on AR | 33 | //config: depends on AR || MAKE || PDPMAKE |
34 | //config: help | 34 | //config: help |
35 | //config: By default the ar format can only store the first 15 characters | 35 | //config: By default the ar format can only store the first 15 characters |
36 | //config: of the filename, this option removes that limitation. | 36 | //config: of the filename, this option removes that limitation. |
37 | //config: It supports the GNU ar long filename method which moves multiple long | 37 | //config: It supports the GNU ar long filename method which moves multiple long |
38 | //config: filenames into a the data section of a new ar entry. | 38 | //config: filenames into the data section of a new ar entry. |
39 | //config: | 39 | //config: |
40 | //config:config FEATURE_AR_CREATE | 40 | //config:config FEATURE_AR_CREATE |
41 | //config: bool "Support archive creation" | 41 | //config: bool "Support archive creation" |
@@ -153,6 +153,9 @@ static int write_ar_archive(archive_handle_t *handle) | |||
153 | { | 153 | { |
154 | struct stat st; | 154 | struct stat st; |
155 | archive_handle_t *out_handle; | 155 | archive_handle_t *out_handle; |
156 | #if ENABLE_PLATFORM_MINGW32 | ||
157 | char *temp_fn = NULL; | ||
158 | #endif | ||
156 | 159 | ||
157 | xfstat(handle->src_fd, &st, handle->ar__name); | 160 | xfstat(handle->src_fd, &st, handle->ar__name); |
158 | 161 | ||
@@ -161,8 +164,14 @@ static int write_ar_archive(archive_handle_t *handle) | |||
161 | */ | 164 | */ |
162 | if (st.st_size != 0) { | 165 | if (st.st_size != 0) { |
163 | out_handle = init_handle(); | 166 | out_handle = init_handle(); |
167 | #if !ENABLE_PLATFORM_MINGW32 | ||
164 | xunlink(handle->ar__name); | 168 | xunlink(handle->ar__name); |
165 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); | 169 | out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC); |
170 | #else | ||
171 | /* can't unlink open file, create temporary output file */ | ||
172 | temp_fn = xasprintf("%sXXXXXX", handle->ar__name); | ||
173 | out_handle->src_fd = xmkstemp(temp_fn); | ||
174 | #endif | ||
166 | out_handle->accept = handle->accept; | 175 | out_handle->accept = handle->accept; |
167 | } else { | 176 | } else { |
168 | out_handle = handle; | 177 | out_handle = handle; |
@@ -184,12 +193,20 @@ static int write_ar_archive(archive_handle_t *handle) | |||
184 | continue; | 193 | continue; |
185 | 194 | ||
186 | /* optional, since we exit right after we return */ | 195 | /* optional, since we exit right after we return */ |
187 | if (ENABLE_FEATURE_CLEAN_UP) { | 196 | if (ENABLE_FEATURE_CLEAN_UP || ENABLE_PLATFORM_MINGW32) { |
188 | close(handle->src_fd); | 197 | close(handle->src_fd); |
189 | if (out_handle->src_fd != handle->src_fd) | 198 | if (out_handle->src_fd != handle->src_fd) |
190 | close(out_handle->src_fd); | 199 | close(out_handle->src_fd); |
191 | } | 200 | } |
192 | 201 | ||
202 | #if ENABLE_PLATFORM_MINGW32 | ||
203 | if (temp_fn != NULL) { | ||
204 | xrename(temp_fn, handle->ar__name); | ||
205 | if (ENABLE_FEATURE_CLEAN_UP) | ||
206 | free(temp_fn); | ||
207 | } | ||
208 | #endif | ||
209 | |||
193 | return EXIT_SUCCESS; | 210 | return EXIT_SUCCESS; |
194 | } | 211 | } |
195 | #endif /* FEATURE_AR_CREATE */ | 212 | #endif /* FEATURE_AR_CREATE */ |