| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rpm2pkg.c,v 1.12 2010/09/04 19:23:00 tron Exp $ */ | | 1 | /* $NetBSD: rpm2pkg.c,v 1.13 2010/09/05 00:24:30 tron Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2001-2010 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2001-2010 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. |
| @@ -322,27 +322,27 @@ Open(int fd) | | | @@ -322,27 +322,27 @@ Open(int fd) |
322 | (void)close(pfds[1]); | | 322 | (void)close(pfds[1]); |
323 | free(fh); | | 323 | free(fh); |
324 | return NULL; | | 324 | return NULL; |
325 | | | 325 | |
326 | case 0: | | 326 | case 0: |
327 | (void)close(pfds[0]); | | 327 | (void)close(pfds[0]); |
328 | if (dup2(fd, STDIN_FILENO) == -1 || | | 328 | if (dup2(fd, STDIN_FILENO) == -1 || |
329 | dup2(pfds[1], STDOUT_FILENO) == -1) { | | 329 | dup2(pfds[1], STDOUT_FILENO) == -1) { |
330 | exit(EXIT_FAILURE); | | 330 | exit(EXIT_FAILURE); |
331 | } | | 331 | } |
332 | (void)close(fd); | | 332 | (void)close(fd); |
333 | (void)close(pfds[1]); | | 333 | (void)close(pfds[1]); |
334 | | | 334 | |
335 | (void)execl(LZCAT, LZCAT, "-f", NULL); | | 335 | (void)execlp(LZCAT, LZCAT, "-f", NULL); |
336 | exit(EXIT_FAILURE); | | 336 | exit(EXIT_FAILURE); |
337 | | | 337 | |
338 | default: | | 338 | default: |
339 | (void)close(pfds[1]); | | 339 | (void)close(pfds[1]); |
340 | fh->fh_Pipe = pfds[0]; | | 340 | fh->fh_Pipe = pfds[0]; |
341 | fh->fh_Child = pid; | | 341 | fh->fh_Child = pid; |
342 | return fh; | | 342 | return fh; |
343 | } | | 343 | } |
344 | #else | | 344 | #else |
345 | return NULL; | | 345 | return NULL; |
346 | #endif | | 346 | #endif |
347 | } | | 347 | } |
348 | | | 348 | |
| @@ -350,27 +350,41 @@ Open(int fd) | | | @@ -350,27 +350,41 @@ Open(int fd) |
350 | } | | 350 | } |
351 | | | 351 | |
352 | static bool | | 352 | static bool |
353 | Read(FileHandle *fh, void *buffer, size_t length) | | 353 | Read(FileHandle *fh, void *buffer, size_t length) |
354 | { | | 354 | { |
355 | ssize_t bytes; | | 355 | ssize_t bytes; |
356 | | | 356 | |
357 | if (fh->fh_BZFile != NULL) { | | 357 | if (fh->fh_BZFile != NULL) { |
358 | int bzerror; | | 358 | int bzerror; |
359 | bytes = BZ2_bzRead(&bzerror, fh->fh_BZFile, buffer, length); | | 359 | bytes = BZ2_bzRead(&bzerror, fh->fh_BZFile, buffer, length); |
360 | } else if (fh->fh_GZFile != NULL) { | | 360 | } else if (fh->fh_GZFile != NULL) { |
361 | bytes = gzread(fh->fh_GZFile, buffer, length); | | 361 | bytes = gzread(fh->fh_GZFile, buffer, length); |
362 | } else if (fh->fh_Pipe >= 0) { | | 362 | } else if (fh->fh_Pipe >= 0) { |
363 | bytes = read(fh->fh_Pipe, buffer, length); | | 363 | bytes = 0; |
| | | 364 | while (length > 0) { |
| | | 365 | ssize_t chunk = read(fh->fh_Pipe, buffer, length); |
| | | 366 | if (chunk < 0) { |
| | | 367 | bytes = -1; |
| | | 368 | break; |
| | | 369 | } else if (chunk == 0) { |
| | | 370 | break; |
| | | 371 | } |
| | | 372 | |
| | | 373 | buffer += chunk; |
| | | 374 | length -= chunk; |
| | | 375 | |
| | | 376 | bytes += chunk; |
| | | 377 | } |
364 | } else { | | 378 | } else { |
365 | bytes = -1; | | 379 | bytes = -1; |
366 | } | | 380 | } |
367 | | | 381 | |
368 | if (bytes > 0) | | 382 | if (bytes > 0) |
369 | fh->fh_Pos += bytes; | | 383 | fh->fh_Pos += bytes; |
370 | | | 384 | |
371 | return (bytes == (ssize_t)length); | | 385 | return (bytes == (ssize_t)length); |
372 | } | | 386 | } |
373 | | | 387 | |
374 | static bool | | 388 | static bool |
375 | SkipAndAlign(FileHandle *fh, off_t Skip) | | 389 | SkipAndAlign(FileHandle *fh, off_t Skip) |
376 | | | 390 | |