152a38012Sejakowatz //----------------------------------------------------------------------
20f8af9d8SAxel Dörfler // This software is part of the Haiku distribution and is covered
30f8af9d8SAxel Dörfler // by the MIT license.
452a38012Sejakowatz //---------------------------------------------------------------------
552a38012Sejakowatz /*!
652a38012Sejakowatz \file FindDirectory.cpp
752a38012Sejakowatz find_directory() implementations.
852a38012Sejakowatz */
952a38012Sejakowatz
1052a38012Sejakowatz #include <FindDirectory.h>
1152a38012Sejakowatz #include <Path.h>
1252a38012Sejakowatz #include <Volume.h>
1352a38012Sejakowatz
1452a38012Sejakowatz
1552a38012Sejakowatz // find_directory
1652a38012Sejakowatz //! Returns a path of a directory specified by a directory_which constant.
1752a38012Sejakowatz /*! \param which the directory_which constant specifying the directory
1852a38012Sejakowatz \param path a BPath object to be initialized to the directory's path
1952a38012Sejakowatz \param createIt \c true, if the directory shall be created, if it doesn't
2052a38012Sejakowatz already exist, \c false otherwise.
2152a38012Sejakowatz \param volume the volume on which the directory is located
2252a38012Sejakowatz \return
2352a38012Sejakowatz - \c B_OK: Everything went fine.
2452a38012Sejakowatz - \c B_BAD_VALUE: \c NULL \a path.
2552a38012Sejakowatz - another error code
2652a38012Sejakowatz */
2752a38012Sejakowatz status_t
find_directory(directory_which which,BPath * path,bool createIt,BVolume * volume)2852a38012Sejakowatz find_directory(directory_which which, BPath* path, bool createIt,
2952a38012Sejakowatz BVolume* volume)
3052a38012Sejakowatz {
310f8af9d8SAxel Dörfler if (path == NULL)
320f8af9d8SAxel Dörfler return B_BAD_VALUE;
330f8af9d8SAxel Dörfler
3417e6de7aSshadow303 dev_t device = (dev_t)-1;
3552a38012Sejakowatz if (volume && volume->InitCheck() == B_OK)
3652a38012Sejakowatz device = volume->Device();
370f8af9d8SAxel Dörfler
380f8af9d8SAxel Dörfler char buffer[B_PATH_NAME_LENGTH];
39*868b22c5SStephan Aßmus status_t error = find_directory(which, device, createIt, buffer,
40*868b22c5SStephan Aßmus B_PATH_NAME_LENGTH);
410f8af9d8SAxel Dörfler if (error == B_OK)
420f8af9d8SAxel Dörfler error = path->SetTo(buffer);
430f8af9d8SAxel Dörfler
4452a38012Sejakowatz return error;
4552a38012Sejakowatz }
4652a38012Sejakowatz
47