Skip to content

Commit 97e8e1e

Browse files
committed
On Windows, the URLs were terminated with the wrong direction slash.
1 parent bb60fcd commit 97e8e1e

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

filesel/modland.com/modland-com-cachedir.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ static void modland_com_cachedir_Save (const struct DevInterfaceAPI_t *API, int
204204
free (modland_com.cacheconfig);
205205
switch (selected)
206206
{
207-
case 0: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATAHOME/modland.com/"); break;
208-
case 1: modland_com.cacheconfig = modland_com_strdup_slash ("$HOME/modland.com/"); break;
209-
case 2: modland_com.cacheconfig = modland_com_strdup_slash ("$OCPDATA/modland.com/"); break;
210-
case 3: modland_com.cacheconfig = modland_com_strdup_slash ("$TEMP/modland.com/"); break;
207+
case 0: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATAHOME/modland.com/"); break;
208+
case 1: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$HOME/modland.com/"); break;
209+
case 2: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$OCPDATA/modland.com/"); break;
210+
case 3: modland_com.cacheconfig = modland_com_strdup_slash_filesystem ("$TEMP/modland.com/"); break;
211211

212212
default:
213213
case 4:
214214
{
215215
char *t = modland_com.cacheconfigcustom;
216-
modland_com.cacheconfig = modland_com_strdup_slash (t);
217-
modland_com.cacheconfigcustom = modland_com_strdup_slash (t);
216+
modland_com.cacheconfig = modland_com_strdup_slash_filesystem (t);
217+
modland_com.cacheconfigcustom = modland_com_strdup_slash_filesystem (t);
218218
free (t);
219219

220220
free (*custom_modland_com);

filesel/modland.com/modland-com-mirrors.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ static void modland_com_mirror_Save (const struct DevInterfaceAPI_t *API, int se
102102
if (selected < NUM_MIRRORS)
103103
{
104104
free (modland_com.mirror);
105-
modland_com.mirror = modland_com_strdup_slash (modland_com_official_mirror[selected]);
105+
modland_com.mirror = modland_com_strdup_slash_url (modland_com_official_mirror[selected]);
106106
} else {
107107
char *t = modland_com.mirrorcustom;
108108
free (modland_com.mirror);
109-
modland_com.mirror = modland_com_strdup_slash (t);
110-
modland_com.mirrorcustom = modland_com_strdup_slash (t);
109+
modland_com.mirror = modland_com_strdup_slash_url (t);
110+
modland_com.mirrorcustom = modland_com_strdup_slash_url (t);
111111
free (t);
112112
}
113113

filesel/modland.com/modland-com.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -505,44 +505,51 @@ static int modland_com_add_data_line (struct modland_com_initialize_t *s, const
505505
return modland_com_add_data_fileentry (s, dir, last + 1, filesize);
506506
}
507507

508-
static char *modland_com_strdup_slash(const char *src)
508+
static char *modland_com_strdup_slash_common(const char *src, char slash)
509509
{
510510
char *retval;
511-
char *e;
512511
size_t len;
513512

514513
if (!src)
515514
{
516-
fprintf (stderr, "modland_com_strdup_slash(src): src is NULL\n");
515+
fprintf (stderr, "modland_com_strdup_slash_common(src): src is NULL\n");
517516
return 0;
518517
}
519-
e = strrchr (src,
520-
#ifdef _WIN32
521-
'\\'
522-
#else
523-
'/'
524-
#endif
525-
);
526-
527-
if (e && e[1])
518+
len = strlen (src);
519+
if (len)
528520
{
529-
e = 0;
521+
if ( ( src[ len - 1 ] == '\\' ) || ( src[ len - 1] == '/' ) )
522+
{
523+
len--;
524+
}
530525
}
531-
len = strlen(src) + !e + 1;
532-
retval = malloc (len);
526+
527+
retval = malloc (len + 2);
533528
if (!retval)
534529
{
535-
fprintf (stderr, "modland_com_strdup_slash(): malloc() failed\n");
530+
fprintf (stderr, "modland_com_strdup_slash_common(): malloc() failed\n");
531+
return 0;
536532
}
537-
snprintf (retval, len, "%s%s", src, !e ?
533+
534+
snprintf (retval, len + 2, "%.*s%c", (int)len, src, slash);
535+
536+
return retval;
537+
}
538+
539+
static char *modland_com_strdup_slash_url (const char *src)
540+
{
541+
return modland_com_strdup_slash_common (src, '/');
542+
}
543+
544+
static char *modland_com_strdup_slash_filesystem (const char *src)
545+
{
538546
#ifdef _WIN32
539-
"\\"
547+
return modland_com_strdup_slash_common (src, '\\');
540548
#else
541-
"/"
549+
return modland_com_strdup_slash_common (src, '/');
542550
#endif
543-
: "");
544-
return retval;
545551
}
552+
546553
#include "modland-com-cachedir.c"
547554
#include "modland-com-filehandle.c"
548555
#include "modland-com-file.c"
@@ -628,14 +635,14 @@ static int modland_com_init (struct PluginInitAPI_t *API)
628635

629636
{
630637
const char *temp = API->configAPI->GetProfileString ("modland.com", "mirror", "https://modland.com/");
631-
modland_com.mirror = modland_com_strdup_slash (temp);
638+
modland_com.mirror = modland_com_strdup_slash_url (temp);
632639
if (!modland_com.mirror)
633640
{
634641
return errAllocMem;
635642
}
636643

637644
temp = API->configAPI->GetProfileString ("modland.com", "mirrorcustom", modland_com.mirror);
638-
modland_com.mirrorcustom = modland_com_strdup_slash (temp);
645+
modland_com.mirrorcustom = modland_com_strdup_slash_url (temp);
639646
if (!modland_com.mirrorcustom)
640647
{
641648
return errAllocMem;

0 commit comments

Comments
 (0)