From: Anatol Belski Date: Fri, 6 Mar 2015 15:52:14 +0000 (+0100) Subject: catching up X-Git-Tag: PRE_PHP7_NSAPI_REMOVAL~762^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5892ec175aadb90e19abf84fe08eae4ce3262718;p=php catching up --- diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c index 5647089a97..2ecf6c6f0c 100644 --- a/ext/fileinfo/libmagic/apprentice.c +++ b/ext/fileinfo/libmagic/apprentice.c @@ -2944,10 +2944,6 @@ error: return NULL; } -private const uint32_t ar[] = { - MAGICNO, VERSIONNO -}; - private int check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) { @@ -3017,6 +3013,10 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) char *dbname; int rv = -1; uint32_t i; + union { + struct magic m; + uint32_t h[2 + MAGIC_SETS]; + } hdr; php_stream *stream; @@ -3032,24 +3032,16 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) file_error(ms, errno, "cannot open `%s'", dbname); goto out; } + memset(&hdr, 0, sizeof(hdr)); + hdr.h[0] = MAGICNO; + hdr.h[1] = VERSIONNO; + memcpy(hdr.h + 2, map->nmagic, nm); - if (write(fd, ar, sizeof(ar)) != (ssize_t)sizeof(ar)) { - file_error(ms, errno, "error writing `%s'", dbname); - goto out; - } - - if (php_stream_write(stream, (const char *)map->nmagic, nm) != (ssize_t)nm) { + if (php_stream_write(stream,(const char *)&hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr)) { file_error(ms, errno, "error writing `%s'", dbname); goto out; } - assert(nm + sizeof(ar) < m); - - if (php_stream_seek(stream,(zend_off_t)sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) { - file_error(ms, errno, "error seeking `%s'", dbname); - goto out; - } - for (i = 0; i < MAGIC_SETS; i++) { len = m * map->nmagic[i]; if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) { @@ -3061,7 +3053,6 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) if (stream) { php_stream_close(stream); } - rv = 0; out: efree(dbname); diff --git a/ext/fileinfo/libmagic/magic.c b/ext/fileinfo/libmagic/magic.c index 28edb8a968..380cb72ce4 100644 --- a/ext/fileinfo/libmagic/magic.c +++ b/ext/fileinfo/libmagic/magic.c @@ -269,18 +269,6 @@ magic_load(struct magic_set *ms, const char *magicfile) return file_apprentice(ms, magicfile, FILE_LOAD); } -/* - * Install a set of compiled magic buffers. - */ -public int -magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes, - size_t nbufs) -{ - if (ms == NULL) - return -1; - return buffer_apprentice(ms, (struct magic **)bufs, sizes, nbufs); -} - public int magic_compile(struct magic_set *ms, const char *magicfile) {