~ubuntu-branches/ubuntu/oneiric/dpkg/oneiric-proposed

« back to all changes in this revision

Viewing changes to dpkg-split/info.c

  • Committer: Steve Langasek
  • Date: 2011-03-15 00:11:56 UTC
  • Revision ID: steve.langasek@linaro.org-20110315001156-uyrlgh501d69seku
Merge newer snapshot from Raphael, to keep us in tune with mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <string.h>
29
29
#include <unistd.h>
30
30
#include <ar.h>
 
31
#include <inttypes.h>
 
32
#include <stdint.h>
31
33
#include <stdlib.h>
32
34
#include <stdio.h>
33
35
 
39
41
 
40
42
#include "dpkg-split.h"
41
43
 
42
 
static unsigned long unsignedlong(const char *value, const char *fn, const char *what) {
43
 
  unsigned long r;
 
44
static intmax_t
 
45
parse_intmax(const char *value, const char *fn, const char *what)
 
46
{
 
47
  intmax_t r;
44
48
  char *endp;
45
49
 
46
 
  r= strtoul(value,&endp,10);
 
50
  r = strtoimax(value, &endp, 10);
47
51
  if (value == endp || *endp)
48
52
    ohshit(_("file `%.250s' is corrupt - bad digit (code %d) in %s"),fn,*endp,what);
49
53
  return r;
74
78
  static size_t readinfobuflen= 0;
75
79
 
76
80
  size_t thisilen;
77
 
  unsigned int templong;
78
 
  char magicbuf[strlen(DPKG_AR_MAGIC)], *rip, *partnums, *slash;
 
81
  intmax_t templong;
 
82
  char magicbuf[sizeof(DPKG_AR_MAGIC) - 1], *rip, *partnums, *slash;
79
83
  struct ar_hdr arh;
80
84
  int c;
81
85
  struct stat stab;
82
86
 
83
87
  if (fread(magicbuf, 1, sizeof(magicbuf), partfile) != sizeof(magicbuf)) {
84
 
    if (ferror(partfile)) rerr(fn); else return NULL;
 
88
    if (ferror(partfile))
 
89
      ohshite(_("error reading %.250s"), fn);
 
90
    else
 
91
      return NULL;
85
92
  }
86
93
  if (memcmp(magicbuf, DPKG_AR_MAGIC, sizeof(magicbuf)))
87
94
    return NULL;
124
131
      strspn(ir->md5sum, "0123456789abcdef") != MD5HASHLEN)
125
132
    ohshit(_("file `%.250s' is corrupt - bad MD5 checksum `%.250s'"),fn,ir->md5sum);
126
133
 
127
 
  ir->orglength = unsignedlong(nextline(&rip, fn, _("archive total size")),
 
134
  ir->orglength = parse_intmax(nextline(&rip, fn, _("archive total size")),
128
135
                               fn, _("archive total size"));
129
 
  ir->maxpartlen = unsignedlong(nextline(&rip, fn, _("archive part offset")),
 
136
  ir->maxpartlen = parse_intmax(nextline(&rip, fn, _("archive part offset")),
130
137
                                fn, _("archive part offset"));
131
138
 
132
139
  partnums = nextline(&rip, fn, _("archive part numbers"));
135
142
    ohshit(_("file '%.250s' is corrupt - no slash between archive part numbers"), fn);
136
143
  *slash++ = '\0';
137
144
 
138
 
  templong = unsignedlong(slash, fn, _("number of archive parts"));
 
145
  templong = parse_intmax(slash, fn, _("number of archive parts"));
139
146
  if (templong <= 0 || templong > INT_MAX)
140
147
    ohshit(_("file '%.250s' is corrupt - bad number of archive parts"), fn);
141
148
  ir->maxpartn= templong;
142
 
  templong = unsignedlong(partnums, fn, _("archive parts number"));
 
149
  templong = parse_intmax(partnums, fn, _("archive parts number"));
143
150
  if (templong <= 0 || templong > ir->maxpartn)
144
151
    ohshit(_("file '%.250s' is corrupt - bad archive part number"),fn);
145
152
  ir->thispartn= templong;
197
204
         "    Part of package:                %s\n"
198
205
         "        ... version:                %s\n"
199
206
         "        ... MD5 checksum:           %s\n"
200
 
         "        ... length:                 %lu bytes\n"
201
 
         "        ... split every:            %lu bytes\n"
 
207
         "        ... length:                 %jd bytes\n"
 
208
         "        ... split every:            %jd bytes\n"
202
209
         "    Part number:                    %d/%d\n"
203
 
         "    Part length:                    %zi bytes\n"
204
 
         "    Part offset:                    %lu bytes\n"
205
 
         "    Part file size (used portion):  %lu bytes\n\n"),
 
210
         "    Part length:                    %jd bytes\n"
 
211
         "    Part offset:                    %jd bytes\n"
 
212
         "    Part file size (used portion):  %jd bytes\n\n"),
206
213
         pi->filename,
207
214
         pi->fmtversion,
208
215
         pi->package,
209
216
         pi->version,
210
217
         pi->md5sum,
211
 
         pi->orglength,
212
 
         pi->maxpartlen,
 
218
         (intmax_t)pi->orglength,
 
219
         (intmax_t)pi->maxpartlen,
213
220
         pi->thispartn,
214
221
         pi->maxpartn,
215
 
         pi->thispartlen,
216
 
         pi->thispartoffset,
217
 
         (unsigned long)pi->filesize);
 
222
         (intmax_t)pi->thispartlen,
 
223
         (intmax_t)pi->thispartoffset,
 
224
         (intmax_t)pi->filesize);
218
225
}
219
226
 
220
227
void do_info(const char *const *argv) {