diff --git a/filesel/modland.com/modland-com-cachedir.c b/filesel/modland.com/modland-com-cachedir.c index 17496300..a4c7fd1e 100644 --- a/filesel/modland.com/modland-com-cachedir.c +++ b/filesel/modland.com/modland-com-cachedir.c @@ -204,17 +204,17 @@ static void modland_com_cachedir_Save (const struct DevInterfaceAPI_t *API, int free (modland_com.cacheconfig); switch (selected) { - case 0: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATAHOME/modland.com/"); break; - case 1: modland_com.cacheconfig = modland_com_strdup_slash ("$HOME/modland.com/"); break; - case 2: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATA/modland.com/"); break; - case 3: modland_com.cacheconfig = modland_com_strdup_slash ("$TEMP/modland.com/"); break; + case 0: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATAHOME/modland.com/"); break; + case 1: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$HOME/modland.com/"); break; + case 2: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATA/modland.com/"); break; + case 3: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$TEMP/modland.com/"); break; default: case 4: { char *t = modland_com.cacheconfigcustom; - modland_com.cacheconfig = modland_com_strdup_slash (t); - modland_com.cacheconfigcustom = modland_com_strdup_slash (t); + modland_com.cacheconfig = modland_com_strdup_slash_filesystem (t); + modland_com.cacheconfigcustom = modland_com_strdup_slash_filesystem (t); free (t); free (*custom_modland_com); diff --git a/filesel/modland.com/modland-com-mirrors.c b/filesel/modland.com/modland-com-mirrors.c index a924bae1..b89fbacb 100644 --- a/filesel/modland.com/modland-com-mirrors.c +++ b/filesel/modland.com/modland-com-mirrors.c @@ -102,12 +102,12 @@ static void modland_com_mirror_Save (const struct DevInterfaceAPI_t *API, int se if (selected < NUM_MIRRORS) { free (modland_com.mirror); - modland_com.mirror = modland_com_strdup_slash (modland_com_official_mirror[selected]); + modland_com.mirror = modland_com_strdup_slash_url (modland_com_official_mirror[selected]); } else { char *t = modland_com.mirrorcustom; free (modland_com.mirror); - modland_com.mirror = modland_com_strdup_slash (t); - modland_com.mirrorcustom = modland_com_strdup_slash (t); + modland_com.mirror = modland_com_strdup_slash_url (t); + modland_com.mirrorcustom = modland_com_strdup_slash_url (t); free (t); } diff --git a/filesel/modland.com/modland-com.c b/filesel/modland.com/modland-com.c index cb6bc18a..d5b98f62 100644 --- a/filesel/modland.com/modland-com.c +++ b/filesel/modland.com/modland-com.c @@ -505,44 +505,51 @@ static int modland_com_add_data_line (struct modland_com_initialize_t *s, const return modland_com_add_data_fileentry (s, dir, last + 1, filesize); } -static char *modland_com_strdup_slash(const char *src) +static char *modland_com_strdup_slash_common(const char *src, char slash) { char *retval; - char *e; size_t len; if (!src) { - fprintf (stderr, "modland_com_strdup_slash(src): src is NULL\n"); + fprintf (stderr, "modland_com_strdup_slash_common(src): src is NULL\n"); return 0; } - e = strrchr (src, -#ifdef _WIN32 - '\\' -#else - '/' -#endif - ); - - if (e && e[1]) + len = strlen (src); + if (len) { - e = 0; + if ( ( src[ len - 1 ] == '\\' ) || ( src[ len - 1] == '/' ) ) + { + len--; + } } - len = strlen(src) + !e + 1; - retval = malloc (len); + + retval = malloc (len + 2); if (!retval) { - fprintf (stderr, "modland_com_strdup_slash(): malloc() failed\n"); + fprintf (stderr, "modland_com_strdup_slash_common(): malloc() failed\n"); + return 0; } - snprintf (retval, len, "%s%s", src, !e ? + + snprintf (retval, len + 2, "%.*s%c", (int)len, src, slash); + + return retval; +} + +static char *modland_com_strdup_slash_url (const char *src) +{ + return modland_com_strdup_slash_common (src, '/'); +} + +static char *modland_com_strdup_slash_filesystem (const char *src) +{ #ifdef _WIN32 - "\\" + return modland_com_strdup_slash_common (src, '\\'); #else - "/" + return modland_com_strdup_slash_common (src, '/'); #endif - : ""); - return retval; } + #include "modland-com-cachedir.c" #include "modland-com-filehandle.c" #include "modland-com-file.c" @@ -628,14 +635,14 @@ static int modland_com_init (struct PluginInitAPI_t *API) { const char *temp = API->configAPI->GetProfileString ("modland.com", "mirror", "https://modland.com/"); - modland_com.mirror = modland_com_strdup_slash (temp); + modland_com.mirror = modland_com_strdup_slash_url (temp); if (!modland_com.mirror) { return errAllocMem; } temp = API->configAPI->GetProfileString ("modland.com", "mirrorcustom", modland_com.mirror); - modland_com.mirrorcustom = modland_com_strdup_slash (temp); + modland_com.mirrorcustom = modland_com_strdup_slash_url (temp); if (!modland_com.mirrorcustom) { return errAllocMem;