Commit ba57be4e authored by Noah Loomans's avatar Noah Loomans
Browse files

directories are not executables

This can be reproduced using `./.`. It errors when trying to execute
while it should not even return it as an executable in the first place.
parent cff93e34
......@@ -13,23 +13,25 @@
#include <unistd.h>
#include <libft.h>
#include <ft_printf.h>
#include <sys/stat.h>
#include "env.h"
#include "path.h"
static struct s_program get_executable(char *pathname)
struct s_program program;
struct stat statbuf;
struct s_program program;
ft_memset(&program, '\0', sizeof(struct s_program));
if (access(pathname, X_OK) == 0)
if (stat(pathname, &statbuf) == -1)
program.type = NOTFOUND;
else if (S_ISREG(statbuf.st_mode) && access(pathname, X_OK) == 0)
program.type = EXECUTABLE;
ft_strncpy(program.pathname, pathname, PATH_MAX);
program.type = NOTFOUND;
return (program);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment