tcharize a couple of routines
authorGunnar Dalsnes <hardon@online.no>
Tue, 1 Mar 2005 22:22:56 +0000 (22:22 +0000)
committerGunnar Dalsnes <hardon@online.no>
Tue, 1 Mar 2005 22:22:56 +0000 (22:22 +0000)
svn path=/trunk/; revision=13791

reactos/lib/crt/makefile
reactos/lib/crt/stdio/fopen.c
reactos/lib/crt/stdio/fprintf.c
reactos/lib/crt/stdio/fwprintf.c [new file with mode: 0644]
reactos/lib/crt/stdio/wfopen.c [new file with mode: 0644]

index cd743dd..e95bdb0 100644 (file)
@@ -274,7 +274,9 @@ STDIO_OBJECTS = \
        stdio/fileno.o \\r
        stdio/flsbuf.o \\r
        stdio/fopen.o \\r
+       stdio/wfopen.o \\r
        stdio/fprintf.o \\r
+       stdio/fwprintf.o \\r
        stdio/fputc.o \\r
        stdio/fputchar.o \\r
        stdio/fputs.o \\r
index 3de3c2c..1bbbd3b 100644 (file)
 #include <string.h>
 #include <io.h>
 #include <fcntl.h>
+#include <tchar.h>
 #include <internal/file.h>
 
 //might change fopen(file,mode) -> fsopen(file,mode,_SH_DENYNO);
 
 
 
-FILE* fopen(const char *file, const char *mode)
+FILE* _tfopen(const _TCHAR *file, const _TCHAR *mode)
 {
   FILE *f;
   int fd, rw, oflags = 0;
@@ -50,28 +51,28 @@ FILE* fopen(const char *file, const char *mode)
   if (f == NULL)
     return NULL;
 
-  rw = (strchr(mode, '+') == NULL) ? 0 : 1;
-  if (strchr(mode, 'a'))
+  rw = (_tcschr(mode, '+') == NULL) ? 0 : 1;
+  if (_tcschr(mode, 'a'))
     oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
-  if (strchr(mode, 'r'))
+  if (_tcschr(mode, 'r'))
     oflags = rw ? O_RDWR : O_RDONLY;
-  if (strchr(mode, 'w'))
+  if (_tcschr(mode, 'w'))
     oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
-  if (strchr(mode, 't'))
+  if (_tcschr(mode, 't'))
     oflags |= O_TEXT;
-  else if (strchr(mode, 'b'))
+  else if (_tcschr(mode, 'b'))
     oflags |= O_BINARY;
   else
     oflags |= (_fmode& (O_TEXT|O_BINARY));
 
-  fd = _open(file, oflags, 0);
+  fd = _topen(file, oflags, 0);
   if (fd < 0)
     return NULL;
 
 // msvcrt ensures that writes will end up at the end of file in append mode
 // we just move the file pointer to the end of file initially
 
-  if (strchr(mode, 'a'))
+  if (_tcschr(mode, 'a'))
     _lseek(fd, 0, SEEK_END);
 
   f->_cnt = 0;
@@ -79,75 +80,14 @@ FILE* fopen(const char *file, const char *mode)
   f->_bufsiz = 0;
   if (rw)
     f->_flag = _IOREAD | _IOWRT;
-  else if (strchr(mode, 'r'))
+  else if (_tcschr(mode, 'r'))
     f->_flag = _IOREAD;
   else
     f->_flag = _IOWRT;
 
-  if (strchr(mode, 't'))
+  if (_tcschr(mode, 't'))
     f->_flag |= _IOTEXT;
-  else if (strchr(mode, 'b'))
-    f->_flag |= _IOBINARY;
-  else if (_fmode& O_BINARY)
-    f->_flag |= _IOBINARY;
-
-  f->_base = f->_ptr = NULL;
-  return f;
-}
-
-/*
- * @implemented
- */
-FILE* _wfopen(const wchar_t *file, const wchar_t *mode)
-{
-  FILE *f;
-  int fd, rw, oflags = 0;
-   
-  if (file == 0)
-    return 0;
-  if (mode == 0)
-    return 0;
-
-  f = __alloc_file();
-  if (f == NULL)
-    return NULL;
-
-  rw = (wcschr(mode, L'+') == NULL) ? 0 : 1;
-  if (wcschr(mode, L'a'))
-    oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
-  if (wcschr(mode, L'r'))
-    oflags = rw ? O_RDWR : O_RDONLY;
-  if (wcschr(mode, L'w'))
-    oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
-  if (wcschr(mode, L't'))
-    oflags |= O_TEXT;
-  else if (wcschr(mode, L'b'))
-    oflags |= O_BINARY;
-  else
-    oflags |= (_fmode& (O_TEXT|O_BINARY));
-
-  fd = _wopen(file, oflags, 0);
-  if (fd < 0)
-    return NULL;
-
-// msvcrt ensures that writes will end up at the end of file in append mode
-// we just move the file pointer to the end of file initially
-  if (wcschr(mode, 'a'))
-    _lseek(fd, 0, SEEK_END);
-
-  f->_cnt = 0;
-  f->_file = fd;
-  f->_bufsiz = 0;
-  if (rw)
-    f->_flag = _IOREAD | _IOWRT;
-  else if (wcschr(mode, L'r'))
-    f->_flag = _IOREAD;
-  else
-    f->_flag = _IOWRT;
-
-  if (wcschr(mode, L't'))
-    f->_flag |= _IOTEXT;
-  else if (wcschr(mode, L'b'))
+  else if (_tcschr(mode, 'b'))
     f->_flag |= _IOBINARY;
   else if (_fmode& O_BINARY)
     f->_flag |= _IOBINARY;
index dc56b3a..21bfe4f 100644 (file)
@@ -1,45 +1,17 @@
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
 #include <stdio.h>
 #include <wchar.h>
+#include <tchar.h>
 #include <internal/file.h>
 
 /*
  * @implemented
  */
 int
-fprintf(register FILE *iop, const char *fmt, ...)
+_ftprintf(register FILE *iop, const _TCHAR *fmt, ...)
 {
   int len;
-  char localbuf[BUFSIZ];
-  va_list a=0;
-  
-
-  va_start( a, fmt ); 
-  if (iop->_flag & _IONBF)
-  {
-    iop->_flag &= ~_IONBF;
-    iop->_ptr = iop->_base = localbuf;
-    iop->_bufsiz = BUFSIZ;
-    len = vfprintf(iop,fmt,a);
-    fflush(iop);
-    iop->_flag |= _IONBF;
-    iop->_base = NULL;
-    iop->_bufsiz = 0;
-    iop->_cnt = 0;
-  }
-  else
-    len = vfprintf(iop, fmt, a);
-  return ferror(iop) ? EOF : len;
-}
-
-/*
- * @implemented
- */
-int
-fwprintf(register FILE *iop, const wchar_t *fmt, ...)
-{
-  int len;
-  wchar_t localbuf[BUFSIZ];
+  _TCHAR localbuf[BUFSIZ];
   va_list a=0;
   
 
@@ -49,7 +21,7 @@ fwprintf(register FILE *iop, const wchar_t *fmt, ...)
     iop->_flag &= ~_IONBF;
     iop->_ptr = iop->_base = (char *)localbuf;
     iop->_bufsiz = BUFSIZ;
-    len = vfwprintf(iop,fmt,a);
+    len = _vftprintf(iop,fmt,a);
     fflush(iop);
     iop->_flag |= _IONBF;
     iop->_base = NULL;
@@ -57,6 +29,6 @@ fwprintf(register FILE *iop, const wchar_t *fmt, ...)
     iop->_cnt = 0;
   }
   else
-    len = vfwprintf(iop, fmt, a);
-  return ferror(iop) ? EOF : len;
+    len = _vftprintf(iop, fmt, a);
+  return ferror(iop) ? -1 : len;
 }
diff --git a/reactos/lib/crt/stdio/fwprintf.c b/reactos/lib/crt/stdio/fwprintf.c
new file mode 100644 (file)
index 0000000..dd273a2
--- /dev/null
@@ -0,0 +1,4 @@
+#define UNICODE\r
+#define _UNICODE\r
+\r
+#include "fprintf.c"\r
diff --git a/reactos/lib/crt/stdio/wfopen.c b/reactos/lib/crt/stdio/wfopen.c
new file mode 100644 (file)
index 0000000..1e134f7
--- /dev/null
@@ -0,0 +1,4 @@
+#define UNICODE\r
+#define _UNICODE\r
+\r
+#include "fopen.c"\r