From 5f92e4b96d1612cdec32e061b7e7d2900b626c24 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Sat, 3 May 2008 02:39:49 -0400 Subject: [PATCH] Added current-directory parameter that gets/sets cwd. --- scheme/ikarus.posix.ss | 22 ++++++++++++++++++++-- scheme/last-revision | 2 +- scheme/makefile.ss | 1 + src/ikarus-runtime.c | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/scheme/ikarus.posix.ss b/scheme/ikarus.posix.ss index 8569fc1..1fc1b66 100644 --- a/scheme/ikarus.posix.ss +++ b/scheme/ikarus.posix.ss @@ -16,13 +16,13 @@ (library (ikarus posix) (export posix-fork fork waitpid system file-exists? delete-file - nanosleep getenv env environ file-ctime) + nanosleep getenv env environ file-ctime current-directory) (import (rnrs bytevectors) (except (ikarus) nanosleep posix-fork fork waitpid system file-exists? delete-file - getenv env environ file-ctime)) + getenv env environ file-ctime current-directory)) (define posix-fork (lambda () @@ -184,4 +184,22 @@ (unless (eq? rv 0) (error 'nanosleep "failed")))) + + (define current-directory + (case-lambda + [() + (let ([v (foreign-call "ikrt_getcwd")]) + (if (bytevector? v) + (utf8->string v) + (die 'current-directory + "failed to get current directory")))] + [(x) + (if (string? x) + (let ([rv (foreign-call "ikrt_chdir" (string->utf8 x))]) + (unless (eq? rv 0) + (die 'current-directory + "failed to set current directory"))) + (die 'current-directory "not a string" x))])) + + ) diff --git a/scheme/last-revision b/scheme/last-revision index ac48d99..d1d4b21 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1462 +1464 diff --git a/scheme/makefile.ss b/scheme/makefile.ss index 4def73a..bca55f5 100755 --- a/scheme/makefile.ss +++ b/scheme/makefile.ss @@ -1202,6 +1202,7 @@ [vector-sort! i r sr] [file-exists? i r fi] [delete-file i r fi] + [current-directory i] [file-ctime i] [define-record-type i r rs] [fields i r rs] diff --git a/src/ikarus-runtime.c b/src/ikarus-runtime.c index 961fa20..e045264 100644 --- a/src/ikarus-runtime.c +++ b/src/ikarus-runtime.c @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef __CYGWIN__ #include "ikarus-winmmap.h" #endif @@ -991,6 +992,27 @@ ikrt_nanosleep(ikptr secs, ikptr nsecs, ikpcb* pcb){ return fix(nanosleep(&t, NULL)); } +ikptr +ikrt_chdir(ikptr pathbv, ikpcb* pcb){ + int err = chdir(off_bytevector_data+(char*)pathbv); + return fix(err); /* FIXME: provide more meaninful result */ +} + +ikptr +ikrt_getcwd(ikpcb* pcb){ + char buff[MAXPATHLEN+1]; + char* path = getcwd(buff, MAXPATHLEN); + if(! path){ + return fix(-1); /* FIXME: provide more meaninful result */ + } + int len = strlen(path); + ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+len+1)); + ref(bv,0) = fix(len); + strncpy(disp_bytevector_data+(char*)(bv), path, len); + return bv+bytevector_tag; +} + + ikptr ikrt_debug(ikptr x){