summaryrefslogtreecommitdiff
path: root/src/xine-utils/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xine-utils/utils.c')
-rw-r--r--src/xine-utils/utils.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index b3286c11a..be5220231 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: utils.c,v 1.18 2003/09/16 02:11:45 storri Exp $
+ * $Id: utils.c,v 1.19 2003/11/04 14:38:26 valtri Exp $
*
*/
#define _POSIX_PTHREAD_SEMANTICS 1 /* for 5-arg getpwuid_r on solaris */
@@ -200,3 +200,44 @@ void xine_hexdump (char *buf, int length) {
printf("-");
printf("\n");
}
+
+
+#ifndef HAVE_BASENAME
+
+#define FILESYSTEM_PREFIX_LEN(filename) 0
+#define ISSLASH(C) ((C) == '/')
+
+/*
+ * get base name
+ *
+ * (adopted from sh-utils)
+ */
+char *basename (char const *name) {
+ char const *base = name + FILESYSTEM_PREFIX_LEN (name);
+ char const *p;
+
+ for (p = base; *p; p++)
+ {
+ if (ISSLASH (*p))
+ {
+ /* Treat multiple adjacent slashes like a single slash. */
+ do p++;
+ while (ISSLASH (*p));
+
+ /* If the file name ends in slash, use the trailing slash as
+ the basename if no non-slashes have been found. */
+ if (! *p)
+ {
+ if (ISSLASH (*base))
+ base = p - 1;
+ break;
+ }
+
+ /* *P is a non-slash preceded by a slash. */
+ base = p;
+ }
+ }
+
+ return (char *) base;
+}
+#endif