Lines Matching refs:map
385 add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx) in add_mlist() argument
389 mlp->map = idx == 0 ? map : NULL; in add_mlist()
393 ml->map = NULL; in add_mlist()
394 ml->magic = map->magic[idx]; in add_mlist()
395 ml->nmagic = map->nmagic[idx]; in add_mlist()
410 struct magic_map *map; in apprentice_1() local
416 (unsigned long)sizeof(*map->magic[0]), in apprentice_1()
422 map = apprentice_load(ms, fn, action); in apprentice_1()
423 if (map == NULL) in apprentice_1()
425 return apprentice_compile(ms, map, fn); in apprentice_1()
428 map = apprentice_map(ms, fn); in apprentice_1()
429 if (map == NULL) { in apprentice_1()
433 map = apprentice_load(ms, fn, action); in apprentice_1()
435 if (map == NULL) in apprentice_1()
440 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
442 apprentice_unmap(map); in apprentice_1()
518 apprentice_unmap(struct magic_map *map) in apprentice_unmap() argument
520 if (map == NULL) in apprentice_unmap()
522 if (map->p != php_magic_database) { in apprentice_unmap()
523 if (map->p == NULL) { in apprentice_unmap()
526 if (map->magic[j]) { in apprentice_unmap()
527 efree(map->magic[j]); in apprentice_unmap()
531 efree(map->p); in apprentice_unmap()
534 efree(map); in apprentice_unmap()
558 if (ml->map) in mlist_free()
559 apprentice_unmap(ml->map); in mlist_free()
1222 struct magic_map *map; in apprentice_load() local
1232 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) in apprentice_load()
1234 file_oomem(ms, sizeof(*map)); in apprentice_load()
1311 &map->magic[j], &map->nmagic[j]) == -1) { in apprentice_load()
1322 apprentice_unmap(map); in apprentice_load()
1325 return map; in apprentice_load()
2784 struct magic_map *map; in apprentice_buf() local
2786 if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { in apprentice_buf()
2787 file_oomem(ms, sizeof(*map)); in apprentice_buf()
2790 map->len = len; in apprentice_buf()
2791 map->p = buf; in apprentice_buf()
2792 map->type = MAP_TYPE_USER; in apprentice_buf()
2793 if (check_buffer(ms, map, "buffer") != 0) { in apprentice_buf()
2794 apprentice_unmap(map); in apprentice_buf()
2797 return map; in apprentice_buf()
2811 struct magic_map *map; in apprentice_map() local
2818 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { in apprentice_map()
2819 file_oomem(ms, sizeof(*map)); in apprentice_map()
2824 map->p = (void *)&php_magic_database; in apprentice_map()
2858 map->len = (size_t)st.sb.st_size; in apprentice_map()
2859 if ((map->p = CAST(void *, emalloc(map->len))) == NULL) { in apprentice_map()
2860 file_oomem(ms, map->len); in apprentice_map()
2863 if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) { in apprentice_map()
2867 map->len = 0; in apprentice_map()
2874 ptr = (uint32_t *)(void *)map->p; in apprentice_map()
2898 map->p = emalloc(sizeof(php_magic_database)); in apprentice_map()
2899 map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database)); in apprentice_map()
2912 map->magic[0] = CAST(struct magic *, map->p) + 1; in apprentice_map()
2916 map->nmagic[i] = swap4(ptr[i + 2]); in apprentice_map()
2918 map->nmagic[i] = ptr[i + 2]; in apprentice_map()
2920 map->magic[i + 1] = map->magic[i] + map->nmagic[i]; in apprentice_map()
2921 nentries += map->nmagic[i]; in apprentice_map()
2930 byteswap(map->magic[i], map->nmagic[i]); in apprentice_map()
2935 return map; in apprentice_map()
2941 apprentice_unmap(map); in apprentice_map()
2949 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) in check_buffer() argument
2956 ptr = CAST(uint32_t *, map->p); in check_buffer()
2975 entries = (uint32_t)(map->len / sizeof(struct magic)); in check_buffer()
2976 if ((entries * sizeof(struct magic)) != map->len) { in check_buffer()
2979 dbname, map->len, sizeof(struct magic)); in check_buffer()
2982 map->magic[0] = CAST(struct magic *, map->p) + 1; in check_buffer()
2986 map->nmagic[i] = swap4(ptr[i + 2]); in check_buffer()
2988 map->nmagic[i] = ptr[i + 2]; in check_buffer()
2990 map->magic[i + 1] = map->magic[i] + map->nmagic[i]; in check_buffer()
2991 nentries += map->nmagic[i]; in check_buffer()
3000 byteswap(map->magic[i], map->nmagic[i]); in check_buffer()
3008 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3010 static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS; in apprentice_compile()
3011 static const size_t m = sizeof(**map->magic); in apprentice_compile()
3038 memcpy(hdr.h + 2, map->nmagic, nm); in apprentice_compile()
3046 len = m * map->nmagic[i]; in apprentice_compile()
3047 if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) { in apprentice_compile()