File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 3838#include < cerrno>
3939#include < ctime>
4040#include < vector>
41+ #include < wordexp.h>
4142#include " config.h"
4243#include " conky.h"
4344#include " core.h"
@@ -130,13 +131,19 @@ double get_time() {
130131}
131132
132133/* Converts '~/...' paths to '/home/blah/...'. It's similar to
133- * variable_substitute, except only cheques for $HOME and ~/ in
134- * path. If HOME is unset it uses an empty string for substitution */
134+ * variable_substitute, works for any enviroment variable */
135135std::string to_real_path (const std::string &source) {
136- const char *homedir = getenv (" HOME" ) != nullptr ? getenv (" HOME" ) : " " ;
137- if (source.find (" ~/" ) == 0 ) { return homedir + source.substr (1 ); }
138- if (source.find (" $HOME/" ) == 0 ) { return homedir + source.substr (5 ); }
139- return source;
136+ wordexp_t p;
137+ char **w;
138+ int i;
139+ const char *csource = source.c_str ();
140+ if (wordexp (csource, &p, 0 ) != 0 ) {
141+ return nullptr ;
142+ }
143+ w = p.we_wordv ;
144+ const char *resolved_path = strdup (w[0 ]);
145+ wordfree (&p);
146+ return std::string (resolved_path);
140147}
141148
142149int open_fifo (const char *file, int *reported) {
Original file line number Diff line number Diff line change @@ -58,9 +58,8 @@ struct process *get_first_process(void);
5858void get_cpu_count (void );
5959double get_time (void );
6060
61- /* Converts '~/...' paths to '/home/blah/...'
62- * It's similar to variable_substitute, except only cheques for $HOME and ~/ in
63- * path */
61+ /* Converts '~/...' paths to '/home/blah/...'. It's similar to
62+ * variable_substitute, works for any enviroment variable */
6463std::string to_real_path (const std::string &source);
6564FILE *open_file (const char *file, int *reported);
6665int open_fifo (const char *file, int *reported);
You can’t perform that action at this time.
0 commit comments