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

Function cg_write

cg.c:80–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static void __attribute__((format(printf,2,3)))
81cg_write(const char *attr, const char *fmt, ...)
82{
83 int maybe = 0;
84 if (attr[0] == '?')
85 {
86 attr++;
87 maybe = 1;
88 }
89
90 va_list args;
91 va_start(args, fmt);
92
93 char buf[CG_BUFSIZE];
94 int n = vsnprintf(buf, sizeof(buf), fmt, args);
95 if (n >= CG_BUFSIZE)
96 die("cg_write: Value for attribute %s is too long", attr);
97
98 if (verbose > 1)
99 msg("CG: Write %s = %s", attr, buf);
100
101 char path[PATH_MAX];
102 cg_makepath(path, sizeof(path), attr);
103
104 int fd = open(path, O_WRONLY | O_TRUNC);
105 if (fd < 0)
106 {
107 if (maybe)
108 goto fail;
109 else
110 die("Cannot write %s: %m", path);
111 }
112
113 int written = write(fd, buf, n);
114 if (written < 0)
115 {
116 if (maybe)
117 goto fail_close;
118 else
119 die("Cannot set %s to %s: %m", path, buf);
120 }
121 if (written != n)
122 die("Short write to %s (%d out of %d bytes)", path, written, n);
123
124fail_close:
125 close(fd);
126fail:
127 va_end(args);
128}
129
130static FILE *cg_fopen(const char *attr)
131{

Callers 2

cg_enterFunction · 0.85
cg_removeFunction · 0.85

Calls 2

msgFunction · 0.85
cg_makepathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…