Write the encoding header of the entry in 'p'. If p is NULL it just returns * the amount of bytes required to encode such a length. Arguments: * * 'encoding' is the encoding we are using for the entry. It could be * ZIP_INT_* or ZIP_STR_* or between ZIP_INT_IMM_MIN and ZIP_INT_IMM_MAX * for single-byte small immediate integers. * * 'rawlen' is only used for ZIP_STR_* encodings and is the le
| 367 | * The function returns the number of bytes used by the encoding/length |
| 368 | * header stored in 'p'. */ |
| 369 | unsigned int zipStoreEntryEncoding(unsigned char *p, unsigned char encoding, unsigned int rawlen) { |
| 370 | unsigned char len = 1, buf[5]; |
| 371 | |
| 372 | if (ZIP_IS_STR(encoding)) { |
| 373 | /* Although encoding is given it may not be set for strings, |
| 374 | * so we determine it here using the raw length. */ |
| 375 | if (rawlen <= 0x3f) { |
| 376 | if (!p) return len; |
| 377 | buf[0] = ZIP_STR_06B | rawlen; |
| 378 | } else if (rawlen <= 0x3fff) { |
| 379 | len += 1; |
| 380 | if (!p) return len; |
| 381 | buf[0] = ZIP_STR_14B | ((rawlen >> 8) & 0x3f); |
| 382 | buf[1] = rawlen & 0xff; |
| 383 | } else { |
| 384 | len += 4; |
| 385 | if (!p) return len; |
| 386 | buf[0] = ZIP_STR_32B; |
| 387 | buf[1] = (rawlen >> 24) & 0xff; |
| 388 | buf[2] = (rawlen >> 16) & 0xff; |
| 389 | buf[3] = (rawlen >> 8) & 0xff; |
| 390 | buf[4] = rawlen & 0xff; |
| 391 | } |
| 392 | } else { |
| 393 | /* Implies integer encoding, so length is always 1. */ |
| 394 | if (!p) return len; |
| 395 | buf[0] = encoding; |
| 396 | } |
| 397 | |
| 398 | /* Store this length at p. */ |
| 399 | memcpy(p,buf,len); |
| 400 | return len; |
| 401 | } |
| 402 | |
| 403 | /* Decode the entry encoding type and data length (string length for strings, |
| 404 | * number of bytes used for the integer for integer entries) encoded in 'ptr'. |
no outgoing calls
no test coverage detected