diff options
author | fluxgen <fluxgen> | 2001-12-17 19:29:25 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2001-12-17 19:29:25 (GMT) |
commit | b77cd310cba024bf2ceb591bb107b204ac039b7e (patch) | |
tree | 98bb4548fcb964f043b0d7547e4b5958e446631e /src/misc.cc | |
parent | dbd3dfac7eb1de576aa66e25a8c765588c29b493 (diff) | |
download | fluxbox_pavel-b77cd310cba024bf2ceb591bb107b204ac039b7e.zip fluxbox_pavel-b77cd310cba024bf2ceb591bb107b204ac039b7e.tar.bz2 |
Added expandFilename
Diffstat (limited to 'src/misc.cc')
-rw-r--r-- | src/misc.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/misc.cc b/src/misc.cc index 728c5ae..809dc24 100644 --- a/src/misc.cc +++ b/src/misc.cc | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <iostream> | 28 | #include <iostream> |
29 | #include <X11/Xutil.h> | 29 | #include <X11/Xutil.h> |
30 | |||
30 | using namespace std; | 31 | using namespace std; |
31 | 32 | ||
32 | //------- strdup ------------------------ | 33 | //------- strdup ------------------------ |
@@ -39,6 +40,22 @@ char *Misc::strdup(const char *s) { | |||
39 | return n; | 40 | return n; |
40 | } | 41 | } |
41 | 42 | ||
43 | //------------- expandFilename ---------------------- | ||
44 | // if ~ then expand it to home of user | ||
45 | // returns expanded filename | ||
46 | // (note: the function creates new memory for the string) | ||
47 | //--------------------------------------------------- | ||
48 | char *Misc::expandFilename(const char *filename) { | ||
49 | char retval[strlen(filename)+strlen(getenv("HOME"))+2]; //2 extra byte just to be safe | ||
50 | retval[0]=0; //mark end | ||
51 | if (filename[0]=='~') { | ||
52 | strcat(retval, getenv("HOME")); | ||
53 | strcat(retval, &filename[1]); | ||
54 | } else | ||
55 | return Misc::strdup(filename); //return unmodified value | ||
56 | |||
57 | return Misc::strdup(retval); //return modified value | ||
58 | } | ||
42 | 59 | ||
43 | // ---------------------------------------------------------------------- | 60 | // ---------------------------------------------------------------------- |
44 | // xvertext, Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) | 61 | // xvertext, Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) |