getcwd: Return proper error codes.
authorStathis Kamperis <beket@dragonflybsd.org>
Fri, 11 Sep 2009 14:56:57 +0000 (17:56 +0300)
committerStathis Kamperis <beket@dragonflybsd.org>
Fri, 11 Sep 2009 15:03:17 +0000 (18:03 +0300)
Dragonfly-bug: http://bugs.dragonflybsd.org/issue1394
Reported-by: hasso@
sys/kern/vfs_cache.c

index 7af6f24..bfdd17d 100644 (file)
@@ -2421,7 +2421,7 @@ sys___getcwd(struct __getcwd_args *uap)
                return (ENODEV);
 
        buflen = uap->buflen;
-       if (buflen < 2)
+       if (buflen == 0)
                return (EINVAL);
        if (buflen > MAXPATHLEN)
                buflen = MAXPATHLEN;
@@ -2470,14 +2470,14 @@ kern_getcwd(char *buf, size_t buflen, int *error)
                for (i = nch.ncp->nc_nlen - 1; i >= 0; i--) {
                        if (bp == buf) {
                                numcwdfail4++;
-                               *error = ENOMEM;
+                               *error = ERANGE;
                                return(NULL);
                        }
                        *--bp = nch.ncp->nc_name[i];
                }
                if (bp == buf) {
                        numcwdfail4++;
-                       *error = ENOMEM;
+                       *error = ERANGE;
                        return(NULL);
                }
                *--bp = '/';
@@ -2497,7 +2497,7 @@ kern_getcwd(char *buf, size_t buflen, int *error)
        if (!slash_prefixed) {
                if (bp == buf) {
                        numcwdfail4++;
-                       *error = ENOMEM;
+                       *error = ERANGE;
                        return(NULL);
                }
                *--bp = '/';