From cd05d511e6e4fe89a77b71463c4d79bd9e723e1e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 15 Jul 2005 12:15:21 +0000 Subject: [PATCH] Introduced generalized versions of get_app_path() and get_app_ref() returning the path/ref for an arbitrary team. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13681 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/AppMisc.h | 2 + src/kits/app/AppMisc.cpp | 88 ++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/headers/private/app/AppMisc.h b/headers/private/app/AppMisc.h index 0ba348a52e..3a7cefcd60 100644 --- a/headers/private/app/AppMisc.h +++ b/headers/private/app/AppMisc.h @@ -35,7 +35,9 @@ struct entry_ref; namespace BPrivate { +status_t get_app_path(team_id team, char *buffer); status_t get_app_path(char *buffer); +status_t get_app_ref(team_id team, entry_ref *ref, bool traverse = true); status_t get_app_ref(entry_ref *ref, bool traverse = true); team_id current_team(); diff --git a/src/kits/app/AppMisc.cpp b/src/kits/app/AppMisc.cpp index 52cc12b922..7c28c5155e 100644 --- a/src/kits/app/AppMisc.cpp +++ b/src/kits/app/AppMisc.cpp @@ -34,6 +34,39 @@ namespace BPrivate { +// get_app_path +/*! \brief Returns the path to an application's executable. + \param team The application's team ID. + \param buffer A pointer to a pre-allocated character array of at least + size B_PATH_NAME_LENGTH to be filled in by this function. + \return + - \c B_OK: Everything went fine. + - \c B_BAD_VALUE: \c NULL \a buffer. + - another error code +*/ +status_t +get_app_path(team_id team, char *buffer) +{ + // The only way to get the path to the application's executable seems to + // be to get an image_info of its image, which also contains a path. + // Several images may belong to the team (libraries, add-ons), but only + // the one in question should be typed B_APP_IMAGE. + if (!buffer) + return B_BAD_VALUE; + + image_info info; + int32 cookie = 0; + + while (get_next_image_info(team, &cookie, &info) == B_OK) { + if (info.type == B_APP_IMAGE) { + strlcpy(buffer, info.name, B_PATH_NAME_LENGTH - 1); + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + // get_app_path /*! \brief Returns the path to the application's executable. \param buffer A pointer to a pre-allocated character array of at least @@ -46,30 +79,39 @@ namespace BPrivate { status_t get_app_path(char *buffer) { - // The only way to get the path to the application's executable seems to - // be to get an image_info of its image, which also contains a path. - // Several images may belong to the team (libraries, add-ons), but only - // the one in question should be typed B_APP_IMAGE. - status_t error = (buffer ? B_OK : B_BAD_VALUE); - image_info info; - int32 cookie = 0; - bool found = false; + return get_app_path(B_CURRENT_TEAM, buffer); +} + +// get_app_ref +/*! \brief Returns an entry_ref referring to an application's executable. + \param team The application's team ID. + \param ref A pointer to a pre-allocated entry_ref to be initialized + to an entry_ref referring to the application's executable. + \param traverse If \c true, the function traverses symbolic links. + \return + - \c B_OK: Everything went fine. + - \c B_BAD_VALUE: \c NULL \a ref. + - another error code +*/ +status_t +get_app_ref(team_id team, entry_ref *ref, bool traverse) +{ + status_t error = (ref ? B_OK : B_BAD_VALUE); + char appFilePath[B_PATH_NAME_LENGTH]; + + if (error == B_OK) + error = get_app_path(team, appFilePath); + if (error == B_OK) { - while (!found && get_next_image_info(0, &cookie, &info) == B_OK) { - if (info.type == B_APP_IMAGE) { - strncpy(buffer, info.name, B_PATH_NAME_LENGTH - 1); - buffer[B_PATH_NAME_LENGTH - 1] = 0; - found = true; - } - } + BEntry entry(appFilePath, traverse); + error = entry.GetRef(ref); } - if (error == B_OK && !found) - error = B_ENTRY_NOT_FOUND; + return error; } // get_app_ref -/*! \brief Returns an entry_ref referring to the application's exectable. +/*! \brief Returns an entry_ref referring to the application's executable. \param ref A pointer to a pre-allocated entry_ref to be initialized to an entry_ref referring to the application's executable. \param traverse If \c true, the function traverses symbolic links. @@ -81,15 +123,7 @@ get_app_path(char *buffer) status_t get_app_ref(entry_ref *ref, bool traverse) { - status_t error = (ref ? B_OK : B_BAD_VALUE); - char appFilePath[B_PATH_NAME_LENGTH]; - if (error == B_OK) - error = get_app_path(appFilePath); - if (error == B_OK) { - BEntry entry(appFilePath, traverse); - error = entry.GetRef(ref); - } - return error; + return get_app_ref(B_CURRENT_TEAM, ref, traverse); } // current_team