Skip to content

Commit

Permalink
added dir-files fixes for Win32 from Chris Double
Browse files Browse the repository at this point in the history
  • Loading branch information
swdunlop committed Jan 1, 2011
1 parent eec0f2f commit 34c5607
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions vm/filesystem.c
Expand Up @@ -26,11 +26,7 @@
#include <string.h>
#include <errno.h>

#ifdef WASP_IN_WIN32
#include <io.h>
#else
#include <dirent.h>
#endif

//TODO: We really need a time type.
WASP_BEGIN_PRIM( "path-mtime", path_mtime )
Expand Down Expand Up @@ -92,40 +88,6 @@ WASP_BEGIN_PRIM( "dir-files", dir_files )

wasp_tc tc = wasp_make_tc( );

#ifdef WASP_IN_WIN32
int len = wasp_string_length( path );

char* glob = malloc( len + 3 );
struct _finddata_t info;

memcpy( glob, wasp_sf_string( path ), len );

glob[ len++ ] = '\\';
glob[ len++ ] = '*';
glob[ len++ ] = 0;

wasp_quad handle = _findfirst( glob, &info );
if( handle == -1 ){
free( glob );
wasp_errf( wasp_es_vm, "sx", "cannot open directory", path );
}else{
wasp_tc_add(
tc,
wasp_vf_string( wasp_string_fs( info.name ) )
);
}

for(;;){
handle = _findnext( handle, &info );
if( handle == -1 ) break;
wasp_tc_add(
tc,
wasp_vf_string( wasp_string_fs( info.name ) )
);
}

free( glob );
#else
DIR* dir = opendir( wasp_sf_string( path ) );
if( ! dir ) wasp_errf( wasp_es_vm, "sx", "cannot open directory", path );

Expand All @@ -136,7 +98,7 @@ WASP_BEGIN_PRIM( "dir-files", dir_files )
};

closedir( dir );
#endif

LIST_RESULT( tc->head );
WASP_END_PRIM( dir_files )

Expand Down

0 comments on commit 34c5607

Please sign in to comment.