libroot: avoid excessive stack usage in __find_directory()

create_path() is inlined in __find_directory().
This commit is contained in:
Jérôme Duval 2018-04-06 20:58:17 +02:00 committed by waddlesplash
parent 70422d06a9
commit 48c1ae929e
1 changed files with 3 additions and 1 deletions

View File

@ -19,6 +19,7 @@
#include <directories.h>
#include <FindDirectory.h>
#include <fs_info.h>
#include <StackOrHeapArray.h>
#include <errno.h>
#include <pwd.h>
@ -195,13 +196,14 @@ static const char *kUserDirectories[] = {
static int
create_path(const char *path, mode_t mode)
{
char buffer[B_PATH_NAME_LENGTH + 1];
int pathLength;
int i = 0;
if (path == NULL || ((pathLength = strlen(path)) > B_PATH_NAME_LENGTH))
return EINVAL;
BStackOrHeapArray<char, 128> buffer(pathLength + 1);
while (++i < pathLength) {
char *slash = strchr(&path[i], '/');
struct stat st;