diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-14 15:17:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-14 15:17:08 +0000 |
commit | aa37d3d42f37ace8dc196320f1677e4e14fe77c8 (patch) | |
tree | 20853c6f5f7cd2a4a59df93dea76784c5ea7215a /src/util | |
parent | 3c61c59e70103d21f9b3f645108f51f7a34b77fc (diff) | |
download | gnunet-aa37d3d42f37ace8dc196320f1677e4e14fe77c8.tar.gz gnunet-aa37d3d42f37ace8dc196320f1677e4e14fe77c8.zip |
LRN: add function GNUNET_STRINGS_get_short_name to get basename
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/strings.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index bd0a8eb52..1a884bc75 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -607,6 +607,26 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t) | |||
607 | return ret; | 607 | return ret; |
608 | } | 608 | } |
609 | 609 | ||
610 | 610 | /** | |
611 | * "man basename" | ||
612 | * Returns a pointer to a part of filename (allocates nothing)! | ||
613 | * | ||
614 | * @param filename filename to extract basename from | ||
615 | * @return short (base) name of the file (that is, everything following the | ||
616 | * last directory separator in filename. If filename ends with a | ||
617 | * directory separator, the result will be a zero-length string. | ||
618 | * If filename has no directory separators, the result is filename | ||
619 | * itself. | ||
620 | */ | ||
621 | const char * | ||
622 | GNUNET_STRINGS_get_short_name (const char *filename) | ||
623 | { | ||
624 | const char *short_fn = filename; | ||
625 | const char *ss; | ||
626 | while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)) | ||
627 | && (ss[1] != '\0')) | ||
628 | short_fn = 1 + ss; | ||
629 | return short_fn; | ||
630 | } | ||
611 | 631 | ||
612 | /* end of strings.c */ | 632 | /* end of strings.c */ |