support linux kernel apis (new archs) with old syscalls removed
[musl] / src / stdio / __fdopen.c
index df6ed71..a6ae73a 100644 (file)
@@ -1,4 +1,10 @@
 #include "stdio_impl.h"
+#include <stdlib.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
 
 FILE *__fdopen(int fd, const char *mode)
 {
@@ -26,7 +32,9 @@ FILE *__fdopen(int fd, const char *mode)
        /* Set append mode on fd if opened for append */
        if (*mode == 'a') {
                int flags = __syscall(SYS_fcntl, fd, F_GETFL);
-               __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND);
+               if (!(flags & O_APPEND))
+                       __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND);
+               f->flags |= F_APP;
        }
 
        f->fd = fd;