Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-02-28 03:37:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-02-28 03:52:44 +0300
commitd7d78591289a89fdbd471476609a825febeb754b (patch)
tree24ad4f35ff4292ccf92a8b27b044a9e8b23342a7
parentba546976c309713680cd2eb4a858da937b77e0e1 (diff)
Cleanup: use fgets for parsing the xdg user dirs
Match bookmark reading behavior.
-rw-r--r--source/blender/editors/space_file/fsmenu.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 94747e79c84..dcd348706d6 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -115,8 +115,9 @@ struct FSMenuEntry *ED_fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory
*/
static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
{
- size_t data_len;
- char *data;
+ /* Add to the default for variable, equals & quotes. */
+ char l[128 + FILE_MAXDIR];
+ FILE *fp;
/* Check if the config file exists. */
{
@@ -128,17 +129,14 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
else {
BLI_path_join(filepath, sizeof(filepath), home, ".config", "user-dirs.dirs", NULL);
}
- data = BLI_file_read_text_as_mem_with_newline_as_nil(filepath, true, 1, &data_len);
- if (data == NULL) {
+ fp = BLI_fopen(filepath, "r");
+ if (!fp) {
return NULL;
}
}
/* By default there are 8 paths. */
GHash *xdg_map = BLI_ghash_str_new_ex(__func__, 8);
- char *data_end = data + data_len;
- uint l_len;
- for (char *l = data; l != data_end; l += l_len + 1) {
- l_len = strlen(l);
+ while (fgets(l, sizeof(l), fp) != NULL) { /* read a line */
/* Avoid inserting invalid values. */
if (STRPREFIX(l, "XDG_")) {
@@ -146,9 +144,12 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
if (l_value != NULL) {
*l_value = '\0';
l_value++;
- if (*l_value == '"' && l[l_len - 1] == '"') {
+
+ BLI_str_rstrip(l_value);
+ const uint l_value_len = strlen(l_value);
+ if ((l_value[0] == '"') && (l_value_len > 0) && (l_value[l_value_len - 1] == '"')) {
l_value++;
- l[l_len - 1] = '\0';
+ l_value[l_value_len - 1] = '\0';
char l_value_expanded[FILE_MAX];
char *l_value_final = l_value;
@@ -166,7 +167,6 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
}
}
}
- MEM_freeN(data);
return xdg_map;
}