MCPcopy Create free account
hub / github.com/ElementsProject/lightning / grab

Function grab

ccan/ccan/ptr_valid/ptr_valid.c:14–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13#if HAVE_PROC_SELF_MAPS
14static char *grab(const char *filename)
15{
16 int ret, fd;
17 size_t max = 16384, s = 0;
18 char *buffer;
19
20 fd = open(filename, O_RDONLY);
21 if (fd < 0)
22 return NULL;
23
24 buffer = malloc(max+1);
25 if (!buffer)
26 goto close;
27
28 while ((ret = read(fd, buffer + s, max - s)) > 0) {
29 s += ret;
30 if (s == max) {
31 buffer = realloc(buffer, max*2+1);
32 if (!buffer)
33 goto close;
34 max *= 2;
35 }
36 }
37 if (ret < 0)
38 goto free;
39
40 close(fd);
41 buffer[s] = '\0';
42 return buffer;
43
44free:
45 free(buffer);
46close:
47 close_noerr(fd);
48 return NULL;
49}
50
51static char *skip_line(char *p)
52{

Callers 1

get_proc_mapsFunction · 0.85

Calls 1

close_noerrFunction · 0.85

Tested by

no test coverage detected