MCPcopy Create free account
hub / github.com/coreboot/coreboot / do_shell

Function do_shell

util/kconfig/preprocess.c:141–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141static char *do_shell(int argc, char *argv[])
142{
143 FILE *p;
144 char buf[4096];
145 char *cmd;
146 size_t nread;
147 int i;
148
149 cmd = argv[0];
150
151 p = popen(cmd, "r");
152 if (!p) {
153 perror(cmd);
154 exit(1);
155 }
156
157 nread = fread(buf, 1, sizeof(buf), p);
158 if (nread == sizeof(buf))
159 nread--;
160
161 /* remove trailing new lines */
162 while (nread > 0 && buf[nread - 1] == '\n')
163 nread--;
164
165 buf[nread] = 0;
166
167 /* replace a new line with a space */
168 for (i = 0; i < nread; i++) {
169 if (buf[i] == '\n')
170 buf[i] = ' ';
171 }
172
173 if (pclose(p) == -1) {
174 perror(cmd);
175 exit(1);
176 }
177
178 return xstrdup(buf);
179}
180
181static char *do_warning_if(int argc, char *argv[])
182{

Callers

nothing calls this directly

Calls 4

perrorFunction · 0.85
exitFunction · 0.85
freadFunction · 0.85
xstrdupFunction · 0.85

Tested by

no test coverage detected