1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibC: Add a O_CLOEXEC mode element to fopen()

This commit also changes the mode parsing to allow specifying the modes
in any order.
This commit is contained in:
AnotherTest 2020-05-28 02:12:05 +04:30 committed by Andreas Kling
parent f9bf2c7e78
commit dd2f9658f3
Notes: sideshowbarker 2024-07-19 06:02:59 +09:00

View file

@ -77,7 +77,6 @@ public:
void set_popen_child(pid_t child_pid) { m_popen_child = child_pid; } void set_popen_child(pid_t child_pid) { m_popen_child = child_pid; }
private: private:
struct Buffer { struct Buffer {
// A ringbuffer that also transparently implements ungetc(). // A ringbuffer that also transparently implements ungetc().
public: public:
@ -911,23 +910,36 @@ void perror(const char* s)
static int parse_mode(const char* mode) static int parse_mode(const char* mode)
{ {
int flags = 0; int flags = 0;
// NOTE: rt is a non-standard mode which opens a file for read, explicitly // NOTE: rt is a non-standard mode which opens a file for read, explicitly
// specifying that it's a text file // specifying that it's a text file
if (!strcmp(mode, "r") || !strcmp(mode, "rb") || !strcmp(mode, "rt")) for (; *mode; ++mode) {
flags = O_RDONLY; switch (*mode) {
else if (!strcmp(mode, "r+") || !strcmp(mode, "rb+")) case 'r':
flags = O_RDWR; flags |= O_RDONLY;
else if (!strcmp(mode, "w") || !strcmp(mode, "wb")) break;
flags = O_WRONLY | O_CREAT | O_TRUNC; case 'w':
else if (!strcmp(mode, "w+") || !strcmp(mode, "wb+")) flags |= O_WRONLY | O_CREAT | O_TRUNC;
flags = O_RDWR | O_CREAT | O_TRUNC; break;
else if (!strcmp(mode, "a") || !strcmp(mode, "ab")) case 'a':
flags = O_WRONLY | O_APPEND | O_CREAT; flags |= O_WRONLY | O_APPEND | O_CREAT;
else if (!strcmp(mode, "a+") || !strcmp(mode, "ab+")) break;
flags = O_RDWR | O_APPEND | O_CREAT; case '+':
else { flags |= O_RDWR;
dbg() << "Unexpected mode _" << mode << "_"; break;
ASSERT_NOT_REACHED(); case 'e':
flags |= O_CLOEXEC;
break;
case 'b':
// Ok...
break;
case 't':
// Ok...
break;
default:
dbg() << "Unsupported mode _" << mode << "_ (because of '" << *mode << "')";
ASSERT_NOT_REACHED();
}
} }
return flags; return flags;