* 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:
		
							parent
							
								
									5f31f6ae27
								
							
						
					
					
						commit
						7d3267a72c
					
				
							
								
								
									
										21
									
								
								src/io.c
								
								
								
								
							
							
						
						
									
										21
									
								
								src/io.c
								
								
								
								
							| 
						 | 
					@ -190,11 +190,7 @@ Object General_File_Operation (Object s, register int op) {
 | 
				
			||||||
            return s;
 | 
					            return s;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Alloca (r, char*, strlen (dir) + 1 + strlen (p) + 1);
 | 
					        Alloca (r, char*, strlen (dir) + 1 + strlen (p) + 1);
 | 
				
			||||||
#ifdef WIN32
 | 
					        sprintf (r, "%s" SEPARATOR_STRING "%s", dir, p);
 | 
				
			||||||
        sprintf (r, "%s\\%s", dir, p);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        sprintf (r, "%s/%s", dir, p);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        ret = Make_String (r, strlen (r));
 | 
					        ret = Make_String (r, strlen (r));
 | 
				
			||||||
        Alloca_End;
 | 
					        Alloca_End;
 | 
				
			||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
| 
						 | 
					@ -241,11 +237,7 @@ Object Open_File (char *name, int flags, int err) {
 | 
				
			||||||
    p = Internal_Tilde_Expand (name, &dir);
 | 
					    p = Internal_Tilde_Expand (name, &dir);
 | 
				
			||||||
    if (p) {
 | 
					    if (p) {
 | 
				
			||||||
        Alloca (name, char*, strlen (dir) + 1 + strlen (p) + 1);
 | 
					        Alloca (name, char*, strlen (dir) + 1 + strlen (p) + 1);
 | 
				
			||||||
#ifdef WIN32
 | 
					        sprintf (name, "%s" SEPARATOR_STRING "%s", dir, p);
 | 
				
			||||||
        sprintf (name, "%s\\%s", dir, p);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        sprintf (name, "%s/%s", dir, p);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!err && stat (name, &st) == -1 &&
 | 
					    if (!err && stat (name, &st) == -1 &&
 | 
				
			||||||
            (errno == ENOENT || errno == ENOTDIR)) {
 | 
					            (errno == ENOENT || errno == ENOTDIR)) {
 | 
				
			||||||
| 
						 | 
					@ -300,13 +292,8 @@ Object General_Open_File (Object name, int flags, Object path) {
 | 
				
			||||||
                Alloca (buf, char*, blen);
 | 
					                Alloca (buf, char*, blen);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            memcpy (buf, STRING(pref)->data, plen);
 | 
					            memcpy (buf, STRING(pref)->data, plen);
 | 
				
			||||||
#ifdef WIN32
 | 
					            if (buf[plen-1] != SEPARATOR_CHAR)
 | 
				
			||||||
            if (buf[plen-1] != '\\')
 | 
					                buf[plen++] = SEPARATOR_CHAR;
 | 
				
			||||||
                buf[plen++] = '\\';
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
            if (buf[plen-1] != '/')
 | 
					 | 
				
			||||||
                buf[plen++] = '/';
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
            memcpy (buf+plen, fn, len);
 | 
					            memcpy (buf+plen, fn, len);
 | 
				
			||||||
            buf[len+plen] = '\0';
 | 
					            buf[len+plen] = '\0';
 | 
				
			||||||
            port = Open_File (buf, flags, 0);
 | 
					            port = Open_File (buf, flags, 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -309,11 +309,7 @@ void Elk_Init (int ac, char **av, int init_objects, char *toplevel) {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    Set_Error_Tag ("scheme-init");
 | 
					    Set_Error_Tag ("scheme-init");
 | 
				
			||||||
    initfile = Safe_Malloc (strlen (Scm_Dir) + 1 + sizeof (INITFILE) + 1);
 | 
					    initfile = Safe_Malloc (strlen (Scm_Dir) + 1 + sizeof (INITFILE) + 1);
 | 
				
			||||||
#ifdef WIN32
 | 
					    sprintf (initfile, "%s" SEPARATOR_STRING "%s", Scm_Dir, INITFILE);
 | 
				
			||||||
    sprintf (initfile, "%s\\%s", Scm_Dir, INITFILE);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    sprintf (initfile, "%s/%s", Scm_Dir, INITFILE);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    if (stat (initfile, &st) == -1 && errno == ENOENT)
 | 
					    if (stat (initfile, &st) == -1 && errno == ENOENT)
 | 
				
			||||||
        file = Make_String (INITFILE, sizeof(INITFILE)-1);
 | 
					        file = Make_String (INITFILE, sizeof(INITFILE)-1);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -197,21 +197,21 @@ static void Load_Lib (Object libs) {
 | 
				
			||||||
        /* Our line starts with dlname='... */
 | 
					        /* Our line starts with dlname='... */
 | 
				
			||||||
        if (strncmp (buffer, "dlname", 6))
 | 
					        if (strncmp (buffer, "dlname", 6))
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        dlname = index (buffer, '\'');
 | 
					        dlname = strchr (buffer, '\'');
 | 
				
			||||||
        if (dlname == NULL)
 | 
					        if (dlname == NULL)
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        dlname++;
 | 
					        dlname++;
 | 
				
			||||||
        eol = rindex (buffer, '\'');
 | 
					        eol = strrchr (buffer, '\'');
 | 
				
			||||||
        if (eol == NULL || eol == dlname)
 | 
					        if (eol == NULL || eol == dlname)
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        *eol = '\0';
 | 
					        *eol = '\0';
 | 
				
			||||||
        path = strdup (STRING(PORT(port)->name)->data);
 | 
					        path = strdup (STRING(PORT(port)->name)->data);
 | 
				
			||||||
        eol = rindex (path, '/');
 | 
					        eol = strrchr (path, SEPARATOR_CHAR);
 | 
				
			||||||
        if (eol == NULL)
 | 
					        if (eol == NULL)
 | 
				
			||||||
            eol = path;
 | 
					            eol = path;
 | 
				
			||||||
        *eol = '\0';
 | 
					        *eol = '\0';
 | 
				
			||||||
        lib = malloc (strlen (path) + 1 + strlen (dlname) + 1);
 | 
					        lib = malloc (strlen (path) + 1 + strlen (dlname) + 1);
 | 
				
			||||||
        sprintf (lib, "%s/%s", path, dlname);
 | 
					        sprintf (lib, "%s" SEPARATOR_STRING "%s", path, dlname);
 | 
				
			||||||
        free (path);
 | 
					        free (path);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue