]> granicus.if.org Git - php/commitdiff
catching up
authorAnatol Belski <ab@php.net>
Fri, 6 Mar 2015 15:52:14 +0000 (16:52 +0100)
committerAnatol Belski <ab@php.net>
Sun, 8 Mar 2015 18:47:30 +0000 (19:47 +0100)
ext/fileinfo/libmagic/apprentice.c
ext/fileinfo/libmagic/magic.c

index 5647089a97ea5990c72fd27ab841d21c4509db41..2ecf6c6f0c4cc7edd9405d98b1ab0e789cf07d1f 100644 (file)
@@ -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);
index 28edb8a9687680e25711114fba6f7a9187e812b6..380cb72ce4c2ef8cd377f94c150528521ff583b8 100644 (file)
@@ -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)
 {