mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-16 04:02:15 +00:00
Implemented path resolution
This commit is contained in:
parent
9afcfadebb
commit
7ec86cfbd8
@ -38,6 +38,7 @@
|
|||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <wordexp.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@ -130,13 +131,19 @@ double get_time() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
|
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
|
||||||
* variable_substitute, except only cheques for $HOME and ~/ in
|
* variable_substitute, works for any enviroment variable */
|
||||||
* path. If HOME is unset it uses an empty string for substitution */
|
|
||||||
std::string to_real_path(const std::string &source) {
|
std::string to_real_path(const std::string &source) {
|
||||||
const char *homedir = getenv("HOME") != nullptr ? getenv("HOME") : "";
|
wordexp_t p;
|
||||||
if (source.find("~/") == 0) { return homedir + source.substr(1); }
|
char **w;
|
||||||
if (source.find("$HOME/") == 0) { return homedir + source.substr(5); }
|
int i;
|
||||||
return source;
|
const char *csource = source.c_str();
|
||||||
|
if (wordexp(csource, &p, 0) != 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
w = p.we_wordv;
|
||||||
|
const char *resolved_path = strdup(w[0]);
|
||||||
|
wordfree(&p);
|
||||||
|
return std::string(resolved_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_fifo(const char *file, int *reported) {
|
int open_fifo(const char *file, int *reported) {
|
||||||
|
@ -58,9 +58,8 @@ struct process *get_first_process(void);
|
|||||||
void get_cpu_count(void);
|
void get_cpu_count(void);
|
||||||
double get_time(void);
|
double get_time(void);
|
||||||
|
|
||||||
/* Converts '~/...' paths to '/home/blah/...'
|
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
|
||||||
* It's similar to variable_substitute, except only cheques for $HOME and ~/ in
|
* variable_substitute, works for any enviroment variable */
|
||||||
* path */
|
|
||||||
std::string to_real_path(const std::string &source);
|
std::string to_real_path(const std::string &source);
|
||||||
FILE *open_file(const char *file, int *reported);
|
FILE *open_file(const char *file, int *reported);
|
||||||
int open_fifo(const char *file, int *reported);
|
int open_fifo(const char *file, int *reported);
|
||||||
|
Loading…
Reference in New Issue
Block a user