2 * Copyright (c) 2004 Michael Schroeder (mls@suse.de)
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
18 /****************************************************************
29 r = r << 8 | getc(fp);
38 r = r << 8 | getc(fp);
39 r = r << 8 | getc(fp);
40 r = r << 8 | getc(fp);
51 s = s2 = xmalloc(l + 2);
59 rpmlskip(FILE *fp, int l)
66 rpmlgetfn(FILE *fp, char **lastfnp, int *lastfnlp)
70 char *lastfn = *lastfnp;
71 int lastfnl = *lastfnlp;
76 fprintf(stderr, "rpmlgetfn: EOF reached!\n");
82 if (l + ol + 1 > lastfnl)
84 lastfn = xrealloc(lastfn, l + ol + 1);
97 rpmlread(FILE *fp, char *fn, int nomagic, struct rpmlfile **filesp, int *nfilesp)
101 char *n, *name, *evr, *nevr;
103 unsigned int buildtime;
104 int patchescnt, filec, i;
105 struct rpmlfile *files = 0;
107 unsigned int mode, s, ogs;
109 if (!nomagic && rpmlget32(fp) != 0x52504d4c)
111 fprintf(stderr, "%s: not an rpml file\n", fn);
114 name = rpmlgetstr(fp);
115 evr = rpmlgetstr(fp);
116 nevr = xmalloc(strlen(name) + strlen(evr) + 2);
117 sprintf(nevr, "%s-%s", name, evr);
118 buildhost = rpmlgetstr(fp);
119 buildtime = rpmlget32(fp);
120 patchescnt = rpmlget16(fp);
126 for (i = 0; i < patchescnt; i++)
128 filec = rpmlget32(fp);
129 for (i = 0; i < filec; i++)
131 if ((nfiles & 15) == 0)
132 files = xrealloc(files, (nfiles + 16) * sizeof(*files));
133 n = rpmlgetfn(fp, &lastfn, &lastfnl);
134 files[nfiles].name = xmalloc(strlen(n) + 1);
135 strcpy(files[nfiles].name, n);
136 files[nfiles].mode = S_IFREG;
137 files[nfiles].fflags = FILE_UNPATCHED;
138 memset(files[nfiles].md5, 0, 16);
144 n = rpmlgetfn(fp, &lastfn, &lastfnl);
147 if ((nfiles & 15) == 0)
148 files = xrealloc(files, (nfiles + 16) * sizeof(*files));
149 if (*n == '.' && n[1] == '/')
151 files[nfiles].name = xmalloc(strlen(n) + 1);
152 strcpy(files[nfiles].name, n);
153 files[nfiles].fflags = 0;
154 memset(files[nfiles].md5, 0, 16);
155 mode = rpmlget16(fp);
156 files[nfiles].mode = mode;
157 if (mode == 0) /* hard link chain */
169 rpmlskip(fp, ogs2 + 1);
171 rpmlskip(fp, (ogs >> 2 & 0x3f) + 1);
176 rpmlskip(fp, (ogs >> 5 & 7) + 1);
178 rpmlskip(fp, (ogs >> 2 & 7) + 1);
180 if (S_ISCHR(mode) || S_ISBLK(mode))
181 rpmlget32(fp); /* rdev */
182 if (S_ISREG(mode) || S_ISLNK(mode))
195 for (s = 0; s < 16; s++)
196 files[nfiles].md5[s] = getc(fp);