From 4ccb69e98ecdca80bad9e656d686b0086ca3149a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 21:55:52 +0000 Subject: Clean up recursive mkdir(). --- src/input/input_cdda.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index e658e30ca..ed6f2b4f9 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1283,39 +1283,29 @@ static void _cdda_mkdir_safe(xine_t *xine, char *path) { } /* - * Make recursive directory creation + * Make recursive directory creation (given an absolute pathname) */ -static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { - char *p, *pp; - char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; - char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1] = { 0, }; - - if(path == NULL) +static void _cdda_mkdir_recursive_safe (xine_t *xine, char *path) +{ + if (!path) return; - snprintf(buf, sizeof(buf), "%s", path); - pp = buf; - while((p = xine_strsep(&pp, "/")) != NULL) { - if(p && strlen(p)) { - -#ifdef WIN32 - if (*buf2 != '\0') { -#endif - - int size = strlen(buf2); - snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); - -#ifdef WIN32 - } - else { - snprintf(buf2, sizeof(buf2), "%s", p); - } + char buf[strlen (path) + 1]; + strcpy (buf, path); + char *p = strchr (buf, '/') ? : buf; -#endif /* WIN32 */ + do + { + while (*p++ == '/') /**/; + p = strchr (p, '/'); + if (p) + *p = 0; + _cdda_mkdir_safe (xine, buf); + if (p) + *p = '/'; + } while (p); - _cdda_mkdir_safe(xine, buf2); - } - } + return 0; } /* -- cgit v1.2.3