Lines Matching refs:map

119  	mlp->map = NULL;
124 ml->map = idx == 0 ? map : NULL;
174 apprentice_unmap(struct magic_map *map)
177 if (map == NULL)
180 - switch (map->type) {
185 - void *b = map->magic[i];
186 - void *p = map->p;
188 - CAST(char *, b) <= CAST(char *, p) + map->len)
190 - free(map->magic[i]);
191 + if (map->p != php_magic_database) {
192 + if (map->p == NULL) {
195 + if (map->magic[j]) {
196 + efree(map->magic[j]);
200 + efree(map->p);
202 - free(map->p);
206 - if (map->p && map->p != MAP_FAILED)
207 - (void)munmap(map->p, map->len);
213 - free(map);
214 + efree(map);
228 if (ml->map)
229 apprentice_unmap(CAST(struct magic_map *, ml->map));
247 - struct magic_map *map;
265 - map = apprentice_buf(ms, bufs[i], sizes[i]);
266 - if (map == NULL)
270 - if (add_mlist(ms->mlist[j], map, j) == -1) {
417 struct magic_map *map;
429 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL)
430 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL)
432 file_oomem(ms, sizeof(*map));
605 - struct magic_map *map;
607 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
608 - file_oomem(ms, sizeof(*map));
611 - map->len = len;
612 - map->p = buf;
613 - map->type = MAP_TYPE_USER;
614 - if (check_buffer(ms, map, "buffer") != 0) {
615 - apprentice_unmap(map);
618 - return map;
634 struct magic_map *map;
643 - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
644 + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
645 file_oomem(ms, sizeof(*map));
649 - map->type = MAP_TYPE_USER; /* unspecified */
652 + map->p = (void *)&php_magic_database;
692 - map->len = CAST(size_t, st.st_size);
694 - map->type = MAP_TYPE_MMAP;
695 - if ((map->p = mmap(0, CAST(size_t, st.st_size), PROT_READ|PROT_WRITE,
697 - file_error(ms, errno, "cannot map `%s'", dbname);
701 map->type = MAP_TYPE_MALLOC;
702 - if ((map->p = CAST(void *, malloc(map->len))) == NULL) {
703 - file_oomem(ms, map->len);
706 - if (read(fd, map->p, map->len) != (ssize_t)map->len) {
713 + map->len = CAST(size_t, st.sb.st_size);
714 + map->p = CAST(void *, emalloc(map->len));
716 - if (check_buffer(ms, map, dbname) != 0) {
720 - if (mprotect(map->p, CAST(size_t, st.st_size), PROT_READ) == -1) {
722 + if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) {
729 - return map;
734 - apprentice_unmap(map);
740 -check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
749 - ptr = CAST(uint32_t *, map->p);
751 + ptr = (uint32_t *)(void *)map->p;
772 - entries = CAST(uint32_t, map->len / sizeof(struct magic));
773 - if ((entries * sizeof(struct magic)) != map->len) {
776 - dbname, map->len, sizeof(struct magic));
783 + map->p = emalloc(sizeof(php_magic_database));
784 + map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database));
797 map->magic[0] = CAST(struct magic *, map->p) + 1;
800 map->magic[i + 1] = map->magic[i] + map->nmagic[i];
801 nentries += map->nmagic[i];
812 byteswap(map->magic[i], map->nmagic[i]);
818 + return map;
824 + apprentice_unmap(map);
834 static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
835 static const size_t m = sizeof(**map->magic);
862 memcpy(hdr.h + 2, map->nmagic, nm);
872 len = m * map->nmagic[i];
873 - if (write(fd, map->magic[i], len) != CAST(ssize_t, len)) {
874 + if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) {
889 - apprentice_unmap(map);