update for HEAD-2003021201
[reactos.git] / lib / msvcrt / stdio / wfdopen.c
diff --git a/lib/msvcrt/stdio/wfdopen.c b/lib/msvcrt/stdio/wfdopen.c
new file mode 100644 (file)
index 0000000..6e4ec0b
--- /dev/null
@@ -0,0 +1,54 @@
+#include <msvcrt/stdio.h>
+#include <msvcrt/internal/file.h>
+
+FILE* __alloc_file(void);
+
+
+FILE* _wfdopen(int handle, wchar_t* mode)
+{
+  FILE* file;
+  int rw;
+
+  if (handle == 0)
+    return stdin;
+
+  if (handle == 1)
+    return stdout;
+
+  if (handle == 2)
+    return stderr;
+
+  if (handle == 3)
+    return stdaux;
+
+  if (handle == 4)
+    return stdprn;
+
+  file = __alloc_file();
+  if (file == NULL)
+    return NULL;
+  file->_file = handle;
+
+  rw = (mode[1] == L'+') || (mode[1] && (mode[2] == L'+'));
+
+  if (*mode == L'a')
+    _lseek(handle, 0, SEEK_END);
+
+  file->_cnt = 0;
+  file->_file = handle;
+  file->_bufsiz = 0;
+
+// The mode of the stream must be compatible with the mode of the file descriptor.
+// this should be checked.
+
+  if (rw)
+    file->_flag = _IOREAD | _IOWRT;
+  else if (*mode == L'r')
+    file->_flag = _IOREAD;
+  else
+    file->_flag = _IOWRT;
+
+  file->_base = file->_ptr = NULL;
+
+  return file;
+}