Implement getcwd() in the core; Fix COM32 getcwd() to use the new function.
This resolves the previous comment about COM32 getcwd() not working by
not using INT 22h AX=001Fh.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
void (*reset_idle)(void);
int (*chdir)(const char *);
+ char *(*getcwd)(char *, size_t);
};
#endif /* _SYSLINUX_PMAPI_H */
* getcwd.c
*/
-#include <syslinux/config.h>
-#include <klibc/compiler.h>
#include <com32.h>
-
-#include <dirent.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
+#include <syslinux/pmapi.h>
char *getcwd(char *buf, size_t size)
{
- static com32sys_t reg;
- char *pwdstr, *ret;
-
- reg.eax.w[0] = 0x001f;
- __intcall(0x22, ®, ®);
- pwdstr = MK_PTR(reg.es, reg.ebx.w[0]);
- if ((strlen(pwdstr) < size) && (buf != NULL)) {
- strcpy(buf, pwdstr);
- ret = buf;
- } else {
- ret = NULL;
- errno = ERANGE;
- }
- return ret;
+ return __com32.cs_pm->getcwd(buf, size);
}
--- /dev/null
+#include <string.h>
+#include "fs.h"
+
+char *getcwd(char *buf, size_t size)
+{
+ char *ret = NULL;
+
+ if((buf != NULL) && (strlen(this_fs->cwd_name) < size)) {
+ strcpy(buf, this_fs->cwd_name);
+ ret = buf;
+ }
+ return ret;
+}
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);
+/* getcwd.c */
+char *getcwd(char *buf, size_t size);
+
/*
* Generic functions that filesystem drivers may choose to use
*/
.reset_idle = reset_idle,
.chdir = chdir,
+ .getcwd = getcwd,
};