From 13d9e61a674ba8dbc03f64563e83527606af54cc Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Fri, 17 Sep 1999 08:35:08 +0000 Subject: 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 --- sys/compat/linux/linux_file.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'sys/compat') diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index b0e8a367c83a..66e9312ed6b7 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); } -- cgit v1.2.3