Skip to content

Commit

Permalink
moved expand_path() to config.h header
Browse files Browse the repository at this point in the history
Signed-off-by: Rentib <[email protected]>
  • Loading branch information
Rentib committed Oct 24, 2024
1 parent 917ac55 commit 6b2032e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
8 changes: 1 addition & 7 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,7 @@ static struct config* get_section(struct config* cfg, const char* name)
return NULL;
}

/**
* Expand path from environment variable.
* @param prefix_env path prefix (var name)
* @param postfix constant postfix
* @return allocated buffer with path, caller should free it after use
*/
static char* expand_path(const char* prefix_env, const char* postfix)
char* expand_path(const char* prefix_env, const char* postfix)
{
char* path;
const char* prefix;
Expand Down
8 changes: 8 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ void config_error_key(const char* section, const char* key);
* @param value configuration parameters
*/
void config_error_val(const char* section, const char* value);

/**
* Expand path from environment variable.
* @param prefix_env path prefix (var name)
* @param postfix constant postfix
* @return allocated buffer with path, caller should free it after use
*/
char* expand_path(const char* prefix_env, const char* postfix);
40 changes: 2 additions & 38 deletions src/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

#include "thumbnail.h"

#include "config.h"
#include "image.h"
#include "memdata.h"
#include "pixmap.h"
#include "src/memdata.h"

#include <errno.h>
#include <stdio.h>
Expand Down Expand Up @@ -52,43 +53,6 @@ static bool make_directories(char* path)
return true;
}

// NOTE: this is a copy from config.h
/**
* Expand path from environment variable.
* @param prefix_env path prefix (var name)
* @param postfix constant postfix
* @return allocated buffer with path, caller should free it after use
*/
static char* expand_path(const char* prefix_env, const char* postfix)
{
char* path;
const char* prefix;
size_t prefix_len = 0;
size_t postfix_len = strlen(postfix);

if (prefix_env) {
const char* delim;
prefix = getenv(prefix_env);
if (!prefix || !*prefix) {
return NULL;
}
// use only the first directory if prefix is a list
delim = strchr(prefix, ':');
prefix_len = delim ? (size_t)(delim - prefix) : strlen(prefix);
}

// compose path
path = malloc(prefix_len + postfix_len + 1 /* last null*/);
if (path) {
if (prefix_len) {
memcpy(path, prefix, prefix_len);
}
memcpy(path + prefix_len, postfix, postfix_len + 1 /*last null*/);
}

return path;
}

static bool get_thumb_path(char** path, const char* source)
{
const char* prefix = "XDG_CACHE_HOME";
Expand Down

0 comments on commit 6b2032e

Please sign in to comment.