Skip to content

Commit

Permalink
ls -la Works
Browse files Browse the repository at this point in the history
  • Loading branch information
sameepkat committed Aug 2, 2024
1 parent eebb4d7 commit 1c4c171
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion file_loc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "main.h"

char * full_path;
//char *full_path;


int startsWithForwardSlash(const char *str)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string.h>


/* 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);
Expand Down

0 comments on commit 1c4c171

Please sign in to comment.