Deleted Added
full compact
compress.c (267897) compress.c (275698)
1/*
2 * Copyright (c) Ian F. Darwin 1986-1995.
3 * Software written by Ian F. Darwin and others;
4 * maintained 1995-present by Christos Zoulas and others.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 21 unchanged lines hidden (view full) ---

30 * zmagic() - returns 0 if not recognized, uncompresses and prints
31 * information if recognized
32 * uncompress(method, old, n, newch) - uncompress old into new,
33 * using method, return sizeof new
34 */
35#include "file.h"
36
37#ifndef lint
1/*
2 * Copyright (c) Ian F. Darwin 1986-1995.
3 * Software written by Ian F. Darwin and others;
4 * maintained 1995-present by Christos Zoulas and others.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 21 unchanged lines hidden (view full) ---

30 * zmagic() - returns 0 if not recognized, uncompresses and prints
31 * information if recognized
32 * uncompress(method, old, n, newch) - uncompress old into new,
33 * using method, return sizeof new
34 */
35#include "file.h"
36
37#ifndef lint
38FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
38FILE_RCSID("@(#)$File: compress.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
39#endif
40
41#include "magic.h"
42#include <stdlib.h>
43#ifdef HAVE_UNISTD_H
44#include <unistd.h>
45#endif
46#include <string.h>
47#include <errno.h>
39#endif
40
41#include "magic.h"
42#include <stdlib.h>
43#ifdef HAVE_UNISTD_H
44#include <unistd.h>
45#endif
46#include <string.h>
47#include <errno.h>
48#ifndef __MINGW32__
48#if !defined(__MINGW32__) && !defined(WIN32)
49#include <sys/ioctl.h>
50#endif
51#ifdef HAVE_SYS_WAIT_H
52#include <sys/wait.h>
53#endif
54#if defined(HAVE_SYS_TIME_H)
55#include <sys/time.h>
56#endif

--- 315 unchanged lines hidden (view full) ---

372}
373#endif
374
375private size_t
376uncompressbuf(struct magic_set *ms, int fd, size_t method,
377 const unsigned char *old, unsigned char **newch, size_t n)
378{
379 int fdin[2], fdout[2];
49#include <sys/ioctl.h>
50#endif
51#ifdef HAVE_SYS_WAIT_H
52#include <sys/wait.h>
53#endif
54#if defined(HAVE_SYS_TIME_H)
55#include <sys/time.h>
56#endif

--- 315 unchanged lines hidden (view full) ---

372}
373#endif
374
375private size_t
376uncompressbuf(struct magic_set *ms, int fd, size_t method,
377 const unsigned char *old, unsigned char **newch, size_t n)
378{
379 int fdin[2], fdout[2];
380 int status;
380 ssize_t r;
381 pid_t pid;
382
383#ifdef BUILTIN_DECOMPRESS
384 /* FIXME: This doesn't cope with bzip2 */
385 if (method == 2)
386 return uncompressgzipped(ms, old, newch, n);
387#endif

--- 66 unchanged lines hidden (view full) ---

454#ifdef DEBUG
455 (void)fprintf(stderr, "Fork failed (%s)\n",
456 strerror(errno));
457#endif
458 exit(1);
459 /*NOTREACHED*/
460
461 default: /* parent */
381 ssize_t r;
382 pid_t pid;
383
384#ifdef BUILTIN_DECOMPRESS
385 /* FIXME: This doesn't cope with bzip2 */
386 if (method == 2)
387 return uncompressgzipped(ms, old, newch, n);
388#endif

--- 66 unchanged lines hidden (view full) ---

455#ifdef DEBUG
456 (void)fprintf(stderr, "Fork failed (%s)\n",
457 strerror(errno));
458#endif
459 exit(1);
460 /*NOTREACHED*/
461
462 default: /* parent */
462 break;
463 if (wait(&status) == -1) {
464#ifdef DEBUG
465 (void)fprintf(stderr,
466 "Wait failed (%s)\n",
467 strerror(errno));
468#endif
469 exit(1);
470 }
471 exit(WIFEXITED(status) ?
472 WEXITSTATUS(status) : 1);
473 /*NOTREACHED*/
463 }
464 (void) close(fdin[1]);
465 fdin[1] = -1;
466 }
467
468 if ((*newch = (unsigned char *) malloc(HOWMANY + 1)) == NULL) {
469#ifdef DEBUG
470 (void)fprintf(stderr, "Malloc failed (%s)\n",
471 strerror(errno));
472#endif
474 }
475 (void) close(fdin[1]);
476 fdin[1] = -1;
477 }
478
479 if ((*newch = (unsigned char *) malloc(HOWMANY + 1)) == NULL) {
480#ifdef DEBUG
481 (void)fprintf(stderr, "Malloc failed (%s)\n",
482 strerror(errno));
483#endif
473 n = 0;
484 n = NODATA;
474 goto err;
475 }
476 if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
477#ifdef DEBUG
478 (void)fprintf(stderr, "Read failed (%s)\n",
479 strerror(errno));
480#endif
481 free(*newch);
485 goto err;
486 }
487 if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
488#ifdef DEBUG
489 (void)fprintf(stderr, "Read failed (%s)\n",
490 strerror(errno));
491#endif
492 free(*newch);
482 n = 0;
493 n = NODATA;
483 *newch = NULL;
484 goto err;
485 } else {
486 n = r;
487 }
488 /* NUL terminate, as every buffer is handled here. */
489 (*newch)[n] = '\0';
490err:
491 if (fdin[1] != -1)
492 (void) close(fdin[1]);
493 (void) close(fdout[0]);
494 *newch = NULL;
495 goto err;
496 } else {
497 n = r;
498 }
499 /* NUL terminate, as every buffer is handled here. */
500 (*newch)[n] = '\0';
501err:
502 if (fdin[1] != -1)
503 (void) close(fdin[1]);
504 (void) close(fdout[0]);
494#ifdef WNOHANG
495 while (waitpid(pid, NULL, WNOHANG) != -1)
496 continue;
497#else
498 (void)wait(NULL);
505 if (wait(&status) == -1) {
506#ifdef DEBUG
507 (void)fprintf(stderr, "Wait failed (%s)\n",
508 strerror(errno));
499#endif
509#endif
510 n = NODATA;
511 } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
512#ifdef DEBUG
513 (void)fprintf(stderr, "Child status (0x%x)\n", status);
514#endif
515 n = NODATA;
516 }
517
500 (void) close(fdin[0]);
501
502 return n;
503 }
504}
505#endif
518 (void) close(fdin[0]);
519
520 return n;
521 }
522}
523#endif