Swap 2nd and 3rd arg to Fread/Fwrite to preserve read/write type return.
[platform/upstream/rpm.git] / rpm2cpio.c
1 /* rpmarchive: spit out the main archive portion of a package */
2
3 #include "system.h"
4
5 #include "rpmlib.h"
6
7 int main(int argc, char **argv)
8 {
9     FD_t fdi, fdo;
10     Header hd;
11     int rc, isSource;
12     char buffer[1024];
13     int ct;
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
23     if (Fileno(fdi) < 0) {
24         perror("cannot open package");
25         exit(EXIT_FAILURE);
26     }
27     fdo = fdDup(STDOUT_FILENO);
28
29     rc = rpmReadPackageHeader(fdi, &hd, &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 #ifdef DYING
44     gzdi = gzdFdopen(fdi, "r"); /* XXX gzdi == fdi */
45 #else
46     gzdi = Fdopen(fdi, "r.gzdio");      /* XXX gzdi == fdi */
47 #endif
48
49     while ((ct = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), gzdi)) > 0) {
50         Fwrite(buffer, sizeof(buffer[0]), ct, fdo);
51     }
52
53     if (ct < 0) {
54         fprintf (stderr, "rpm2cpio: zlib: %s\n", Fstrerror(gzdi));
55         rc = EXIT_FAILURE;
56     } else {
57         rc = EXIT_SUCCESS;
58     }
59
60     Fclose(gzdi);       /* XXX gzdi == fdi */
61
62     return rc;
63 }