| @@ -1,33 +1,30 @@ | | | @@ -1,33 +1,30 @@ |
1 | /* $NetBSD: rpm2pkg.c,v 1.6 2006/01/21 20:46:29 tron Exp $ */ | | 1 | /* $NetBSD: rpm2pkg.c,v 1.7 2009/04/23 21:38:02 tron Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2004 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2004-2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matthias Scheler. | | 8 | * by Matthias Scheler. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of The NetBSD Foundation nor the names of its | | | |
19 | * contributors may be used to endorse or promote products derived | | | |
20 | * from this software without specific prior written permission. | | | |
21 | * | | 18 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 30 | */ |
| @@ -118,30 +115,30 @@ typedef void PListEntryFunc(PListEntry * | | | @@ -118,30 +115,30 @@ typedef void PListEntryFunc(PListEntry * |
118 | #define PLIST_ORDER_FORWARD 0 | | 115 | #define PLIST_ORDER_FORWARD 0 |
119 | #define PLIST_ORDER_BACKWARD 1 | | 116 | #define PLIST_ORDER_BACKWARD 1 |
120 | | | 117 | |
121 | #define INVERT_PLIST_ORDER(o) (1 - (o)) | | 118 | #define INVERT_PLIST_ORDER(o) (1 - (o)) |
122 | | | 119 | |
123 | typedef struct FileHandleStruct { | | 120 | typedef struct FileHandleStruct { |
124 | FILE *fh_File; | | 121 | FILE *fh_File; |
125 | BZFILE *fh_BZFile; | | 122 | BZFILE *fh_BZFile; |
126 | gzFile *fh_GZFile; | | 123 | gzFile *fh_GZFile; |
127 | off_t fh_Pos; | | 124 | off_t fh_Pos; |
128 | } FileHandle; | | 125 | } FileHandle; |
129 | | | 126 | |
130 | static int | | 127 | static int |
131 | InitBuffer(void **Buffer, int *BufferSizePtr) | | 128 | InitBuffer(void **Buffer, size_t *BufferSizePtr) |
132 | { | | 129 | { |
133 | if (*Buffer == NULL) { | | 130 | if (*Buffer == NULL) { |
134 | int BufferSize; | | 131 | size_t BufferSize; |
135 | | | 132 | |
136 | BufferSize = sysconf(_SC_PAGESIZE) * 256; | | 133 | BufferSize = sysconf(_SC_PAGESIZE) * 256; |
137 | while ((*Buffer = malloc(BufferSize)) == NULL) { | | 134 | while ((*Buffer = malloc(BufferSize)) == NULL) { |
138 | BufferSize >>= 1; | | 135 | BufferSize >>= 1; |
139 | if (BufferSize == 0) | | 136 | if (BufferSize == 0) |
140 | return FALSE; | | 137 | return FALSE; |
141 | } | | 138 | } |
142 | *BufferSizePtr = BufferSize; | | 139 | *BufferSizePtr = BufferSize; |
143 | } | | 140 | } |
144 | return TRUE; | | 141 | return TRUE; |
145 | } | | 142 | } |
146 | | | 143 | |
147 | static void | | 144 | static void |
| @@ -226,37 +223,38 @@ SkipAndAlign(FileHandle *fh, off_t Skip) | | | @@ -226,37 +223,38 @@ SkipAndAlign(FileHandle *fh, off_t Skip) |
226 | | | 223 | |
227 | NewPos = (fh->fh_Pos + Skip + 3) & ~3; | | 224 | NewPos = (fh->fh_Pos + Skip + 3) & ~3; |
228 | if (fh->fh_Pos == NewPos) | | 225 | if (fh->fh_Pos == NewPos) |
229 | return TRUE; | | 226 | return TRUE; |
230 | | | 227 | |
231 | if (fh->fh_GZFile != NULL) { | | 228 | if (fh->fh_GZFile != NULL) { |
232 | if (gzseek(fh->fh_GZFile, NewPos, SEEK_SET) == NewPos) { | | 229 | if (gzseek(fh->fh_GZFile, NewPos, SEEK_SET) == NewPos) { |
233 | fh->fh_Pos = NewPos; | | 230 | fh->fh_Pos = NewPos; |
234 | return TRUE; | | 231 | return TRUE; |
235 | } | | 232 | } |
236 | return FALSE; | | 233 | return FALSE; |
237 | } else { | | 234 | } else { |
238 | static void *Buffer = NULL; | | 235 | static void *Buffer = NULL; |
239 | static int BufferSize = 0; | | 236 | static size_t BufferSize = 0; |
240 | | | 237 | |
241 | if (!InitBuffer(&Buffer, &BufferSize)) | | 238 | if (!InitBuffer(&Buffer, &BufferSize)) |
242 | return FALSE; | | 239 | return FALSE; |
243 | | | 240 | |
244 | while (fh->fh_Pos < NewPos) { | | 241 | while (fh->fh_Pos < NewPos) { |
245 | off_t Length; | | 242 | off_t Length; |
246 | int Chunk; | | 243 | int Chunk; |
247 | | | 244 | |
248 | Length = NewPos - fh->fh_Pos; | | 245 | Length = NewPos - fh->fh_Pos; |
249 | Chunk = (Length > BufferSize) ? BufferSize : Length; | | 246 | Chunk = (Length > (off_t)BufferSize) ? |
| | | 247 | (off_t)BufferSize : Length; |
250 | if (!Read(fh, Buffer, Chunk)) | | 248 | if (!Read(fh, Buffer, Chunk)) |
251 | return FALSE; | | 249 | return FALSE; |
252 | } | | 250 | } |
253 | } | | 251 | } |
254 | | | 252 | |
255 | return TRUE; | | 253 | return TRUE; |
256 | } | | 254 | } |
257 | | | 255 | |
258 | static PListEntry * | | 256 | static PListEntry * |
259 | InsertPListEntry(PListEntry **Tree,char *Name) | | 257 | InsertPListEntry(PListEntry **Tree,char *Name) |
260 | { | | 258 | { |
261 | PListEntry *Node; | | 259 | PListEntry *Node; |
262 | | | 260 | |
| @@ -549,27 +547,27 @@ MakeSymLink(char *Link, char *Name) | | | @@ -549,27 +547,27 @@ MakeSymLink(char *Link, char *Name) |
549 | return FALSE; | | 547 | return FALSE; |
550 | } | | 548 | } |
551 | | | 549 | |
552 | return ((unlink(Name) == 0) && (symlink(Link, Name) == 0)); | | 550 | return ((unlink(Name) == 0) && (symlink(Link, Name) == 0)); |
553 | } | | 551 | } |
554 | | | 552 | |
555 | static int | | 553 | static int |
556 | WriteFile(FileHandle *In, char *Name, mode_t Mode, unsigned long Length, | | 554 | WriteFile(FileHandle *In, char *Name, mode_t Mode, unsigned long Length, |
557 | char *Link) | | 555 | char *Link) |
558 | { | | 556 | { |
559 | int Out; | | 557 | int Out; |
560 | struct stat Stat; | | 558 | struct stat Stat; |
561 | static void *Buffer = NULL; | | 559 | static void *Buffer = NULL; |
562 | static int BufferSize = 0; | | 560 | static size_t BufferSize = 0; |
563 | | | 561 | |
564 | if ((lstat(Name, &Stat) == 0) && | | 562 | if ((lstat(Name, &Stat) == 0) && |
565 | (!S_ISREG(Stat.st_mode) || (unlink(Name) < 0))) { | | 563 | (!S_ISREG(Stat.st_mode) || (unlink(Name) < 0))) { |
566 | return FALSE; | | 564 | return FALSE; |
567 | } | | 565 | } |
568 | | | 566 | |
569 | if (!InitBuffer(&Buffer, &BufferSize)) | | 567 | if (!InitBuffer(&Buffer, &BufferSize)) |
570 | return FALSE; | | 568 | return FALSE; |
571 | | | 569 | |
572 | if (Link != NULL) { | | 570 | if (Link != NULL) { |
573 | if (link(Link, Name) < 0) | | 571 | if (link(Link, Name) < 0) |
574 | return FALSE; | | 572 | return FALSE; |
575 | Out = open(Name, O_WRONLY, Mode); | | 573 | Out = open(Name, O_WRONLY, Mode); |