fileType :: FilePath -> IO IODeviceType
fileType file =
allocaBytes sizeof_stat $ \ p_stat -> do
- withCString file $ \p_file -> do
+ withFilePath file $ \p_file -> do
throwErrnoIfMinus1Retry "fileType" $
c_stat p_file p_stat
statGetType p_stat
return mode
+#ifdef mingw32_HOST_OS
+withFilePath :: FilePath -> (CWString -> IO a) -> IO a
+withFilePath = withCWString
+#else
+withFilePath :: FilePath -> (CString -> IO a) -> IO a
+withFilePath = withCString
+#endif
+
-- ---------------------------------------------------------------------------
-- Terminal-related stuff
-- -----------------------------------------------------------------------------
-- foreign imports
+#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
+type CFilePath = CString
+#else
+type CFilePath = CWString
+#endif
+
foreign import ccall unsafe "HsBase.h access"
c_access :: CString -> CInt -> IO CInt
#endif
foreign import ccall unsafe "HsBase.h __hscore_lstat"
- lstat :: CString -> Ptr CStat -> IO CInt
+ lstat :: CFilePath -> Ptr CStat -> IO CInt
-foreign import ccall unsafe "HsBase.h __hscore_open"
- c_open :: CString -> CInt -> CMode -> IO CInt
+foreign import ccall unsafe "__hscore_open"
+ c_open :: CFilePath -> CInt -> CMode -> IO CInt
foreign import ccall unsafe "HsBase.h opendir"
c_opendir :: CString -> IO (Ptr CDir)
foreign import ccall unsafe "HsBase.h rewinddir"
c_rewinddir :: Ptr CDir -> IO ()
-foreign import ccall unsafe "HsBase.h __hscore_stat"
- c_stat :: CString -> Ptr CStat -> IO CInt
+foreign import ccall unsafe "__hscore_stat"
+ c_stat :: CFilePath -> Ptr CStat -> IO CInt
foreign import ccall unsafe "HsBase.h umask"
c_umask :: CMode -> IO CMode
#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 )
{
// 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
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; }
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
}
#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__)