/* * Open the map file and allocate a structure to manage it. * * We create a private mapping because we want to terminate the log tag * strings with '\0'. */ EventTagMap* android_openEventTagMap(const char* fileName) { EventTagMap* newTagMap; off_t end; int fd = -1; newTagMap = calloc(1, sizeof(EventTagMap)); if (newTagMap == NULL) return NULL; fd = open(fileName, O_RDONLY); if (fd < 0) { fprintf(stderr, "%s: unable to open map '%s': %s\n", OUT_TAG, fileName, strerror(errno)); goto fail; } end = lseek(fd, 0L, SEEK_END); (void) lseek(fd, 0L, SEEK_SET); if (end < 0) { fprintf(stderr, "%s: unable to seek map '%s'\n", OUT_TAG, fileName); goto fail; } newTagMap->mapAddr = mmap(NULL, end, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (newTagMap->mapAddr == MAP_FAILED) { fprintf(stderr, "%s: mmap(%s) failed: %s\n", OUT_TAG, fileName, strerror(errno)); goto fail; } newTagMap->mapLen = end; if (processFile(newTagMap) != 0) goto fail; return newTagMap; fail: android_closeEventTagMap(newTagMap); if (fd >= 0) close(fd); return NULL; }
/* * Open the map file and allocate a structure to manage it. * * We create a private mapping because we want to terminate the log tag * strings with '\0'. */ EventTagMap* android_openEventTagMap(const char* fileName) { EventTagMap* newTagMap; off_t end; int fd = -1; newTagMap = calloc(1, sizeof(EventTagMap)); if (newTagMap == NULL) return NULL; fd = open(fileName, O_RDONLY); if (fd < 0) { goto fail; } end = lseek(fd, 0L, SEEK_END); (void) lseek(fd, 0L, SEEK_SET); if (end < 0) { goto fail; } newTagMap->mapAddr = mmap(NULL, end, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (newTagMap->mapAddr == MAP_FAILED) { goto fail; } newTagMap->mapLen = end; if (processFile(newTagMap) != 0) goto fail; if (fd >= 0) close(fd); return newTagMap; fail: android_closeEventTagMap(newTagMap); if (fd >= 0) close(fd); return NULL; }