Skip to content

Commit

Permalink
Implement getcwd on UEFI.
Browse files Browse the repository at this point in the history
  • Loading branch information
stikonas committed Dec 28, 2022
1 parent 2718459 commit 1b8dacd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
29 changes: 21 additions & 8 deletions amd64/uefi/uefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ char* _relative_path_to_absolute(char* narrow_string)
}
strcat(absolute_path, narrow_string);

return absolute_path;
}

char* _posix_path_to_uefi(char* narrow_string)
{
char* absolute_path = _relative_path_to_absolute(narrow_string);

unsigned length = strlen(absolute_path);
unsigned i;
for(i = 0; i < length; i += 1)
Expand All @@ -513,13 +520,6 @@ char* _relative_path_to_absolute(char* narrow_string)
}
}

return absolute_path;
}

char* _posix_path_to_uefi(char* narrow_string)
{
char* absolute_path = _relative_path_to_absolute(narrow_string);
unsigned length = strlen(absolute_path);
char* wide_string = _string2wide(absolute_path);
free(absolute_path);
return wide_string;
Expand Down Expand Up @@ -708,10 +708,10 @@ char* strchr(char const* str, int ch);
void _setup_current_working_directory(char** envp)
{
_cwd = calloc(__PATH_MAX, 1);
strcpy(_cwd, "/");

unsigned i = 0;
unsigned j;
unsigned k;
char* value;
char* match;

Expand All @@ -732,10 +732,23 @@ void _setup_current_working_directory(char** envp)
value = match + 1;
}
strcpy(_cwd, value);
k = 0;
while(_cwd[k] != '\0')
{
if(_cwd[k] == '\\')
{
_cwd[k] = '/';
}
k += 1;
}
}
envp[i][j] = '=';
i += 1;
}
if(strcmp(_cwd, "") == 0)
{
strcpy(_cwd, "/");
}
}

void* malloc(unsigned size);
Expand Down
16 changes: 3 additions & 13 deletions amd64/uefi/unistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,11 @@ int unlink(char* filename)
}


int _getcwd(char* buf, int size)
{
asm("lea_rdi,[rsp+DWORD] %16"
"mov_rdi,[rdi]"
"lea_rsi,[rsp+DWORD] %8"
"mov_rsi,[rsi]"
"mov_rax, %79"
"syscall");
}


char* getcwd(char* buf, unsigned size)
{
int c = _getcwd(buf, size);
if(0 == c) return NULL;
size_t length = strlen(_cwd);
if(length >= size) return NULL;
strcpy(buf, _cwd);
return buf;
}

Expand Down

0 comments on commit 1b8dacd

Please sign in to comment.