MCPcopy Create free account
hub / github.com/coreutils/coreutils / open_temp

Function open_temp

src/sort.c:1298–1340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1296 kind of failure. */
1297
1298static FILE *
1299open_temp (struct tempnode *temp)
1300{
1301 int tempfd, pipefds[2];
1302 FILE *fp = NULL;
1303
1304 if (temp->state == UNREAPED)
1305 wait_proc (temp->pid);
1306
1307 tempfd = open (temp->name, O_RDONLY);
1308 if (tempfd < 0)
1309 return NULL;
1310
1311 pid_t child;
1312 int result = pipe_child (&child, pipefds, tempfd, true,
1313 MAX_TRIES_DECOMPRESS);
1314
1315 if (result)
1316 {
1317 if (result != EMFILE)
1318 error (SORT_FAILURE, result, _("could not run compress program %s -d"),
1319 quoteaf (compress_program));
1320 close (tempfd);
1321 errno = EMFILE;
1322 }
1323 else
1324 {
1325 temp->pid = child;
1326 register_proc (temp);
1327 close (tempfd);
1328 close (pipefds[1]);
1329
1330 fp = fdopen (pipefds[0], "r");
1331 if (! fp)
1332 {
1333 int saved_errno = errno;
1334 close (pipefds[0]);
1335 errno = saved_errno;
1336 }
1337 }
1338
1339 return fp;
1340}
1341
1342/* Append DIR to the array of temporary directory names. */
1343static void

Callers 1

open_input_filesFunction · 0.85

Calls 3

wait_procFunction · 0.85
pipe_childFunction · 0.85
register_procFunction · 0.85

Tested by

no test coverage detected