Skip to content

Commit

Permalink
#2204 : use std handles if associated with streams, else open "nul" s…
Browse files Browse the repository at this point in the history
…treams
  • Loading branch information
nomennescio authored and mrjbq7 committed May 14, 2024
1 parent f1594b5 commit add5807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions basis/io/files/windows/windows.factor
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ M: windows wait-for-fd

: console-app? ( -- ? ) GetConsoleWindow >boolean ;

M: windows init-stdio
console-app?
[ init-c-stdio ]
[ null-reader null-writer null-writer set-stdio ] if ;
M: windows init-stdio init-c-stdio ;

: open-file ( path access-mode create-mode flags -- handle )
[
Expand Down
12 changes: 9 additions & 3 deletions vm/factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ void factor_vm::init_factor(vm_parameters* p) {
special_objects[OBJ_ARGS] = false_object;
special_objects[OBJ_EMBEDDED] = false_object;

#ifdef WINDOWS
#define VALID_HANDLE(handle,mode) (_fileno (handle)==-2 ? fopen ("nul",mode) : handle)
#else
#define VALID_HANDLE(handle,mode) (handle)
#endif

cell aliens[][2] = {
{OBJ_STDIN, (cell)stdin},
{OBJ_STDOUT, (cell)stdout},
{OBJ_STDERR, (cell)stderr},
{OBJ_STDIN, (cell)(VALID_HANDLE (stdin ,"r"))},
{OBJ_STDOUT, (cell)(VALID_HANDLE (stdout,"w"))},
{OBJ_STDERR, (cell)(VALID_HANDLE (stderr,"w"))},
{OBJ_CPU, (cell)FACTOR_CPU_STRING},
{OBJ_EXECUTABLE, (cell)safe_strdup(p->executable_path)},
{OBJ_IMAGE, (cell)safe_strdup(p->image_path)},
Expand Down

0 comments on commit add5807

Please sign in to comment.