pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/emscripten-core/emscripten/pull/26597

/github.githubassets.com/assets/actions-0e714a98ea09295a.css" /> [WasmFS] Fix argument name for open in the Node backend. NFC by kleisauke · Pull Request #26597 · emscripten-core/emscripten · GitHub
Skip to content

[WasmFS] Fix argument name for open in the Node backend. NFC#26597

Open
kleisauke wants to merge 1 commit intoemscripten-core:mainfrom
kleisauke:wasmfs-fix-arg-name
Open

[WasmFS] Fix argument name for open in the Node backend. NFC#26597
kleisauke wants to merge 1 commit intoemscripten-core:mainfrom
kleisauke:wasmfs-fix-arg-name

Conversation

@kleisauke
Copy link
Copy Markdown
Collaborator

Split out from #24733.


// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy