1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-20 03:52:25 +03:00

Fix libxml_PyFileGet with stdout on macOS

macOS returns O_RDWR for standard file descriptors, but fails to write
to stdout or stderr when opened with fdopen(dup_fd, "rw").
This commit is contained in:
Nick Wellnhofer
2022-08-29 23:53:40 +02:00
parent b1a0961858
commit ce8f3d1195

View File

@@ -155,30 +155,44 @@ libxml_PyFileGet(PyObject *f) {
return(NULL); return(NULL);
#else #else
/* /*
* Get the flags on the fd to understand how it was opened * macOS returns O_RDWR for standard streams, but fails to write to
* stdout or stderr when opened with fdopen(dup_fd, "rw").
*/ */
flags = fcntl(fd, F_GETFL, 0); switch (fd) {
switch (flags & O_ACCMODE) { case STDIN_FILENO:
case O_RDWR: mode = "r";
if (flags & O_APPEND) break;
mode = "a+"; case STDOUT_FILENO:
else case STDERR_FILENO:
mode = "rw"; mode = "w";
break; break;
case O_RDONLY: default:
if (flags & O_APPEND) /*
mode = "r+"; * Get the flags on the fd to understand how it was opened
else */
mode = "r"; flags = fcntl(fd, F_GETFL, 0);
break; switch (flags & O_ACCMODE) {
case O_WRONLY: case O_RDWR:
if (flags & O_APPEND) if (flags & O_APPEND)
mode = "a"; mode = "a+";
else else
mode = "w"; mode = "rw";
break; break;
default: case O_RDONLY:
return(NULL); if (flags & O_APPEND)
mode = "r+";
else
mode = "r";
break;
case O_WRONLY:
if (flags & O_APPEND)
mode = "a";
else
mode = "w";
break;
default:
return(NULL);
}
} }
#endif #endif