aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/getcwd.c
blob: 95008bb26875d410df09e967182667fb6d75ef5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * getcwd.c
 */

#include <syslinux/config.h>
#include <klibc/compiler.h>
#include <com32.h>

#include <dirent.h>
#include <stdio.h>
#include <errno.h>

char *getcwd(char *buf, size_t size)
{
	static com32sys_t reg;
	char *pwdstr, *ret;

	reg.eax.w[0] = 0x001f;
	__intcall(0x22, &reg, &reg);
	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;
}