summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>1999-09-17 08:35:08 +0000
committermarcel <marcel@FreeBSD.org>1999-09-17 08:35:08 +0000
commitbae502690e008a4ff0f04d687620a5f49efc97ad (patch)
tree69a00b836538d383914877298bebcd300f546b25 /sys
parent246bb5b220f7755b104251f4bd3c79bd39a687a3 (diff)
downloadFreeBSD-src-bae502690e008a4ff0f04d687620a5f49efc97ad.zip
FreeBSD-src-bae502690e008a4ff0f04d687620a5f49efc97ad.tar.gz
Fix getcwd. It must return the length of the path including the terminating 0.
While I'm here, fix style and debug printf. Fix derived from patch by: Darryl Okahata <darrylo@sr.hp.com>
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/linux/linux_file.c25
-rw-r--r--sys/i386/linux/linux_file.c25
2 files changed, 38 insertions, 12 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index b0e8a36..66e9312 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -855,14 +855,27 @@ linux_link(struct proc *p, struct linux_link_args *args)
int
linux_getcwd(struct proc *p, struct linux_getcwd_args *args)
{
- struct __getcwd_args bsd;
+ struct __getcwd_args bsd;
+ caddr_t sg;
+ int error, len;
#ifdef DEBUG
- printf("Linux-emul(%d): getcwd(%p, %ld)\n",
- p->p_pid, args->buf, args->bufsize);
+ printf("Linux-emul(%ld): getcwd(%p, %ld)\n", (long)p->p_pid,
+ args->buf, args->bufsize);
#endif
- bsd.buf = args->buf;
- bsd.buflen = args->bufsize;
- return __getcwd(p, &bsd);
+ sg = stackgap_init();
+ bsd.buf = stackgap_alloc(&sg, SPARE_USRSPACE);
+ bsd.buflen = SPARE_USRSPACE;
+ error = __getcwd(p, &bsd);
+ if (!error) {
+ len = strlen(bsd.buf) + 1;
+ if (len <= args->bufsize) {
+ p->p_retval[0] = len;
+ error = copyout(bsd.buf, args->buf, len);
+ }
+ else
+ error = ERANGE;
+ }
+ return (error);
}
diff --git a/sys/i386/linux/linux_file.c b/sys/i386/linux/linux_file.c
index b0e8a36..66e9312 100644
--- a/sys/i386/linux/linux_file.c
+++ b/sys/i386/linux/linux_file.c
@@ -855,14 +855,27 @@ linux_link(struct proc *p, struct linux_link_args *args)
int
linux_getcwd(struct proc *p, struct linux_getcwd_args *args)
{
- struct __getcwd_args bsd;
+ struct __getcwd_args bsd;
+ caddr_t sg;
+ int error, len;
#ifdef DEBUG
- printf("Linux-emul(%d): getcwd(%p, %ld)\n",
- p->p_pid, args->buf, args->bufsize);
+ printf("Linux-emul(%ld): getcwd(%p, %ld)\n", (long)p->p_pid,
+ args->buf, args->bufsize);
#endif
- bsd.buf = args->buf;
- bsd.buflen = args->bufsize;
- return __getcwd(p, &bsd);
+ sg = stackgap_init();
+ bsd.buf = stackgap_alloc(&sg, SPARE_USRSPACE);
+ bsd.buflen = SPARE_USRSPACE;
+ error = __getcwd(p, &bsd);
+ if (!error) {
+ len = strlen(bsd.buf) + 1;
+ if (len <= args->bufsize) {
+ p->p_retval[0] = len;
+ error = copyout(bsd.buf, args->buf, len);
+ }
+ else
+ error = ERANGE;
+ }
+ return (error);
}
OpenPOWER on IntegriCloud