[Toybox] [PATCH 2/2] pending/file: add cpio, tar, zip formats.

Isaac Dunham ibid.ag at gmail.com
Wed Feb 17 15:27:43 PST 2016


On Wed, Feb 17, 2016 at 03:08:55PM -0800, Isaac Dunham wrote:
> ---
>  toys/pending/file.c | 29 ++++++++++++++++++++++++++---

> +  // https://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt
> +  // the lengths for cpio are size of header + 9 bytes, since any valid
> +  // cpio archive ends with a record for "TARGET!!!"
> +  else if (len>85 && strstart(&s, "07070")) {
> +    char *cpioformat = "unknown type";
> +    if (toybuf[5] == '7') cpioformat = "pre-SVR4 or odc";
> +    else if (toybuf[5] == '1') cpioformat = "SVR4 with no CRC";
> +    else if (toybuf[5] == '2') cpioformat = "SVR4 with CRC";
> +    xprintf("ASCII cpio archive (%s)\n", cpioformat);
> +  }
> +  else if (len>33 && (peek(&s,2)==0143561 || peek(&s,2)==070707)) {
> +    if (peek(&s, 2) == 0143561) printf("byte-swapped ");
> +    xprintf("cpio archive\n");

I suspect this could be improved; I'm not sure how, though.

> +  // tar archive (ustar/pax or gnu)
> +  else if (len>500 && !strncmp(s+257, "ustar", 5)) {
> +    xprintf("POSIX tar archive%s\n", strncmp(s+262,"  ",2)?"":" (GNU)");

strstart() cannot be used because its first argument is char **, so one
would have to do:
  char *temp = s+262;
  strstart(&temp, string);
Per grep, it is always invoked with an '&' before the first argument.
Does it make sense to drop the second * ?


> +  // zip/jar/apk archive, ODF/OOXML document, or such
> +  else if (len>5 && strstart(&s, "PK\03\04")) {

Does not recognize empty or 'multi-volume' zipfiles.
Also does not differentiate between jar, apk, odf, ooxml, or any other
formats that use zip as a container.

Thanks,
Isaac Dunham

 1455751663.0


More information about the Toybox mailing list