/* Copyright (c) 1997 The Regents of the University of California.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

/*
 * this file contains file-handling routines.
 */


#include "m_imp.h"


#include <sys/types.h>
#include <sys/stat.h>

int sys_isreadablefile(char *s)
{
    struct stat statbuf;
    int mode;
    if (stat(s, &statbuf) < 0) return (0);
#if 0
    	/* LATER try to use the "mode" to detect directories. */
    	/* this isn't right yet. */
    mode = statbuf.st_mode;
    if (mode & (~(0777))) return (0);
#endif
    return (1);
}


#if 0 /* LATER make this replace openviapath() */

static int namefrompath(char **path, char *result)
{
    char *wherecolon = strchr(*path, ':');
    if (!strlen(*path) return(0);
    if (!wherepath)
    {
    	strncpy(result, *path, PDSTRINGLENGTH);
    	result[PDSTRINGLENGTH-1] = 0;
    	*path += strlen(*path);
    	return (1);
    }
    else
    {
    	if (wherecolon > *path + (PDSTRINGLENGTH-1))
    	    wherecolon = *path + (PDSTRINGLENGTH-1);
    	strcpy(result, *path);
    	*path = wherecolon + 1;
    	return(1);
    }
}

    /* find a file in a search path */
int sys_searchpath(char *files, char *path, char *result)
{
}
#endif

    /* change '/' characters to the system's native file separator */
void sys_bashfilename(char *from, char *to)
{
    char c;
    while (c = *from++)
    {
#ifdef NT
    	if (c == '/') c = '\\';
#endif
    	*to++ = c;
    }
    *to = 0;
}

