2 * Copyright 2004, François Revol.
3 * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de.
4 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
5 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
6 * Distributed under the terms of the MIT License.
10 #include <FindDirectory.h>
18 #include <StorageDefs.h>
20 #include <find_directory_private.h>
23 #ifndef HAIKU_BUILD_GENERATED_DIRECTORY
24 # error HAIKU_BUILD_GENERATED_DIRECTORY not defined!
28 /*! make dir and its parents if needed */
30 create_path(const char *path
, mode_t mode
)
32 char buffer
[B_PATH_NAME_LENGTH
+ 1];
36 if (path
== NULL
|| ((pathLength
= strlen(path
)) > B_PATH_NAME_LENGTH
))
39 while (++i
< pathLength
) {
40 const char *slash
= strchr(&path
[i
], '/');
45 else if (i
!= slash
- path
)
50 strlcpy(buffer
, path
, i
+ 1);
51 if (stat(buffer
, &st
) < 0) {
53 if (mkdir(buffer
, mode
) < 0)
63 find_directory(directory_which which
, dev_t device
, bool createIt
,
64 char *returnedPath
, int32 pathLength
)
66 // we support only the handful of paths we need
69 case B_SYSTEM_TEMP_DIRECTORY
:
70 path
= HAIKU_BUILD_GENERATED_DIRECTORY
"/tmp";
72 case B_SYSTEM_SETTINGS_DIRECTORY
:
73 path
= HAIKU_BUILD_GENERATED_DIRECTORY
"/system/settings";
75 case B_SYSTEM_CACHE_DIRECTORY
:
76 path
= HAIKU_BUILD_GENERATED_DIRECTORY
"/system/cache";
78 case B_USER_SETTINGS_DIRECTORY
:
79 path
= HAIKU_BUILD_GENERATED_DIRECTORY
"/user/settings";
81 case B_USER_CACHE_DIRECTORY
:
82 path
= HAIKU_BUILD_GENERATED_DIRECTORY
"/user/cache";
88 // create, if necessary
89 status_t error
= B_OK
;
91 if (createIt
&& stat(path
, &st
) < 0)
92 error
= create_path(path
, 0755);
95 strlcpy(returnedPath
, path
, pathLength
);
102 __find_directory(directory_which which
, dev_t device
, bool createIt
,
103 char *returnedPath
, int32 pathLength
)
105 return find_directory(which
, device
, createIt
, returnedPath
, pathLength
);