Lines Matching refs:map

117  	mlp->map = NULL;
122 ml->map = idx == 0 ? map : NULL;
172 apprentice_unmap(struct magic_map *map)
175 if (map == NULL)
178 - switch (map->type) {
183 - void *b = map->magic[i];
184 - void *p = map->p;
186 - CAST(char *, b) <= CAST(char *, p) + map->len)
188 - free(map->magic[i]);
189 + if (map->p != php_magic_database) {
190 + if (map->p == NULL) {
193 + if (map->magic[j]) {
194 + efree(map->magic[j]);
198 + efree(map->p);
200 - free(map->p);
204 - if (map->p && map->p != MAP_FAILED)
205 - (void)munmap(map->p, map->len);
211 - free(map);
212 + efree(map);
226 if (ml->map)
227 apprentice_unmap(CAST(struct magic_map *, ml->map));
245 - struct magic_map *map;
263 - map = apprentice_buf(ms, bufs[i], sizes[i]);
264 - if (map == NULL)
268 - if (add_mlist(ms->mlist[j], map, j) == -1) {
415 struct magic_map *map;
427 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL)
428 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL)
430 file_oomem(ms, sizeof(*map));
603 - struct magic_map *map;
605 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
606 - file_oomem(ms, sizeof(*map));
609 - map->len = len;
610 - map->p = buf;
611 - map->type = MAP_TYPE_USER;
612 - if (check_buffer(ms, map, "buffer") != 0) {
613 - apprentice_unmap(map);
616 - return map;
632 struct magic_map *map;
641 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
642 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
643 file_oomem(ms, sizeof(*map));
647 - map->type = MAP_TYPE_USER; /* unspecified */
650 + map->p = (void *)&php_magic_database;
690 - map->len = CAST(size_t, st.st_size);
692 - map->type = MAP_TYPE_MMAP;
693 - if ((map->p = mmap(0, CAST(size_t, st.st_size), PROT_READ|PROT_WRITE,
695 - file_error(ms, errno, "cannot map `%s'", dbname);
699 map->type = MAP_TYPE_MALLOC;
700 - if ((map->p = CAST(void *, malloc(map->len))) == NULL) {
701 - file_oomem(ms, map->len);
704 - if (read(fd, map->p, map->len) != (ssize_t)map->len) {
711 + map->len = CAST(size_t, st.sb.st_size);
712 + map->p = CAST(void *, emalloc(map->len));
714 - if (check_buffer(ms, map, dbname) != 0) {
718 - if (mprotect(map->p, CAST(size_t, st.st_size), PROT_READ) == -1) {
720 + if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) {
727 - return map;
732 - apprentice_unmap(map);
738 -check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
747 - ptr = CAST(uint32_t *, map->p);
749 + ptr = (uint32_t *)(void *)map->p;
770 - entries = CAST(uint32_t, map->len / sizeof(struct magic));
771 - if ((entries * sizeof(struct magic)) != map->len) {
774 - dbname, map->len, sizeof(struct magic));
781 + map->p = emalloc(sizeof(php_magic_database));
782 + map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database));
795 map->magic[0] = CAST(struct magic *, map->p) + 1;
798 map->magic[i + 1] = map->magic[i] + map->nmagic[i];
799 nentries += map->nmagic[i];
810 byteswap(map->magic[i], map->nmagic[i]);
816 + return map;
822 + apprentice_unmap(map);
832 static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
833 static const size_t m = sizeof(**map->magic);
860 memcpy(hdr.h + 2, map->nmagic, nm);
870 len = m * map->nmagic[i];
871 - if (write(fd, map->magic[i], len) != CAST(ssize_t, len)) {
872 + if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
887 - apprentice_unmap(map);