I'm trying to make my own cd command. When I try to run :
Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char path[sizeof(argv)];
if( strcpy(path, argv[1]) < 0)
printf("error converting argv to string\n");
else
printf("argv converted to string\n");
if (argc != 2)
printf("Input error");
else
if (chdir(path) < 0)
printf("FAILURE\n");
else
printf("SUCCESS\n");
char cwd[1024];
if (getcwd(cwd, sizeof(cwd)) != NULL)
fprintf(stdout, "You are in %s\n", cwd);
exit(0);
}
It works for any existing subdirectory and ".."(as in move up one level).
However if I try to cd to any directory that does not exist or any directory that is above the current directory, I get the error Abort Trap. I have no idea what that means, this error is not listed in the man pages for either strcpy() or chdir() which is where i would assume the error to be happening.
Any help will be appreciated.