Skip to content

Commit bf20b67

Browse files
committed
remove unnecessary Process util functions
1 parent 81712a8 commit bf20b67

1 file changed

Lines changed: 23 additions & 31 deletions

File tree

src/rcore.c

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,31 +4301,11 @@ struct rProcessData {
43014301
void *pipeStdoutRead; // Process stdout and stderr read pipe
43024302
void *pipeStdinWrite; // Process stdin write pipe
43034303
};
4304-
4305-
static bool CreatePipeWindows(void** readPipe, void** writePipe) {
4306-
struct _SECURITY_ATTRIBUTES sa = { 0 };
4307-
sa.nLength = sizeof(struct _SECURITY_ATTRIBUTES);
4308-
sa.bInheritHandle = 1;
4309-
sa.lpSecurityDescriptor = NULL;
4310-
return CreatePipe(readPipe, writePipe, &sa, 0) != 0;
4311-
}
4312-
4313-
static void CloseAllPipesWindows(void** pipes, int count) {
4314-
for (int i = 0; i < count; i++) {
4315-
if (pipes[i] != NULL) CloseHandle(pipes[i]);
4316-
}
4317-
}
43184304
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
43194305
struct rProcessData {
43204306
int pipefdStdout[2]; // Process stdout and stderr pipe file descriptors
43214307
int pipefdStdin[2]; // Process stdin pipe file descriptors
43224308
};
4323-
4324-
static void CloseAllPipesUnix(int* pipefds, int count) {
4325-
for (int i = 0; i < count; i++) {
4326-
if (pipefds[i] != -1) close(pipefds[i]);
4327-
}
4328-
}
43294309
#endif
43304310

43314311
// Initialize a new process, returns a Process struct
@@ -4361,15 +4341,22 @@ RLAPI Process InitProcess(const char *command, char *const args[])
43614341
// For stdout/stderr, read handles reserved for Raylib side, write handles passed to child process
43624342
// For stdin, write handle reserved for Raylib side, read handle passed to child process
43634343
// NOTE: stdout and stderr are merged into a single pipe
4364-
void *pipeStdoutRead, *pipeStdoutWrite;
4365-
void *pipeStdinRead, *pipeStdinWrite;
4344+
void *pipeStdoutRead = NULL, *pipeStdoutWrite = NULL;
4345+
void *pipeStdinRead = NULL, *pipeStdinWrite = NULL;
4346+
4347+
struct _SECURITY_ATTRIBUTES sa = { 0 };
4348+
sa.nLength = sizeof(struct _SECURITY_ATTRIBUTES);
4349+
sa.bInheritHandle = 1;
4350+
sa.lpSecurityDescriptor = NULL;
43664351

4367-
if ((!CreatePipeWindows(&pipeStdoutRead, &pipeStdoutWrite)) ||
4368-
(!CreatePipeWindows(&pipeStdinRead, &pipeStdinWrite)))
4352+
if ((!CreatePipe(&pipeStdoutRead, &pipeStdoutWrite, &sa, 0)) ||
4353+
(!CreatePipe(&pipeStdinRead, &pipeStdinWrite, &sa, 0)))
43694354
{
43704355
TRACELOG(LOG_WARNING, "PROCESS: Failed to create pipes for process I/O redirection");
43714356
void *pipes[] = { pipeStdoutRead, pipeStdoutWrite, pipeStdinRead, pipeStdinWrite };
4372-
CloseAllPipesWindows(pipes, sizeof(pipes) / sizeof(pipes[0]));
4357+
for (int i = 0; i < 4; i++) {
4358+
if (pipes[i] != NULL) CloseHandle(pipes[i]);
4359+
}
43734360
return process;
43744361
}
43754362

@@ -4412,7 +4399,9 @@ RLAPI Process InitProcess(const char *command, char *const args[])
44124399
(pipe(&pipefd[2]) == -1))
44134400
{
44144401
TRACELOG(LOG_WARNING, "PROCESS: Failed to create pipes");
4415-
CloseAllPipesUnix(pipefd, 4);
4402+
for (int i = 0; i < 4; i++) {
4403+
if (pipefd[i] != -1) close(pipefd[i]);
4404+
}
44164405
return process;
44174406
}
44184407

@@ -4425,8 +4414,10 @@ RLAPI Process InitProcess(const char *command, char *const args[])
44254414
if (pid < 0)
44264415
{
44274416
TRACELOG(LOG_WARNING, "PROCESS: Failed to create process");
4428-
CloseAllPipesUnix(pipefd, 4);
4417+
4418+
for (int i = 0; i < 4; i++) close(pipefd[i]);
44294419
RL_FREE(process.processData);
4420+
44304421
return process;
44314422
}
44324423
else if (pid == 0)
@@ -4786,8 +4777,8 @@ RLAPI void CloseProcess(Process process)
47864777
CloseHandle(hProcess);
47874778

47884779
// Clean up pipes
4789-
void *pipes[] = { process.processData->pipeStdoutRead, process.processData->pipeStdinWrite };
4790-
CloseAllPipesWindows(pipes, sizeof(pipes) / sizeof(pipes[0]));
4780+
if (process.processData->pipeStdoutRead != NULL) CloseHandle(process.processData->pipeStdoutRead);
4781+
if (process.processData->pipeStdinWrite != NULL) CloseHandle(process.processData->pipeStdinWrite);
47914782

47924783
RL_FREE(process.processData);
47934784

@@ -4813,8 +4804,9 @@ RLAPI void CloseProcess(Process process)
48134804
// Wait process termination
48144805
waitpid(process.pid, NULL, 0);
48154806

4816-
int pipefd[2] = { process.processData->pipefdStdout[0], process.processData->pipefdStdin[1] };
4817-
CloseAllPipesUnix(pipefd, 2);
4807+
close(process.processData->pipefdStdout[0]);
4808+
close(process.processData->pipefdStdin[1]);
4809+
48184810
RL_FREE(process.processData);
48194811
#else
48204812
TRACELOG(LOG_WARNING, "PROCESS: Process management not supported on this platform");

0 commit comments

Comments
 (0)