From e8324105d0f970bf1de74a7ac9fe3b907e85bbfb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 27 Apr 2022 17:26:02 -0500 Subject: [PATCH] Identify PDF --- toys/posix/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toys/posix/file.c b/toys/posix/file.c index 2e65bcfa..dfd2a092 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -206,6 +206,7 @@ static void do_regular_file(int fd, char *name) { char *s = toybuf; unsigned len, magic; + int ii; // zero through elf shnum, just in case memset(s, 0, 80); @@ -215,6 +216,8 @@ static void do_regular_file(int fd, char *name) // 45 bytes: https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html else if (len>=45 && strstart(&s, "\177ELF")) do_elf_file(fd); else if (strstart(&s, "!\n")) xputs("ar archive"); + else if (*s=='%' && 2==sscanf(s, "%%PDF%d.%u", &ii, &magic)) + xprintf("PDF document, version %d.%u\n", -ii, magic); else if (len>28 && strstart(&s, "\x89PNG\x0d\x0a\x1a\x0a")) { // PNG is big-endian: https://www.w3.org/TR/PNG/#7Integers-and-byte-order int chunk_length = peek_be(s, 4); -- 2.39.2