* Fixed the / and \ issues in path separators.

* Use strchr/strrchr instead of index/rindex.


git-svn-id: svn://svn.zoy.org/elk/trunk@163 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
sam 2003-09-17 13:29:39 +00:00
parent 5f31f6ae27
commit 7d3267a72c
3 changed files with 9 additions and 26 deletions

View File

@ -190,11 +190,7 @@ Object General_File_Operation (Object s, register int op) {
return s;
}
Alloca (r, char*, strlen (dir) + 1 + strlen (p) + 1);
#ifdef WIN32
sprintf (r, "%s\\%s", dir, p);
#else
sprintf (r, "%s/%s", dir, p);
#endif
sprintf (r, "%s" SEPARATOR_STRING "%s", dir, p);
ret = Make_String (r, strlen (r));
Alloca_End;
return ret;
@ -241,11 +237,7 @@ Object Open_File (char *name, int flags, int err) {
p = Internal_Tilde_Expand (name, &dir);
if (p) {
Alloca (name, char*, strlen (dir) + 1 + strlen (p) + 1);
#ifdef WIN32
sprintf (name, "%s\\%s", dir, p);
#else
sprintf (name, "%s/%s", dir, p);
#endif
sprintf (name, "%s" SEPARATOR_STRING "%s", dir, p);
}
if (!err && stat (name, &st) == -1 &&
(errno == ENOENT || errno == ENOTDIR)) {
@ -300,13 +292,8 @@ Object General_Open_File (Object name, int flags, Object path) {
Alloca (buf, char*, blen);
}
memcpy (buf, STRING(pref)->data, plen);
#ifdef WIN32
if (buf[plen-1] != '\\')
buf[plen++] = '\\';
#else
if (buf[plen-1] != '/')
buf[plen++] = '/';
#endif
if (buf[plen-1] != SEPARATOR_CHAR)
buf[plen++] = SEPARATOR_CHAR;
memcpy (buf+plen, fn, len);
buf[len+plen] = '\0';
port = Open_File (buf, flags, 0);

View File

@ -309,11 +309,7 @@ void Elk_Init (int ac, char **av, int init_objects, char *toplevel) {
*/
Set_Error_Tag ("scheme-init");
initfile = Safe_Malloc (strlen (Scm_Dir) + 1 + sizeof (INITFILE) + 1);
#ifdef WIN32
sprintf (initfile, "%s\\%s", Scm_Dir, INITFILE);
#else
sprintf (initfile, "%s/%s", Scm_Dir, INITFILE);
#endif
sprintf (initfile, "%s" SEPARATOR_STRING "%s", Scm_Dir, INITFILE);
if (stat (initfile, &st) == -1 && errno == ENOENT)
file = Make_String (INITFILE, sizeof(INITFILE)-1);
else

View File

@ -197,21 +197,21 @@ static void Load_Lib (Object libs) {
/* Our line starts with dlname='... */
if (strncmp (buffer, "dlname", 6))
continue;
dlname = index (buffer, '\'');
dlname = strchr (buffer, '\'');
if (dlname == NULL)
continue;
dlname++;
eol = rindex (buffer, '\'');
eol = strrchr (buffer, '\'');
if (eol == NULL || eol == dlname)
continue;
*eol = '\0';
path = strdup (STRING(PORT(port)->name)->data);
eol = rindex (path, '/');
eol = strrchr (path, SEPARATOR_CHAR);
if (eol == NULL)
eol = path;
*eol = '\0';
lib = malloc (strlen (path) + 1 + strlen (dlname) + 1);
sprintf (lib, "%s/%s", path, dlname);
sprintf (lib, "%s" SEPARATOR_STRING "%s", path, dlname);
free (path);
break;
}