From 3c83cbf8055d4f13d21723f95c7c325fae8eae7a Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 15 Apr 2011 12:54:13 -0700 Subject: Fix mkdir_r to not assume existence of PATH_MAX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Required to build on HURD, but good practice anyway. Reviewed-by: Thorbjørn Lindeijer --- src/utils/mkdir.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp index 43f5264e..bd9fd2b1 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -36,17 +36,13 @@ #include "mkdir.h" +/// Create a directory, making leading components first if necessary int mkdir_r(const char *pathname) { - char tmp[PATH_MAX]; + size_t len = strlen(pathname); + char tmp[len+2]; char *p; - if (strlen(pathname) >= PATH_MAX-2) - return -1; - - strncpy(tmp, pathname, sizeof(tmp)-1); - tmp[PATH_MAX-1] = '\0'; - - int len=strlen(tmp); + strcpy(tmp, pathname); // terminate the pathname with '/' if (tmp[len-1] != '/') { -- cgit v1.2.3-70-g09d2