Skip to content

Instantly share code, notes, and snippets.

@davidfoerster
Created July 24, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfoerster/3df8b84a774d1a0ccb5a7b09e537ce9c to your computer and use it in GitHub Desktop.
Save davidfoerster/3df8b84a774d1a0ccb5a7b09e537ce9c to your computer and use it in GitHub Desktop.
Test expansion inside the value of the "PATH" environment variable by glibc
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if (argc <= 0)
abort();
if (argc == 1)
{
fprintf(stderr, "Usage: %s <command> [args...]\n", argv[0]);
return 2;
}
execvp(argv[1], &argv[1]);
fprintf(stderr, "%s: Can't execute \"%s\": %s\n",
argv[0], argv[1], strerror(errno));
return EXIT_FAILURE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment