@@ -61,6 +61,25 @@ mergeInto(LibraryManager.library, {
61
61
if ( canWrite ) mode |= { { { cDefine ( 'S_IWUGO' ) } } } ;
62
62
return mode ;
63
63
} ,
64
+ modeStringToFlags : ( str ) = > {
65
+ var flags = FS . flagModes [ str ] ;
66
+ if ( typeof flags == 'undefined' ) {
67
+ throw new Error ( 'Unknown file open mode: ' + str ) ;
68
+ }
69
+ return flags ;
70
+ } ,
71
+ flagModes : {
72
+ // copied directly from library_fs.js
73
+ // Extra quotes used here on the keys to this object otherwise jsifier will
74
+ // erase them in the process of reading and then writing the JS library
75
+ // code.
76
+ '"r"' : { { { cDefine ( 'O_RDONLY' ) } } } ,
77
+ '"r+"' : { { { cDefine ( 'O_RDWR' ) } } } ,
78
+ '"w"' : { { { cDefine ( 'O_TRUNC' ) } } } | { { { cDefine ( 'O_CREAT' ) } } } | { { { cDefine ( 'O_WRONLY' ) } } } ,
79
+ '"w+"' : { { { cDefine ( 'O_TRUNC' ) } } } | { { { cDefine ( 'O_CREAT' ) } } } | { { { cDefine ( 'O_RDWR' ) } } } ,
80
+ '"a"' : { { { cDefine ( 'O_APPEND' ) } } } | { { { cDefine ( 'O_CREAT' ) } } } | { { { cDefine ( 'O_WRONLY' ) } } } ,
81
+ '"a+"' : { { { cDefine ( 'O_APPEND' ) } } } | { { { cDefine ( 'O_CREAT' ) } } } | { { { cDefine ( 'O_RDWR' ) } } } ,
82
+ } ,
64
83
createDataFile : ( parent , name , data , canRead , canWrite , canOwn ) = > {
65
84
// Data files must be cached until the file system itself has been initialized.
66
85
var mode = FS . getMode ( canRead , canWrite ) ;
@@ -122,6 +141,14 @@ mergeInto(LibraryManager.library, {
122
141
// TODO: mkdirTree
123
142
// TDOO: rmdir
124
143
// TODO: open
144
+ open : ( path , flags , mode ) = > {
145
+ flags = typeof flags == 'string' ? FS . modeStringToFlags ( flags ) : flags ;
146
+ mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode ;
147
+ return withStackSave ( ( ) => {
148
+ var buffer = allocateUTF8OnStack ( path ) ;
149
+ return __wasmfs_open ( { { { to64 ( 'buffer' ) } } } , flags , mode ) ;
150
+ } )
151
+ } ,
125
152
// TODO: create
126
153
// TODO: close
127
154
unlink: ( path ) => {
0 commit comments