1//----------------------------------------------------------------------
2//  This software is part of the Haiku distribution and is covered
3//  by the MIT license.
4//---------------------------------------------------------------------
5/*!
6	\file FindDirectory.cpp
7	find_directory() implementations.
8*/
9
10#include <FindDirectory.h>
11#include <Path.h>
12#include <Volume.h>
13
14
15// find_directory
16//!	Returns a path of a directory specified by a directory_which constant.
17/*!	\param which the directory_which constant specifying the directory
18	\param path a BPath object to be initialized to the directory's path
19	\param createIt \c true, if the directory shall be created, if it doesn't
20		   already exist, \c false otherwise.
21	\param volume the volume on which the directory is located
22	\return
23	- \c B_OK: Everything went fine.
24	- \c B_BAD_VALUE: \c NULL \a path.
25	- another error code
26*/
27status_t
28find_directory(directory_which which, BPath* path, bool createIt,
29			   BVolume* volume)
30{
31	if (path == NULL)
32		return B_BAD_VALUE;
33
34	dev_t device = (dev_t)-1;
35	if (volume && volume->InitCheck() == B_OK)
36		device = volume->Device();
37
38	char buffer[B_PATH_NAME_LENGTH];
39	status_t error = find_directory(which, device, createIt, buffer,
40		B_PATH_NAME_LENGTH);
41	if (error == B_OK)
42		error = path->SetTo(buffer);
43
44	return error;
45}
46
47