Lines Matching refs:map

117  	mlp->map = NULL;
122 ml->map = idx == 0 ? map : NULL;
126 struct magic_map *map;
135 return apprentice_compile(ms, map, fn);
139 map = apprentice_map(ms, fn);
140 if (map == (struct magic_map *)-1)
142 if (map == NULL) {
145 - map = apprentice_load(ms, fn, action);
149 + map = apprentice_load(ms, fn, action);
151 if (map == NULL)
213 apprentice_unmap(struct magic_map *map)
216 if (map == NULL)
219 - switch (map->type) {
224 - void *b = map->magic[i];
225 - void *p = map->p;
227 - CAST(char *, b) <= CAST(char *, p) + map->len)
229 - free(map->magic[i]);
230 + if (map->p != php_magic_database) {
231 + if (map->p == NULL) {
234 + if (map->magic[j]) {
235 + efree(map->magic[j]);
239 + efree(map->p);
241 - free(map->p);
245 - if (map->p && map->p != MAP_FAILED)
246 - (void)munmap(map->p, map->len);
252 - free(map);
253 + efree(map);
267 if (ml->map)
268 apprentice_unmap(CAST(struct magic_map *, ml->map));
284 - struct magic_map *map;
303 - map = apprentice_buf(ms, bufs[i], sizes[i]);
304 - if (map == NULL)
308 - if (add_mlist(ms->mlist[j], map, j) == -1) {
458 struct magic_map *map;
470 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL)
471 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL)
473 file_oomem(ms, sizeof(*map));
637 struct magic_map *map;
639 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
640 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
641 file_oomem(ms, sizeof(*map));
654 struct magic_map *map;
663 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
664 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
665 file_oomem(ms, sizeof(*map));
669 - map->type = MAP_TYPE_USER; /* unspecified */
672 + map->p = (void *)&php_magic_database;
710 - map->len = (size_t)st.st_size;
712 - map->type = MAP_TYPE_MMAP;
713 - if ((map->p = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
715 - file_error(ms, errno, "cannot map `%s'", dbname);
719 - map->type = MAP_TYPE_MALLOC;
720 - if ((map->p = CAST(void *, malloc(map->len))) == NULL) {
721 + map->len = (size_t)st.sb.st_size;
722 + if ((map->p = CAST(void *, emalloc(map->len))) == NULL) {
723 file_oomem(ms, map->len);
726 - if (read(fd, map->p, map->len) != (ssize_t)map->len) {
727 + if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) {
731 + map->len = 0;
737 - if (check_buffer(ms, map, dbname) != 0) {
743 + ptr = (uint32_t *)(void *)map->p;
763 - if (mprotect(map->p, (size_t)st.st_size, PROT_READ) == -1) {
770 + map->p = emalloc(sizeof(php_magic_database));
771 + map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database));
784 + map->magic[0] = CAST(struct magic *, map->p) + 1;
788 + map->nmagic[i] = swap4(ptr[i + 2]);
790 + map->nmagic[i] = ptr[i + 2];
792 + map->magic[i + 1] = map->magic[i] + map->nmagic[i];
793 + nentries += map->nmagic[i];
803 + byteswap(map->magic[i], map->nmagic[i]);
809 return map;
817 apprentice_unmap(map);
838 static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
839 static const size_t m = sizeof(**map->magic);
866 memcpy(hdr.h + 2, map->nmagic, nm);
875 len = m * map->nmagic[i];
876 - if (write(fd, map->magic[i], len) != (ssize_t)len) {
877 + if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
890 - apprentice_unmap(map);