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

Function grab

ccan/ccan/ptr_valid/ptr_valid.c:14–50  ·  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 char *nb = realloc(buffer, max*2+1);
32 if (!nb)
33 goto free;
34 buffer = nb;
35 max *= 2;
36 }
37 }
38 if (ret < 0)
39 goto free;
40
41 close(fd);
42 buffer[s] = '\0';
43 return buffer;
44
45free:
46 free(buffer);
47close:
48 close_noerr(fd);
49 return NULL;
50}
51
52static char *skip_line(char *p)
53{

Callers 1

get_proc_mapsFunction · 0.70

Calls 1

close_noerrFunction · 0.85

Tested by

no test coverage detected