diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-17 23:43:37 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-17 23:43:57 +1300 |
commit | ac013c6f539401d08cecf9351c74f382f5e435d6 (patch) | |
tree | 9d543711007b25a649b0a19cd7debfecbe090a22 | |
parent | Handle dependences properly (diff) | |
download | tunics-ac013c6f539401d08cecf9351c74f382f5e435d6.tar.gz tunics-ac013c6f539401d08cecf9351c74f382f5e435d6.zip |
Handle path being too long
-rw-r--r-- | pwd.c | 8 | ||||
-rw-r--r-- | pwd.h | 2 |
2 files changed, 8 insertions, 2 deletions
@@ -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); } @@ -5,4 +5,6 @@ #include <stdlib.h> #include <unistd.h> +#define PATH_MAX 512 + #endif |