RSRegion* rs_region_open(const char* path, bool write) { RSRegion* self; struct stat stat_buf; void* map = NULL; int fd = open(path, write ? (O_RDWR | O_CREAT) : O_RDONLY, 0666); if (fd < 0) { return NULL; /* TODO proper error handling */ } if (fstat(fd, &stat_buf) < 0) { close(fd); return NULL; } /* zero size is valid, but anything between 0 and 8192 isn't */ if (stat_buf.st_size > 0 && stat_buf.st_size < 8192) { close(fd); return NULL; } if (stat_buf.st_size > 0) { map = mmap(NULL, stat_buf.st_size, write ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { close(fd); return NULL; } } self = rs_new0(RSRegion, 1); self->path = rs_strdup(path); self->write = write; self->fd = fd; self->fsize = stat_buf.st_size; self->map = map; self->cached_writes = NULL; self->locations = NULL; self->timestamps = NULL; if (self->map) { self->locations = (struct ChunkLocation*)(self->map); self->timestamps = (uint32_t*)(self->map + 4096); } return self; }
RSList* rs_list_cell_new(void) { RSList* cell = rs_new0(RSList, 1); return cell; }