libclod
C library for interacting with NBTs, region files, LOD data and other things.
Loading...
Searching...
No Matches
region_read.c
1#include <clod/region.h>
2#include "region_impl.h"
3#include "region_file.h"
4#include "error.h"
5
7 struct clod_region *region,
8 const int64_t *pos,
9 uint8_t *,
10 size_t,
11 size_t *
12) {
13 REGION_PUBLIC_ENTER(region);
14
15 mutex_lock(&region->mtx);
16
17 struct region_file *rf;
18 auto res = region_file_get(region, &rf, pos, false);
19 if (res != CLOD_REGION_OK) {
20 mutex_unlock(&region->mtx);
21 REGION_PUBLIC_LEAVE(region);
22 return res;
23 }
24
25 rwmutex_rdlock(&rf->mtx);
26 mutex_unlock(&region->mtx);
27
28 uint8_t *data;
29 size_t size;
30 res = file_get(rf->f, (void**)&data, &size);
31 if (res != CLOD_REGION_OK) {
32 rwmutex_rdunlock(&rf->mtx);
33 REGION_PUBLIC_LEAVE(region);
34 return res;
35 }
36
37 REGION_PUBLIC_LEAVE(region);
38 return res;
39}
enum clod_region_result clod_region_read(struct clod_region *region, const int64_t *pos, uint8_t *, size_t, size_t *)
Definition region_read.c:6
clod_region_result
Definition region.h:43
@ CLOD_REGION_OK
Definition region.h:45