From d86e0bcc0c2ce3bcdccce735edeaacb42ef49a20 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 9 Jun 2002 00:46:24 +0000 Subject: Check the return value of getcwd() to avoid printf()ing a NULL. Mark usage() as __dead2 to avoid a GCC warning. Spotted by: keramida --- bin/realpath/realpath.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bin/realpath') diff --git a/bin/realpath/realpath.c b/bin/realpath/realpath.c index 2cd9e60..57cbb97 100644 --- a/bin/realpath/realpath.c +++ b/bin/realpath/realpath.c @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include -static void usage(void); +static void usage(void) __dead2; int main(int argc, char *argv[]) @@ -49,9 +49,10 @@ main(int argc, char *argv[]) char buf[PATH_MAX]; char *p; - if (argc == 1) - p = getcwd(NULL, 0); - else if (argc == 2) { + if (argc == 1) { + if ((p = getcwd(NULL, 0)) == NULL) + err(1, "getcwd()"); + } else if (argc == 2) { if ((p = realpath(argv[1], buf)) == NULL) err(1, "%s", argv[1]); } else -- cgit v1.1