Shows basic error message formatting
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <error.h>
int main(int argc, const char* argv[])
{
const char* badpath = "!#$%^&/";
execlp(badpath, badpath, NULL);
perror("Exec failed");
if(open(badpath, 0) == -1)
{
int error = errno;
char buffer[1024] = {'\0'};
const char* msg = strerror_r(error, buffer, 1024);
printf("Exec failed with error code %d = '%s'\n", error, msg);
}
if(creat(badpath, O_CREAT) < 0)
{
int error = errno;
error_at_line(
0,
error,
__FILE__,
__LINE__,
"Exec of '%s' failed",
badpath
);
}
return 0;
}