Changeset View
Standalone View
contrib/pkgconf/libpkgconf/personality.c
| Show All 11 Lines | |||||||||
| * implied. In no event shall the authors be liable for any damages arising | * implied. In no event shall the authors be liable for any damages arising | ||||||||
| * from the use of this software. | * from the use of this software. | ||||||||
| */ | */ | ||||||||
| #include <libpkgconf/config.h> | #include <libpkgconf/config.h> | ||||||||
| #include <libpkgconf/stdinc.h> | #include <libpkgconf/stdinc.h> | ||||||||
| #include <libpkgconf/libpkgconf.h> | #include <libpkgconf/libpkgconf.h> | ||||||||
| #ifdef __FreeBSD__ | |||||||||
| # include <sys/sysctl.h> | |||||||||
| # include <err.h> | |||||||||
| #endif | |||||||||
| /* | /* | ||||||||
| * !doc | * !doc | ||||||||
| * | * | ||||||||
| * libpkgconf `personality` module | * libpkgconf `personality` module | ||||||||
| * ========================= | * ========================= | ||||||||
| */ | */ | ||||||||
| /* | /* | ||||||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (find_paths(B_FIND_PATH_DEVELOP_LIB_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) { | ||||||||
| free(paths); | free(paths); | ||||||||
| paths = NULL; | paths = NULL; | ||||||||
| } | } | ||||||||
| if (find_paths(B_FIND_PATH_DATA_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) { | if (find_paths(B_FIND_PATH_DATA_DIRECTORY, "pkgconfig", &paths, &count) == B_OK) { | ||||||||
| for (size_t i = 0; i < count; i++) | for (size_t i = 0; i < count; i++) | ||||||||
| pkgconf_path_add(paths[i], dirlist, true); | pkgconf_path_add(paths[i], dirlist, true); | ||||||||
| free(paths); | free(paths); | ||||||||
| paths = NULL; | paths = NULL; | ||||||||
| } | |||||||||
| #elif defined(__FreeBSD__) | |||||||||
| pkgconf_buffer_t path1 = PKGCONF_BUFFER_INITIALIZER; | |||||||||
| pkgconf_buffer_t path2 = PKGCONF_BUFFER_INITIALIZER; | |||||||||
| char const * localbase; | |||||||||
| char *str = NULL; | |||||||||
| size_t len; | |||||||||
| localbase = getenv("LOCALBASE"); | |||||||||
| if (localbase == NULL) { | |||||||||
| if ((str = malloc((len = PATH_MAX) + 1)) == NULL) | |||||||||
des: Just use a stack buffer. The result will never be longer than `MAXPATHLEN` including the… | |||||||||
Done Inline Actionsthis snprintf() is pointless, I would do the reverse: add str = localbase; to the other branch and pass str to pkgconf_buffer_append() below. You may want to rename localbase to buf and str to localbase. des: this `snprintf()` is pointless, I would do the reverse: add `str = localbase;` to the other… | |||||||||
Done Inline Actions
des: | |||||||||
| err(1, NULL); | |||||||||
| while (sysctlbyname("user.localbase", str, &len, NULL, 0) < 0) { | |||||||||
| if (errno != ENOMEM) | |||||||||
Done Inline Actionsredundant braces des: redundant braces | |||||||||
Done Inline Actions
redundant des: redundant | |||||||||
| err(1, "sysctl(user.localbase)"); | |||||||||
| if ((str = realloc(str, len + 1)) == NULL) | |||||||||
| err(1, NULL); | |||||||||
| } | } | ||||||||
| str[len] = '\0'; | |||||||||
| localbase = str; | |||||||||
| } | |||||||||
| if (localbase == NULL) { | |||||||||
| localbase = LOCALBASE; | |||||||||
khorbenAuthorUnsubmitted Done Inline ActionsReading this again, I think this code will never be reached, so we wouldn't even need -DLOCALBASE=... in CFLAGS. khorben: Reading this again, I think this code will never be reached, so we wouldn't even need `… | |||||||||
| } | |||||||||
| if (!pkgconf_buffer_append(&path1, localbase) || | |||||||||
| !pkgconf_buffer_append(&path1, "/libdata/pkgconfig")) | |||||||||
| err(1, NULL); | |||||||||
| pkgconf_path_add(pkgconf_buffer_str(&path1), dirlist, false); | |||||||||
| pkgconf_path_add("/usr/libdata/pkgconfig", dirlist, false); | |||||||||
Not Done Inline ActionsIt seems odd to use err() here, how does the rest of pkgconf deal with string handling failures? des: It seems odd to use `err()` here, how does the rest of pkgconf deal with string handling… | |||||||||
Not Done Inline ActionsInterestingly, I just identified two similar functions that use malloc(), check for errors, and report them: bool pkgconf_buffer_append_fmt() and bool pkgconf_buffer_append_vfmt() (true is success, false is error). But then when called from build_default_search_path() (the same place we are patching) possible errors are ignored, and the result inconsistent. I don't think there's much risk there so we could probably do the same... 🤔 khorben: Interestingly, I just identified two similar functions that use `malloc()`, check for errors… | |||||||||
| if (!pkgconf_buffer_append(&path2, localbase) || | |||||||||
| !pkgconf_buffer_append(&path2, "/share/pkgconfig")) | |||||||||
| err(1, NULL); | |||||||||
| pkgconf_path_add(pkgconf_buffer_str(&path2), dirlist, false); | |||||||||
| free(str); | |||||||||
| #else | #else | ||||||||
| pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, false); | pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, false); | ||||||||
| #endif | #endif | ||||||||
| } | } | ||||||||
| /* | /* | ||||||||
| * !doc | * !doc | ||||||||
| * | * | ||||||||
| ▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | #if ! defined(_WIN32) && ! defined(__HAIKU__) | ||||||||
| } | } | ||||||||
| pkgconf_path_free(&plist); | pkgconf_path_free(&plist); | ||||||||
| #endif | #endif | ||||||||
| pkgconf_path_split(PERSONALITY_PATH, &plist, true); | pkgconf_path_split(PERSONALITY_PATH, &plist, true); | ||||||||
| PKGCONF_FOREACH_LIST_ENTRY(plist.head, n) | PKGCONF_FOREACH_LIST_ENTRY(plist.head, n) | ||||||||
| { | { | ||||||||
| pkgconf_path_t *pn = n->data; | pkgconf_path_t *pn = n->data; | ||||||||
Done Inline Actions
des: | |||||||||
| out = load_personality_with_path(pn->path, triplet, false); | out = load_personality_with_path(pn->path, triplet, false); | ||||||||
| if (out != NULL) | if (out != NULL) | ||||||||
Done Inline Actionsredundant braces des: redundant braces | |||||||||
Done Inline Actions
redundant des: redundant | |||||||||
| goto finish; | goto finish; | ||||||||
| } | } | ||||||||
| finish: | finish: | ||||||||
| pkgconf_path_free(&plist); | pkgconf_path_free(&plist); | ||||||||
| return out != NULL ? out : pkgconf_cross_personality_default(); | return out != NULL ? out : pkgconf_cross_personality_default(); | ||||||||
| } | } | ||||||||
| #endif | #endif | ||||||||
Just use a stack buffer. The result will never be longer than MAXPATHLEN including the terminating null character.