Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/libwasmfs_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ addToLibrary({
},

_wasmfs_node_open__deps: ['$wasmfsTry'],
_wasmfs_node_open: (path_p, mode_p) => {
return wasmfsTry(() => fs.openSync(UTF8ToString(path_p), UTF8ToString(mode_p)));
_wasmfs_node_open: (path_p, flags_p) => {
return wasmfsTry(() => fs.openSync(UTF8ToString(path_p), UTF8ToString(flags_p)));
},

_wasmfs_node_rename__deps: ['$wasmfsTry'],
Expand Down
2 changes: 1 addition & 1 deletion system/lib/wasmfs/backends/node_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int _wasmfs_node_symlink(const char *target, const char *linkpath);
int _wasmfs_node_readlink(const char *path, const char *buf, int bufsize);

// Open the file and return the underlying file descriptor.
[[nodiscard]] int _wasmfs_node_open(const char* path, const char* mode);
[[nodiscard]] int _wasmfs_node_open(const char* path, const char* flags);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't mode the correct name for the string arguments like w+ etc? i.e. its a string which matches FILE *fdopen(int fd, const char *mode); so mode makes sense to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to follow Node.js conventions here:
https://nodejs.org/api/fs.html#fsopensyncpath-flags-mode

At first, I wondered "Why is mode being passed to flags?" and made this change to prevent that confusion.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.. well thats confusing. C calls the r/w/a string things mode.. not flags, but node calls is falgs. I guess maybe worth adding a comment for this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing indeed. I think it's only a issue with fs.open{sync,}() though, as that accepts flags (which can also be a number) and mode (corresponding to mode_t in native code).

int open(const char *filename, int flags, ...)
{
mode_t mode = 0;
if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
}
int fd = __sys_open_cp(filename, flags, mode);

As possible follow-up, perhaps we could do?:

Suggested change
[[nodiscard]] int _wasmfs_node_open(const char* path, const char* flags);
[[nodiscard]] int _wasmfs_node_open(const char* path, int flags);

That would make it less confusing, as it would align with POSIX open(2) (and would avoid the need of UTF8ToString()).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... actually, we can't change const char* flags to int flags as Node.js's fs.constants are derived from the underlying file system constants, which can vary.


// Close the underlying file descriptor.
[[nodiscard]] int _wasmfs_node_close(int fd);
Expand Down
Loading