Lines Matching refs:map

385 add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)  in add_mlist()  argument
389 mlp->map = NULL; in add_mlist()
393 ml->map = idx == 0 ? 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 == (struct magic_map *)-1) in apprentice_1()
431 if (map == NULL) { in apprentice_1()
435 map = apprentice_load(ms, fn, action); in apprentice_1()
437 if (map == NULL) in apprentice_1()
442 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
521 apprentice_unmap(struct magic_map *map) in apprentice_unmap() argument
523 if (map == NULL) in apprentice_unmap()
525 if (map->p != php_magic_database) { in apprentice_unmap()
526 if (map->p == NULL) { in apprentice_unmap()
529 if (map->magic[j]) { in apprentice_unmap()
530 efree(map->magic[j]); in apprentice_unmap()
534 efree(map->p); in apprentice_unmap()
537 efree(map); in apprentice_unmap()
561 if (ml->map) in mlist_free()
562 apprentice_unmap(CAST(struct magic_map *, ml->map)); in mlist_free()
1274 struct magic_map *map; in apprentice_load() local
1284 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) in apprentice_load()
1286 file_oomem(ms, sizeof(*map)); in apprentice_load()
1289 map->type = MAP_TYPE_MALLOC; in apprentice_load()
1365 &map->magic[j], &map->nmagic[j]) == -1) { in apprentice_load()
1376 apprentice_unmap(map); in apprentice_load()
1379 return map; in apprentice_load()
2934 struct magic_map *map; in apprentice_buf() local
2936 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { in apprentice_buf()
2937 file_oomem(ms, sizeof(*map)); in apprentice_buf()
2940 map->len = len; in apprentice_buf()
2941 map->p = buf; in apprentice_buf()
2942 map->type = MAP_TYPE_USER; in apprentice_buf()
2943 if (check_buffer(ms, map, "buffer") != 0) { in apprentice_buf()
2944 apprentice_unmap(map); in apprentice_buf()
2947 return map; in apprentice_buf()
2961 struct magic_map *map; in apprentice_map() local
2968 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { in apprentice_map()
2969 file_oomem(ms, sizeof(*map)); in apprentice_map()
2974 map->p = (void *)&php_magic_database; in apprentice_map()
3008 map->len = (size_t)st.sb.st_size; in apprentice_map()
3009 if ((map->p = CAST(void *, emalloc(map->len))) == NULL) { in apprentice_map()
3010 file_oomem(ms, map->len); in apprentice_map()
3013 if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) { in apprentice_map()
3017 map->len = 0; in apprentice_map()
3024 ptr = (uint32_t *)(void *)map->p; in apprentice_map()
3048 map->p = emalloc(sizeof(php_magic_database)); in apprentice_map()
3049 map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database)); in apprentice_map()
3062 map->magic[0] = CAST(struct magic *, map->p) + 1; in apprentice_map()
3066 map->nmagic[i] = swap4(ptr[i + 2]); in apprentice_map()
3068 map->nmagic[i] = ptr[i + 2]; in apprentice_map()
3070 map->magic[i + 1] = map->magic[i] + map->nmagic[i]; in apprentice_map()
3071 nentries += map->nmagic[i]; in apprentice_map()
3080 byteswap(map->magic[i], map->nmagic[i]); in apprentice_map()
3085 return map; in apprentice_map()
3091 apprentice_unmap(map); in apprentice_map()
3099 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) in check_buffer() argument
3106 ptr = CAST(uint32_t *, map->p); in check_buffer()
3125 entries = (uint32_t)(map->len / sizeof(struct magic)); in check_buffer()
3126 if ((entries * sizeof(struct magic)) != map->len) { in check_buffer()
3129 dbname, map->len, sizeof(struct magic)); in check_buffer()
3132 map->magic[0] = CAST(struct magic *, map->p) + 1; in check_buffer()
3136 map->nmagic[i] = swap4(ptr[i + 2]); in check_buffer()
3138 map->nmagic[i] = ptr[i + 2]; in check_buffer()
3140 map->magic[i + 1] = map->magic[i] + map->nmagic[i]; in check_buffer()
3141 nentries += map->nmagic[i]; in check_buffer()
3150 byteswap(map->magic[i], map->nmagic[i]); in check_buffer()
3158 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3160 static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS; in apprentice_compile()
3161 static const size_t m = sizeof(**map->magic); in apprentice_compile()
3187 memcpy(hdr.h + 2, map->nmagic, nm); in apprentice_compile()
3195 len = m * map->nmagic[i]; in apprentice_compile()
3196 if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) { in apprentice_compile()