MCPcopy Create free account
hub / github.com/ioi/isolate / cg_read

Function cg_read

cg.c:35–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35static int
36cg_read(const char *attr, char *buf)
37{
38 int result = 0;
39 int maybe = 0;
40 if (attr[0] == '?')
41 {
42 attr++;
43 maybe = 1;
44 }
45
46 char path[PATH_MAX];
47 cg_makepath(path, sizeof(path), attr);
48
49 int fd = open(path, O_RDONLY);
50 if (fd < 0)
51 {
52 if (maybe)
53 goto fail;
54 die("Cannot read %s: %m", path);
55 }
56
57 int n = read(fd, buf, CG_BUFSIZE);
58 if (n < 0)
59 {
60 if (maybe)
61 goto fail_close;
62 die("Cannot read %s: %m", path);
63 }
64 if (n >= CG_BUFSIZE - 1)
65 die("Attribute %s too long", path);
66 if (n > 0 && buf[n-1] == '\n')
67 n--;
68 buf[n] = 0;
69
70 if (verbose > 1)
71 msg("CG: Read %s = <%s>\n", attr, buf);
72
73 result = 1;
74fail_close:
75 close(fd);
76fail:
77 return result;
78}
79
80static void __attribute__((format(printf,2,3)))
81cg_write(const char *attr, const char *fmt, ...)

Callers 1

cg_statsFunction · 0.85

Calls 2

cg_makepathFunction · 0.85
msgFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…