diff --git a/README.md b/README.md index e5ec908..5d82fdb 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,13 @@ char *strdup(const char *s); ``` Description: Returns a pointer to a new string which is a duplicate of the string s. +### 10. Isatty() +```cpp +int isatty(int fd); +``` +Description: Checks if the file is opened in interactive or non-interactive mode using the file descriptor. + + # Misc #### 1. size_t, ssize_t diff --git a/file_loc.c b/file_loc.c index a3aed56..28ca9b8 100644 --- a/file_loc.c +++ b/file_loc.c @@ -1,6 +1,6 @@ #include "main.h" -char * full_path; +//char *full_path; int startsWithForwardSlash(const char *str) @@ -54,6 +54,7 @@ char *get_file_loc(char *path, char *file_name) char *get_file_path(char *file_name) { char *path = getenv("PATH"); + char *full_path; if(startsWithForwardSlash(file_name) && access(file_name, X_OK) ==0) return (strdup(file_name)); if(!path) diff --git a/main.c b/main.c index 44ee4b5..2d4fdb2 100644 --- a/main.c +++ b/main.c @@ -14,13 +14,14 @@ int main(int argc, char *argv[]) while (1) { write(STDOUT_FILENO,"Dashed$ ",8); + if(isatty(STDIN_FILENO)) + write(STDOUT_FILENO, "Dashed$ ", 8); nread = getline(&buf, &count, stdin); if(nread == -1) { - perror("Exiting shell"); - exit(1); + exit(0); } - token = strtok(buf, "\n"); + token = strtok(buf, " \n"); array = malloc(sizeof(char *) * 1024); i = 0; while(token) diff --git a/main.h b/main.h index 76cf79b..100449a 100644 --- a/main.h +++ b/main.h @@ -10,7 +10,7 @@ #include -/* HElper Functions */ +/* Helper Functions */ char *get_file_path(char *file_name); char *get_file_loc(char *path, char *file_name); int startsWithForwardSlash(const char *str);