do not use SWI path handling code: YAP should not try to control cwd, that's the OS task

This commit is contained in:
Vitor Santos Costa 2015-03-28 19:41:12 +00:00
parent 9709c590bf
commit d6e648a7ff
3 changed files with 41 additions and 22 deletions

View File

@ -393,6 +393,7 @@ PL_EXPORT(SOCKET) Swinsock(IOSTREAM *s);
#endif #endif
#endif #endif
PL_EXPORT(int) ScheckBOM(IOSTREAM *s); PL_EXPORT(int) ScheckBOM(IOSTREAM *s);
PL_EXPORT(int) SwriteBOM(IOSTREAM *s); PL_EXPORT(int) SwriteBOM(IOSTREAM *s);
PL_EXPORT(ssize_t) Sread_user(void *handle, char *buf, size_t size); PL_EXPORT(ssize_t) Sread_user(void *handle, char *buf, size_t size);

View File

@ -873,8 +873,8 @@ Is the file accessible?
return TRUE; return TRUE;
if ( md == ACCESS_WRITE && !AccessFile(n, ACCESS_EXIST) ) if ( md == ACCESS_WRITE && !AccessFile(n, ACCESS_EXIST) )
{ char tmp[MAXPATHLEN]; {
char *dir = DirName(n, tmp); char *dir = DirName(n);
if ( dir[0] ) if ( dir[0] )
{ if ( !ExistsDirectory(dir) ) { if ( !ExistsDirectory(dir) )
@ -977,11 +977,10 @@ PRED_IMPL("file_base_name", 2, file_base_name, 0)
static static
PRED_IMPL("file_directory_name", 2, file_directory_name, 0) PRED_IMPL("file_directory_name", 2, file_directory_name, 0)
{ char *n; { char *n;
char tmp[MAXPATHLEN];
if ( !PL_get_chars(A1, &n, CVT_ALL|REP_FN|CVT_EXCEPTION) ) if ( !PL_get_chars(A1, &n, CVT_ALL|REP_FN|CVT_EXCEPTION) )
return FALSE; return FALSE;
int out = PL_unify_chars(A2, PL_ATOM|REP_FN, -1, DirName(n, tmp)); int out = PL_unify_chars(A2, PL_ATOM|REP_FN, -1, DirName(n));
return out; return out;
} }

View File

@ -108,8 +108,6 @@ static double initial_time;
#define LOCK() PL_LOCK(L_OS) #define LOCK() PL_LOCK(L_OS)
#define UNLOCK() PL_UNLOCK(L_OS) #define UNLOCK() PL_UNLOCK(L_OS)
static void initExpand(void);
static void cleanupExpand(void);
static void initEnviron(void); static void initEnviron(void);
#ifndef DEFAULT_PATH #ifndef DEFAULT_PATH
@ -149,11 +147,13 @@ bool
initOs(void) initOs(void)
{ GET_LD { GET_LD
GD->statistics.start_time = WallTime(); GD->statistics.start_time = WallTime();
#ifndef __YAP_PROLOG__
DEBUG(1, Sdprintf("OS:initExpand() ...\n")); DEBUG(1, Sdprintf("OS:initExpand() ...\n"));
initExpand(); initExpand();
DEBUG(1, Sdprintf("OS:initEnviron() ...\n")); DEBUG(1, Sdprintf("OS:initEnviron() ...\n"));
#endif
initEnviron(); initEnviron();
#ifdef __WINDOWS__ #ifdef __WINDOWS__
@ -171,7 +171,10 @@ initOs(void)
void void
cleanupOs(void) cleanupOs(void)
{ cleanupExpand(); {
#ifndef __YAP_PROLOG__
cleanupExpand();
#endif
} }
@ -279,7 +282,7 @@ CpuTime(cputime_kind which)
{ case CPU_USER: { case CPU_USER:
used = (double) t.tms_utime / MTOK_hz; used = (double) t.tms_utime / MTOK_hz;
break; break;
case CPU_SYSTEM: case CPU_SYSTEM:
default: /* make compiler happy */ default: /* make compiler happy */
used = (double) t.tms_stime / MTOK_hz; used = (double) t.tms_stime / MTOK_hz;
} }
@ -486,7 +489,7 @@ setRandom(unsigned int *seedp)
} else } else
{ {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
seed = (unsigned int)GetTickCount(); seed = (unsigned int)GetTickCount();
#else #else
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
struct timeval tp; struct timeval tp;
@ -498,7 +501,6 @@ setRandom(unsigned int *seedp)
#endif #endif
#endif #endif
} }
#if HAVE_SRANDOM #if HAVE_SRANDOM
srandom(seed); srandom(seed);
#elif HAVE_SRAND #elif HAVE_SRAND
@ -536,6 +538,11 @@ _PL_Random(void)
#endif #endif
} }
#ifndef __YAP_PROLOG__
static void initExpand(void);
static void cleanupExpand(void);
/******************************** /********************************
* FILES * * FILES *
*********************************/ *********************************/
@ -800,7 +807,7 @@ OsPath(const char *p, char *buf)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char *AbsoluteFile(const char *file, char *path) char *AbsoluteFile1(const char *file, char *path)
Expand a file specification to a system-wide unique description of Expand a file specification to a system-wide unique description of
the file that can be passed to the file functions that take a path the file that can be passed to the file functions that take a path
@ -1075,7 +1082,6 @@ cleanupExpand(void)
#endif /*O_CANONISE_DIRS*/ #endif /*O_CANONISE_DIRS*/
char * char *
canoniseFileName(char *path) canoniseFileName(char *path)
{ char *out = path, *in = path, *start = path; { char *out = path, *in = path, *start = path;
@ -1126,7 +1132,7 @@ canoniseFileName(char *path)
{ {
again: again:
if ( *in ) if ( *in )
{ while( in[1] == '/' ) /* delete multiple / */ { while( in[1] == '/' ) /* delete multiple / */
in++; in++;
if ( in[1] == '.' ) if ( in[1] == '.' )
{ if ( in[2] == '/' ) /* delete /./ */ { if ( in[2] == '/' ) /* delete /./ */
@ -1470,9 +1476,6 @@ IsAbsolutePath(const char *p)
#endif /*O_HASDRIVES*/ #endif /*O_HASDRIVES*/
#define isRelativePath(p) ( p[0] == '.' )
char * char *
AbsoluteFile(const char *spec, char *path) AbsoluteFile(const char *spec, char *path)
{ GET_LD { GET_LD
@ -1594,6 +1597,10 @@ PL_cwd(char *cwd, size_t cwdlen)
{ char *rc; { char *rc;
LOCK(); LOCK();
#if __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "YapJava", "CD=%s; yeah", cwd);
#endif
rc = cwd_unlocked(cwd, cwdlen); rc = cwd_unlocked(cwd, cwdlen);
UNLOCK(); UNLOCK();
@ -1615,7 +1622,7 @@ BaseName(const char *f)
char * char *
DirName(const char *f, char *dir) DirName(const char *f)
{ const char *base, *p; { const char *base, *p;
for(base = p = f; *p; p++) for(base = p = f; *p; p++)
@ -1649,7 +1656,9 @@ bool
ChDir(const char *path) ChDir(const char *path)
{ char ospath[MAXPATHLEN]; { char ospath[MAXPATHLEN];
char tmp[MAXPATHLEN]; char tmp[MAXPATHLEN];
#if __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "YapJava", "ChDir=%s", path);
#endif
OsPath(path, ospath); OsPath(path, ospath);
if ( path[0] == EOS || streq(path, ".") || if ( path[0] == EOS || streq(path, ".") ||
@ -1711,6 +1720,8 @@ ChDir(const char *path)
fail; fail;
} }
#endif /* files in SWI */
/******************************** /********************************
* TIME CONVERSION * * TIME CONVERSION *
@ -2527,6 +2538,10 @@ char *command;
#endif #endif
#ifndef __YAP_PROLOG__
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
char *findExecutable(char *buf) char *findExecutable(char *buf)
@ -2624,6 +2639,8 @@ okToExec(const char *s)
} }
#endif /*EXEC_EXTENSIONS*/ #endif /*EXEC_EXTENSIONS*/
#define isRelativePath(p) ( p[0] == '.' )
static char * static char *
Which(const char *program, char *fullname) Which(const char *program, char *fullname)
{ char *path, *dir; { char *path, *dir;
@ -2633,10 +2650,10 @@ Which(const char *program, char *fullname)
#if OS2 && EMX #if OS2 && EMX
isDriveRelativePath(program) || isDriveRelativePath(program) ||
#endif /* OS2 */ #endif /* OS2 */
isRelativePath(program) || isRelativePath(program) ||
strchr(program, '/') ) strchr(program, '/') )
{ if ( (e = okToExec(program)) != NULL ) { if ( (e = okToExec(program)) != NULL )
{ strcpy(fullname, e); { strcpy(fullname, e);1
return fullname; return fullname;
} }
@ -2683,6 +2700,8 @@ Which(const char *program, char *fullname)
#endif /*__WINDOWS__*/ #endif /*__WINDOWS__*/
#endif
/** int Pause(double time) /** int Pause(double time)
Suspend execution `time' seconds. Time is given as a floating point Suspend execution `time' seconds. Time is given as a floating point