~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to rpm2cpio.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rpmarchive: spit out the main archive portion of a package */
 
2
 
 
3
#include "system.h"
 
4
 
 
5
#include "rpmlib.h"
 
6
#include "debug.h"
 
7
 
 
8
int main(int argc, char **argv)
 
9
{
 
10
    FD_t fdi, fdo;
 
11
    Header h;
 
12
    char * rpmio_flags;
 
13
    int rc, isSource;
 
14
    FD_t gzdi;
 
15
    
 
16
    setprogname(argv[0]);       /* Retrofit glibc __progname */
 
17
    if (argc == 1)
 
18
        fdi = fdDup(STDIN_FILENO);
 
19
    else
 
20
        fdi = Fopen(argv[1], "r.ufdio");
 
21
 
 
22
    if (Ferror(fdi)) {
 
23
        fprintf(stderr, "%s: %s: %s\n", argv[0],
 
24
                (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
 
25
        exit(EXIT_FAILURE);
 
26
    }
 
27
    fdo = fdDup(STDOUT_FILENO);
 
28
 
 
29
    rc = rpmReadPackageHeader(fdi, &h, &isSource, NULL, NULL);
 
30
    switch (rc) {
 
31
    case 0:
 
32
        break;
 
33
    case 1:
 
34
        fprintf(stderr, _("argument is not an RPM package\n"));
 
35
        exit(EXIT_FAILURE);
 
36
        break;
 
37
    default:
 
38
        fprintf(stderr, _("error reading header from package\n"));
 
39
        exit(EXIT_FAILURE);
 
40
        break;
 
41
    }
 
42
 
 
43
    /* Retrieve type of payload compression. */
 
44
    {   const char * payload_compressor = NULL;
 
45
        char * t;
 
46
 
 
47
        if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
 
48
                            (void **) &payload_compressor, NULL))
 
49
            payload_compressor = "gzip";
 
50
        rpmio_flags = t = alloca(sizeof("r.gzdio"));
 
51
        *t++ = 'r';
 
52
        if (!strcmp(payload_compressor, "gzip"))
 
53
            t = stpcpy(t, ".gzdio");
 
54
        if (!strcmp(payload_compressor, "bzip2"))
 
55
            t = stpcpy(t, ".bzdio");
 
56
    }
 
57
 
 
58
    gzdi = Fdopen(fdi, rpmio_flags);    /* XXX gzdi == fdi */
 
59
    if (gzdi == NULL) {
 
60
        fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
 
61
        exit(EXIT_FAILURE);
 
62
    }
 
63
 
 
64
    rc = ufdCopy(gzdi, fdo);
 
65
    rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
 
66
    Fclose(fdo);
 
67
 
 
68
    Fclose(gzdi);       /* XXX gzdi == fdi */
 
69
 
 
70
    return rc;
 
71
}