libc: Add dummy getcwd()

This commit is contained in:
apio 2022-10-24 17:05:28 +02:00
parent e7d41fa6dc
commit 0dec5f7bad
5 changed files with 21 additions and 0 deletions

View File

@ -16,5 +16,6 @@
#define EMFILE 24
#define ENOTTY 25
#define ENOSPC 28
#define ERANGE 36
#define ENOSYS 38
#define ENOTSUP 95

View File

@ -21,6 +21,7 @@ extern int errno;
#define ENOTTY 25 // Inappropriate ioctl for device
#define ENOSPC 28 // No space left on device
#define EPIPE 32 // Broken pipe. Not implemented.
#define ERANGE 34 // Numerical result out of range
#define ENOSYS 38 // Function not implemented
#define ENOTSUP 95 // Operation not supported

View File

@ -69,6 +69,9 @@ extern "C"
/* Checks if the file descriptor fd refers to a terminal. */
int isatty(int fd);
/* Writes the current process's current working directory to buf. */
char* getcwd(char* buf, size_t size);
#ifdef __cplusplus
}
#endif

View File

@ -274,6 +274,7 @@ extern "C"
case ENOTTY: return "Inappropriate ioctl for device";
case ENOSPC: return "No space left on device";
case EPIPE: return "Broken pipe";
case ERANGE: return "Numerical result out of range";
case ENOSYS: return "Function not implemented";
case ENOTSUP: return "Operation not supported";
case 0: return "Success";

View File

@ -1,5 +1,8 @@
#include <errno.h>
#include <fcntl.h>
#include <luna.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
@ -81,4 +84,16 @@ extern "C"
if (result < 0) return 0;
return 1;
}
char* getcwd(char* buf, size_t size)
{
const char* dummy_cwd = "/"; // FIXME: Actually retrieve the current working directory from the kernel.
if (size < 2)
{
errno = ERANGE;
return NULL;
}
if (!buf) { buf = (char*)malloc(size); }
strlcpy(buf, dummy_cwd, 2);
}
}