~ubuntu-branches/ubuntu/lucid/php5/lucid

« back to all changes in this revision

Viewing changes to ext/zip/lib/zip_dirent.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-03-16 09:09:50 UTC
  • mfrom: (1.1.18 upstream) (0.3.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100316090950-e36m0pzranoixifd
Tags: 5.3.2-1ubuntu1
* Merge from debian unstable: 
  - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions already in
      universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
  - Dropped debian/patches/libedit_is_editline.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 
69
69
 
70
70
 
 
71
int
 
72
_zip_cdir_grow(struct zip_cdir *cd, int nentry, struct zip_error *error)
 
73
{
 
74
    struct zip_dirent *entry;
 
75
 
 
76
    if (nentry < cd->nentry) {
 
77
        _zip_error_set(error, ZIP_ER_INTERNAL, 0);
 
78
        return -1;
 
79
    }
 
80
 
 
81
    if ((entry=((struct zip_dirent *)
 
82
                realloc(cd->entry, sizeof(*(cd->entry))*nentry))) == NULL) {
 
83
        _zip_error_set(error, ZIP_ER_MEMORY, 0);
 
84
        return -1;
 
85
    }
 
86
 
 
87
    cd->nentry = nentry;
 
88
    cd->entry = entry;
 
89
 
 
90
    return 0;
 
91
}
 
92
 
 
93
 
 
94
 
71
95
struct zip_cdir *
72
96
_zip_cdir_new(int nentry, struct zip_error *error)
73
97
{
173
197
   Fills the zip directory entry zde.
174
198
 
175
199
   If bufp is non-NULL, data is taken from there and bufp is advanced
176
 
   by the amount of data used; no more than left bytes are used.
177
 
   Otherwise data is read from fp as needed.
 
200
   by the amount of data used; otherwise data is read from fp as needed.
 
201
   
 
202
   if leftp is non-NULL, no more bytes than specified by it are used,
 
203
   and *leftp is reduced by the number of bytes used.
178
204
 
179
 
   If localp != 0, it reads a local header instead of a central
 
205
   If local != 0, it reads a local header instead of a central
180
206
   directory entry.
181
207
 
182
208
   Returns 0 if successful. On error, error is filled in and -1 is
183
209
   returned.
 
210
 
 
211
   XXX: leftp and file position undefined on error.
184
212
*/
185
213
 
186
214
int
187
215
_zip_dirent_read(struct zip_dirent *zde, FILE *fp,
188
 
                 unsigned char **bufp, unsigned int left, int localp,
 
216
                 unsigned char **bufp, unsigned int *leftp, int local,
189
217
                 struct zip_error *error)
190
218
{
191
219
    unsigned char buf[CDENTRYSIZE];
193
221
    unsigned short dostime, dosdate;
194
222
    unsigned int size;
195
223
 
196
 
    if (localp)
 
224
    if (local)
197
225
        size = LENTRYSIZE;
198
226
    else
199
227
        size = CDENTRYSIZE;
200
 
    
 
228
 
 
229
    if (leftp && (*leftp < size)) {
 
230
        _zip_error_set(error, ZIP_ER_NOZIP, 0);
 
231
        return -1;
 
232
    }
 
233
 
201
234
    if (bufp) {
202
235
        /* use data from buffer */
203
236
        cur = *bufp;
204
 
        if (left < size) {
205
 
            _zip_error_set(error, ZIP_ER_NOZIP, 0);
206
 
            return -1;
207
 
        }
208
237
    }
209
238
    else {
210
239
        /* read entry from disk */
212
241
            _zip_error_set(error, ZIP_ER_READ, errno);
213
242
            return -1;
214
243
        }
215
 
        left = size;
216
244
        cur = buf;
217
245
    }
218
246
 
219
 
    if (memcmp(cur, (localp ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
 
247
    if (memcmp(cur, (local ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
220
248
        _zip_error_set(error, ZIP_ER_NOZIP, 0);
221
249
        return -1;
222
250
    }
225
253
    
226
254
    /* convert buffercontents to zip_dirent */
227
255
    
228
 
    if (!localp)
 
256
    if (!local)
229
257
        zde->version_madeby = _zip_read2(&cur);
230
258
    else
231
259
        zde->version_madeby = 0;
245
273
    zde->filename_len = _zip_read2(&cur);
246
274
    zde->extrafield_len = _zip_read2(&cur);
247
275
    
248
 
    if (localp) {
 
276
    if (local) {
249
277
        zde->comment_len = 0;
250
278
        zde->disk_number = 0;
251
279
        zde->int_attrib = 0;
263
291
    zde->extrafield = NULL;
264
292
    zde->comment = NULL;
265
293
 
 
294
    size += zde->filename_len+zde->extrafield_len+zde->comment_len;
 
295
 
 
296
    if (leftp && (*leftp < size)) {
 
297
        _zip_error_set(error, ZIP_ER_NOZIP, 0);
 
298
        return -1;
 
299
    }
 
300
 
266
301
    if (bufp) {
267
 
        if (left < CDENTRYSIZE + (zde->filename_len+zde->extrafield_len
268
 
                                  +zde->comment_len)) {
269
 
            _zip_error_set(error, ZIP_ER_NOZIP, 0);
270
 
            return -1;
271
 
        }
272
 
 
273
302
        if (zde->filename_len) {
274
303
            zde->filename = _zip_readstr(&cur, zde->filename_len, 1, error);
275
304
            if (!zde->filename)
312
341
 
313
342
    if (bufp)
314
343
      *bufp = cur;
 
344
    if (leftp)
 
345
        *leftp -= size;
315
346
 
316
347
    return 0;
317
348
}
442
473
static time_t
443
474
_zip_d2u_time(int dtime, int ddate)
444
475
{
445
 
    struct tm *tm;
446
 
    time_t now;
 
476
    struct tm tm;
447
477
 
448
 
    now = time(NULL);
449
 
    tm = localtime(&now);
 
478
    memset(&tm, sizeof(tm), 0);
 
479
    
450
480
    /* let mktime decide if DST is in effect */
451
 
    tm->tm_isdst = -1;
 
481
    tm.tm_isdst = -1;
452
482
    
453
 
    tm->tm_year = ((ddate>>9)&127) + 1980 - 1900;
454
 
    tm->tm_mon = ((ddate>>5)&15) - 1;
455
 
    tm->tm_mday = ddate&31;
456
 
 
457
 
    tm->tm_hour = (dtime>>11)&31;
458
 
    tm->tm_min = (dtime>>5)&63;
459
 
    tm->tm_sec = (dtime<<1)&62;
460
 
 
461
 
    return mktime(tm);
 
483
    tm.tm_year = ((ddate>>9)&127) + 1980 - 1900;
 
484
    tm.tm_mon = ((ddate>>5)&15) - 1;
 
485
    tm.tm_mday = ddate&31;
 
486
 
 
487
    tm.tm_hour = (dtime>>11)&31;
 
488
    tm.tm_min = (dtime>>5)&63;
 
489
    tm.tm_sec = (dtime<<1)&62;
 
490
 
 
491
    return mktime(&tm);
462
492
}
463
493
 
464
494