Skip to content

Instantly share code, notes, and snippets.

@scivision
Created February 14, 2023 17:12
Embed
What would you like to do?
execlp example, trying to do system call a bit more securely for Windows and Unix-like OS
#ifdef _WIN32
#include <process.h>
#else
#include <unistd.h>
#endif
int main(void)
{
int r;
#ifdef _WIN32
intptr_t ir = _execlp("cmd", "cmd", "/c", "dir", NULL);
r = (int)ir;
#else
r = execlp("ls", "ls", ".", NULL);
#endif
if(r != -1)
return 0;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment