Skip to content

Commit

Permalink
cwd: implemented getcwd()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 1, 2024
1 parent e03e7c3 commit 3c524ea
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ int chdir(Thread *t, uint16_t id, const char *path) {
}

return requestServer(t, &cmd);
}

/* getcwd(): returns the current working directory of the running process
* params: t - running thread
* params: buf - buffer to store the path in
* params: len - length of the buffer
* returns: pointer to buffer on success, negative error code on fail
*/

char *getcwd(Thread *t, char *buf, size_t len) {
Process *p = getProcess(t->pid);
if(!p) return (char *) -ESRCH;
if(!len) return (char *) -EINVAL;
if(len < (strlen(p->cwd) + 1)) return (char *) -ERANGE;

return strcpy(buf, p->cwd);
}

0 comments on commit 3c524ea

Please sign in to comment.