Tidy up use of read/write/recv/send; avoid unnecessary wrappers
[ghc-base.git] / include / HsBase.h
index 6ed0faa..92cc4e3 100644 (file)
@@ -417,33 +417,6 @@ __hscore_setmode( int fd, HsBool toBin )
 
 #if __GLASGOW_HASKELL__
 
-INLINE int
-__hscore_PrelHandle_write( int fd, void *ptr, HsInt off, int sz )
-{
-  return write(fd,(char *)ptr + off, sz);
-}
-
-INLINE int
-__hscore_PrelHandle_read( int fd, void *ptr, HsInt off, int sz )
-{
-  return read(fd,(char *)ptr + off, sz);
-
-}
-
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
-INLINE int
-__hscore_PrelHandle_send( int fd, void *ptr, HsInt off, int sz )
-{
-    return send(fd,(char *)ptr + off, sz, 0);
-}
-
-INLINE int
-__hscore_PrelHandle_recv( int fd, void *ptr, HsInt off, int sz )
-{
-    return recv(fd,(char *)ptr + off, sz, 0);
-}
-#endif
-
 #endif /* __GLASGOW_HASKELL__ */
 
 INLINE int
@@ -456,16 +429,6 @@ __hscore_mkdir( char *pathName, int mode )
 #endif
 }
 
-INLINE int
-__hscore_lstat( const char *fname, struct stat *st )
-{
-#if HAVE_LSTAT
-  return lstat(fname, st);
-#else
-  return stat(fname, st);
-#endif
-}
-
 INLINE char *
 __hscore_d_name( struct dirent* d )
 {
@@ -491,8 +454,6 @@ __hscore_free_dirent(struct dirent *dEnt)
 // and you have to ask for those explicitly.  Unfortunately there
 // doesn't seem to be a 64-bit version of truncate/ftruncate, so while
 // hFileSize and hSeek will work with large files, hSetFileSize will not.
-#define stat(file,buf)       _stati64(file,buf)
-#define fstat(fd,buf)        _fstati64(fd,buf)
 typedef struct _stati64 struct_stat;
 typedef off64_t stsize_t;
 #else
@@ -514,6 +475,37 @@ INLINE dev_t  __hscore_st_dev  ( struct_stat* st ) { return st->st_dev; }
 INLINE ino_t  __hscore_st_ino  ( struct_stat* st ) { return st->st_ino; }
 #endif
 
+#if defined(__MINGW32__)
+INLINE int __hscore_stat(wchar_t *file, struct_stat *buf) {
+       return _wstati64(file,buf);
+}
+
+INLINE int __hscore_fstat(int fd, struct_stat *buf) {
+       return _fstati64(fd,buf);
+}
+INLINE int __hscore_lstat(wchar_t *fname, struct_stat *buf )
+{
+       return _wstati64(fname,buf);
+}
+#else
+INLINE int __hscore_stat(char *file, struct_stat *buf) {
+       return stat(file,buf);
+}
+
+INLINE int __hscore_fstat(int fd, struct_stat *buf) {
+       return fstat(fd,buf);
+}
+
+INLINE int __hscore_lstat( const char *fname, struct stat *buf )
+{
+#if HAVE_LSTAT
+  return lstat(fname, buf);
+#else
+  return stat(fname, buf);
+#endif
+}
+#endif
+
 #if HAVE_TERMIOS_H
 INLINE tcflag_t __hscore_lflag( struct termios* ts ) { return ts->c_lflag; }
 
@@ -673,18 +665,20 @@ extern void __hscore_set_saved_termios(int fd, void* ts);
 
 INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }
 
-INLINE int __hscore_open(char *file, int how, mode_t mode) {
 #ifdef __MINGW32__
+INLINE int __hscore_open(wchar_t *file, int how, mode_t mode) {
        if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND))
-         return _sopen(file,how | _O_NOINHERIT,_SH_DENYRW,mode);
+         return _wsopen(file,how | _O_NOINHERIT,_SH_DENYRW,mode);
           // _O_NOINHERIT: see #2650
        else
-         return _sopen(file,how | _O_NOINHERIT,_SH_DENYWR,mode);
+         return _wsopen(file,how | _O_NOINHERIT,_SH_DENYWR,mode);
           // _O_NOINHERIT: see #2650
+}
 #else
+INLINE int __hscore_open(char *file, int how, mode_t mode) {
        return open(file,how,mode);
-#endif
 }
+#endif
 
 // These are wrapped because on some OSs (eg. Linux) they are
 // macros which redirect to the 64-bit-off_t versions when large file
@@ -700,14 +694,6 @@ INLINE off_t __hscore_lseek(int fd, off_t off, int whence) {
 }
 #endif
 
-INLINE int __hscore_stat(char *file, struct_stat *buf) {
-       return (stat(file,buf));
-}
-
-INLINE int __hscore_fstat(int fd, struct_stat *buf) {
-       return (fstat(fd,buf));
-}
-
 // select-related stuff
 
 #if !defined(__MINGW32__)