aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pwd.c8
-rw-r--r--pwd.h2
2 files changed, 8 insertions, 2 deletions
diff --git a/pwd.c b/pwd.c
index 8416ed4..0c0c695 100644
--- a/pwd.c
+++ b/pwd.c
@@ -2,8 +2,12 @@
int main(void)
{
- char buf[1024];
- fprintf(stdout, "%s\n", getcwd(buf, 1024));
+ char buf[PATH_MAX];
+ if (getcwd(buf, PATH_MAX) == NULL) {
+ perror("getcwd");
+ exit(EXIT_FAILURE);
+ }
+ fprintf(stdout, "%s\n", buf);
exit(EXIT_SUCCESS);
}
diff --git a/pwd.h b/pwd.h
index 7ea4bed..a14c34b 100644
--- a/pwd.h
+++ b/pwd.h
@@ -5,4 +5,6 @@
#include <stdlib.h>
#include <unistd.h>
+#define PATH_MAX 512
+
#endif