Added missing io functions from crtdll and implemented wide and 64 bit functions.
authorEric Kohl <eric.kohl@reactos.org>
Tue, 3 Jul 2001 22:18:42 +0000 (22:18 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 3 Jul 2001 22:18:42 +0000 (22:18 +0000)
svn path=/trunk/; revision=2032

26 files changed:
reactos/include/msvcrt/dir.h
reactos/include/msvcrt/internal/file.h
reactos/include/msvcrt/io.h
reactos/include/msvcrt/sys/stat.h
reactos/include/msvcrt/sys/types.h
reactos/include/msvcrt/sys/utime.h
reactos/lib/msvcrt/io/chmod.c [new file with mode: 0644]
reactos/lib/msvcrt/io/chsize.c [new file with mode: 0644]
reactos/lib/msvcrt/io/create.c [new file with mode: 0644]
reactos/lib/msvcrt/io/dup.c [new file with mode: 0644]
reactos/lib/msvcrt/io/dup2.c [new file with mode: 0644]
reactos/lib/msvcrt/io/eof.c [new file with mode: 0644]
reactos/lib/msvcrt/io/filelen.c [new file with mode: 0644]
reactos/lib/msvcrt/io/find.c [new file with mode: 0644]
reactos/lib/msvcrt/io/locking.c [new file with mode: 0644]
reactos/lib/msvcrt/io/lseek.c
reactos/lib/msvcrt/io/open.c
reactos/lib/msvcrt/io/pipe.c [new file with mode: 0644]
reactos/lib/msvcrt/io/sopen.c [new file with mode: 0644]
reactos/lib/msvcrt/io/tell.c [new file with mode: 0644]
reactos/lib/msvcrt/io/umask.c [new file with mode: 0644]
reactos/lib/msvcrt/io/unlink.c
reactos/lib/msvcrt/io/utime.c [new file with mode: 0644]
reactos/lib/msvcrt/sys_stat/fstat.c
reactos/lib/msvcrt/sys_stat/futime.c [new file with mode: 0644]
reactos/lib/msvcrt/sys_stat/stat.c

index 9d05996..c0d1257 100644 (file)
@@ -18,9 +18,9 @@
  *  DISCLAMED. This includes but is not limited to warranties of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: ekohl $
- * $Date: 2001/07/03 12:55:00 $
+ * $Date: 2001/07/03 22:15:02 $
  *
  */
 
@@ -53,7 +53,7 @@ typedef       unsigned long   _fsize_t;
 #endif
 
 /*
- * The following structure is filled in by _findfirst or _findnext when
+ * The following structures are filled in by _findfirst or _findnext when
  * they succeed in finding a match.
  */
 struct _finddata_t
@@ -66,15 +66,47 @@ struct _finddata_t
        char            name[FILENAME_MAX];     /* may include spaces. */
 };
 
+struct _finddatai64_t
+{
+       unsigned        attrib;         /* Attributes, see constants above. */
+       time_t          time_create;
+       time_t          time_access;    /* always midnight local time */
+       time_t          time_write;
+       __int64         size;
+       char            name[FILENAME_MAX];     /* may include spaces. */
+};
+
+struct _wfinddata_t
+{
+       unsigned        attrib;         /* Attributes, see constants above. */
+       time_t          time_create;
+       time_t          time_access;    /* always midnight local time */
+       time_t          time_write;
+       _fsize_t        size;
+       wchar_t         name[FILENAME_MAX];     /* may include spaces. */
+};
+
+struct _wfinddatai64_t
+{
+       unsigned        attrib;         /* Attributes, see constants above. */
+       time_t          time_create;
+       time_t          time_access;    /* always midnight local time */
+       time_t          time_write;
+       __int64         size;
+       wchar_t         name[FILENAME_MAX];     /* may include spaces. */
+};
+
 /*
  * Functions for searching for files. _findfirst returns -1 if no match
  * is found. Otherwise it returns a handle to be used in _findnext and
  * _findclose calls. _findnext also returns -1 if no match could be found,
  * and 0 if a match was found. Call _findclose when you are finished.
  */
+int    _findclose (int nHandle);
 int    _findfirst (const char* szFilespec, struct _finddata_t* find);
+int    _findfirsti64 (const char* szFilespec, struct _finddatai64_t* find);
 int    _findnext (int nHandle, struct _finddata_t* find);
-int    _findclose (int nHandle);
+int    _findnexti64 (int nHandle, struct _finddatai64_t* find);
 
 int    _chdir (const char* szPath);
 char*  _getcwd (char* caBuffer, int nBufferSize);
@@ -83,6 +115,18 @@ char*       _mktemp (char* szTemplate);
 int    _rmdir (const char* szPath);
 
 
+/* Wide character versions */
+int    _wfindfirst(const wchar_t *_name, struct _wfinddata_t *result);
+int    _wfindfirsti64(const wchar_t *_name, struct _wfinddatai64_t *result);
+int    _wfindnext(int handle, struct _wfinddata_t *result);
+int    _wfindnexti64(int handle, struct _wfinddatai64_t *result);
+
+int    _wchdir(const wchar_t *szPath);
+wchar_t* _wgetcwd(wchar_t *buffer, int maxlen);
+int    _wmkdir(const wchar_t *_path);
+int    _wrmdir(const wchar_t *_path);
+
+
 #ifndef _NO_OLDNAMES
 
 int    chdir (const char* szPath);
index b36a126..d6b6256 100644 (file)
@@ -52,6 +52,7 @@ int _doscan(FILE *iop, const char *fmt, va_list argp);
 
 
 int __fileno_dup2( int handle1, int handle2 );
+int __fileno_getmode(int _fd);
 int __fileno_setmode(int _fd, int _newmode);
 int __fileno_close(int _fd);
 
index b080048..e49d348 100644 (file)
@@ -18,9 +18,9 @@
  *  DISCLAMED. This includes but is not limited to warranties of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: ekohl $
- * $Date: 2001/07/03 12:55:00 $
+ * $Date: 2001/07/03 22:15:02 $
  *
  */
 /* Appropriated for Reactos Crtdll by Ariadne */
@@ -66,13 +66,15 @@ extern "C" {
 #endif
 
 int            _access (const char* szFileName, int nAccessMode);
+int            _chmod (const char* szPath, int nMode);
 int            _chsize (int nHandle, long lnNewSize);
 int            _close (int nHandle);
-int            _commit(int _fd);
+int            _commit(int _fd);
 int            _creat (const char* szFileName, int nAccessMode);
 int            _dup (int nHandle);
 int            _dup2 (int nOldHandle, int nNewHandle);
 long           _filelength (int nHandle);
+__int64                _filelengthi64(int nHandle);
 int            _fileno (FILE* fileGetHandle);
 void*          _get_osfhandle (int nHandle);
 int            _isatty (int nHandle);
@@ -90,6 +92,7 @@ int           _eof (int nHandle);
 int            _locking (int nHandle, int nCmd, long lnLockRegionLength);
 
 off_t          _lseek(int _fd, off_t _offset, int _whence);
+__int64                _lseeki64(int _fildes, __int64 _offset, int _whence);
 int            _open (const char* szFileName, int nFlags, ...);
 int            _open_osfhandle (void *lnOSHandle, int nFlags);
 int            _pipe (int *naHandles, unsigned int unSize, int nMode);
@@ -98,36 +101,48 @@ size_t             _read(int _fd, void *_buf, size_t _nbyte);
 /* SH_... flags for nFlag defined in share.h */
 int            _sopen (char* szFileName, int nAccess, int nFlag, int nMode);
 
-long           _tell (int nHandle);
-unsigned       _umask (unsigned unMode);
-int            _unlink (const char* szFileName);
+long           _tell(int nHandle);
+__int64                _telli64(int nHandle);
+unsigned       _umask(unsigned unMode);
+int            _unlink(const char* szFileName);
 size_t         _write(int _fd, const void *_buf, size_t _nbyte);
 
+
+/* wide character functions */
+int            _waccess(const wchar_t *_path, int _amode);
+int            _wchmod(const wchar_t *filename, int mode);
+int            _wcreat(const wchar_t *filename, int mode);
+
+int            _wopen(const wchar_t *_path, int _oflag,...);
+int            _wsopen(wchar_t *path, int access, int shflag, int mode);
+int            _wunlink(const wchar_t *filename);
+
+
 #ifndef        _NO_OLDNAMES
 /*
  * Non-underscored versions of non-ANSI functions to improve portability.
  * These functions live in libmoldname.a.
  */
 
-#define access                 _access
-#define chsize                 _chsize 
-#define close          _close
-#define creat          _creat
-#define        dup             _dup
-#define        dup2            _dup2
+#define        access          _access
+#define        chmod           _chmod
+#define        chsize          _chsize
+#define        close           _close
+#define        creat           _creat
+#define        dup             _dup
+#define        dup2            _dup2
 #define        eof             _eof
-#define        filelength      _filelength
-#define fileno(f)      ((f)->_file)
-#define        isatty          _isatty
-#define        lseek           _lseek
-#define        open            _open
-#define        read            _read
-#define        sopen(path,access,shflag,mode)  _open((path), (access)|(shflag), (mode))
-#define        tell(file)                      _lseek(_file, 0, SEEK_CUR)
-#define        umask           _umask
+#define        filelength      _filelength
+#define        fileno(f)       ((f)->_file)
+#define        isatty          _isatty
+#define        lseek           _lseek
+#define        open            _open
+#define        read            _read
+#define        sopen(path,access,shflag,mode)  _open((path), (access)|(shflag), (mode))
+#define        tell(file)                      _lseek(_file, 0, SEEK_CUR)
+#define        umask           _umask
 #define        unlink          _unlink
-#define        write           _write
-               
+#define        write           _write
 
 #endif /* Not _NO_OLDNAMES */
 
index 3870273..8c4ec72 100644 (file)
@@ -19,9 +19,9 @@
  *  DISCLAMED. This includes but is not limited to warranties of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: ekohl $
- * $Date: 2001/07/03 13:07:12 $
+ * $Date: 2001/07/03 22:16:07 $
  *
  */
 
 extern "C" {
 #endif
 
+#ifndef _WCHAR_T_
+#define _WCHAR_T_
+#define _WCHAR_T
+#define _WCHAR_T_DEFINED
+#ifndef __WCHAR_TYPE__
+#define        __WCHAR_TYPE__          short unsigned int
+#endif
+#ifndef __cplusplus
+typedef __WCHAR_TYPE__         wchar_t;
+#endif /* C++ */
+#endif /* wchar_t not already defined */
+
+
 /*
  * Constants for the stat st_mode member.
  */
@@ -89,17 +102,33 @@ struct stat
        time_t  st_ctime;       /* Creation time */
 };
 
+struct _stati64
+{
+       short   st_dev;         /* Equivalent to drive number 0=A 1=B ... */
+       short   st_ino;         /* Always zero ? */
+       short   st_mode;        /* See above constants */
+       short   st_nlink;       /* Number of links. */
+       int     st_uid;         /* User: Maybe significant on NT ? */
+       short   st_gid;         /* Group: Ditto */
+       short   st_rdev;        /* Seems useless (not even filled in) */
+       __int64 st_size;        /* File size in bytes */
+       time_t  st_atime;       /* Accessed date (always 00:00 hrs local
+                                * on FAT) */
+       time_t  st_mtime;       /* Modified time */
+       time_t  st_ctime;       /* Creation time */
+};
 
 int    _fstat (int nFileNo, struct stat* pstat);
-int    _chmod (const char* szPath, int nMode);
+__int64        _fstati64 (int nFileNo, struct _stati64* pstat);
 int    _stat (const char* szPath, struct stat* pstat);
-
+__int64        _stati64 (const char* szPath, struct _stati64* pstat);
+int    _wstat (const wchar_t* szPath, struct stat* pstat);
+__int64        _wstati64 (const wchar_t* szPath, struct _stati64* pstat);
 
 #ifndef        _NO_OLDNAMES
 
-#define        fstat(nFileNo, pstat)   _fstat(nFileNo, pstat)
-#define        chmod(szPath,nMode)     _chmod(szPath,nMode)
-#define        stat(szPath,pstat)      _stat(szPath,pstat)
+#define        fstat(nFileNo, pstat)   _fstat(nFileNo, pstat)
+#define        stat(szPath,pstat)      _stat(szPath,pstat)
 
 #endif /* Not _NO_OLDNAMES */
 
index 9b3bff9..6b2fff0 100644 (file)
  *  DISCLAMED. This includes but is not limited to warrenties of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: ekohl $
- * $Date: 2001/07/03 13:07:12 $
+ * $Date: 2001/07/03 22:16:07 $
  *
  */
 
 #ifndef        _TYPES_H_
 #define        _TYPES_H_
 
+#ifdef __GNUC__
+#undef __int64
+#define        __int64 long long
+#endif
+
 #ifndef        _TIME_T_
 #define        _TIME_T_
 typedef        long    time_t;
index b1a512c..9005621 100644 (file)
@@ -18,9 +18,9 @@
  *  DISCLAMED. This includes but is not limited to warranties of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: ekohl $
- * $Date: 2001/07/03 13:07:12 $
+ * $Date: 2001/07/03 22:16:07 $
  *
  */
 
@@ -48,10 +48,10 @@ struct _utimbuf
 };
 
 int    _utime (const char* szFileName, struct _utimbuf* pTimes);
-int     _futime (int nHandle, struct _utimbuf *pTimes);
+int    _futime (int nHandle, struct _utimbuf *pTimes);
 
 /* Wide character version */
-int     _wutime (const wchar_t *szFileName, struct _utimbuf *times);
+int    _wutime (const wchar_t *szFileName, struct _utimbuf *times);
 
 #ifndef        _NO_OLDNAMES
 
diff --git a/reactos/lib/msvcrt/io/chmod.c b/reactos/lib/msvcrt/io/chmod.c
new file mode 100644 (file)
index 0000000..11e7cad
--- /dev/null
@@ -0,0 +1,53 @@
+#include <windows.h>
+#include <msvcrt/io.h>
+
+#define mode_t int
+
+
+int _chmod(const char *filename, mode_t mode)
+{
+  DWORD FileAttributes = 0;
+
+  FileAttributes = GetFileAttributesA(filename);
+  if ( FileAttributes == -1 )
+    return -1;
+
+  if ( mode == 0 )
+    return -1;
+
+  if ((mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
+    FileAttributes &= FILE_ATTRIBUTE_READONLY;
+  else if (((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE))
+    FileAttributes &= FILE_ATTRIBUTE_NORMAL;
+  else
+    FileAttributes &= FILE_ATTRIBUTE_NORMAL;
+
+  if (SetFileAttributesA(filename, FileAttributes) == FALSE)
+     return -1;
+
+  return 1;
+}
+
+int _wchmod(const wchar_t *filename, mode_t mode)
+{
+  DWORD FileAttributes = 0;
+
+  FileAttributes = GetFileAttributesW(filename);
+  if ( FileAttributes == -1 )
+    return -1;
+
+  if ( mode == 0 )
+    return -1;
+
+  if ((mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
+    FileAttributes &= FILE_ATTRIBUTE_READONLY;
+  else if (((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE))
+    FileAttributes &= FILE_ATTRIBUTE_NORMAL;
+  else
+    FileAttributes &= FILE_ATTRIBUTE_NORMAL;
+
+  if (SetFileAttributesW(filename, FileAttributes) == FALSE)
+     return -1;
+
+  return 1;
+}
\ No newline at end of file
diff --git a/reactos/lib/msvcrt/io/chsize.c b/reactos/lib/msvcrt/io/chsize.c
new file mode 100644 (file)
index 0000000..a0ca25e
--- /dev/null
@@ -0,0 +1,11 @@
+/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
+#include <msvcrt/io.h>
+
+int _chsize(int _fd, long size)
+{
+  if (lseek(_fd, size, 0) == -1)
+    return -1;
+  if (_write(_fd, 0, 0) < 0)
+    return -1;
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/io/create.c b/reactos/lib/msvcrt/io/create.c
new file mode 100644 (file)
index 0000000..f8ee1a0
--- /dev/null
@@ -0,0 +1,12 @@
+#include <msvcrt/io.h>
+#include <msvcrt/fcntl.h>
+
+int _creat(const char *filename, int mode)
+{
+  return _open(filename,_O_CREAT|_O_TRUNC,mode);
+}
+
+int _wcreat(const wchar_t *filename, int mode)
+{
+  return _wopen(filename,_O_CREAT|_O_TRUNC,mode);
+}
diff --git a/reactos/lib/msvcrt/io/dup.c b/reactos/lib/msvcrt/io/dup.c
new file mode 100644 (file)
index 0000000..9364791
--- /dev/null
@@ -0,0 +1,8 @@
+#include <msvcrt/io.h>
+#include <msvcrt/internal/file.h>
+
+
+int _dup(int handle)
+{
+  return __fileno_alloc(_get_osfhandle(handle), __fileno_getmode(handle));
+}
diff --git a/reactos/lib/msvcrt/io/dup2.c b/reactos/lib/msvcrt/io/dup2.c
new file mode 100644 (file)
index 0000000..fc82505
--- /dev/null
@@ -0,0 +1,7 @@
+#include <msvcrt/io.h>
+#include <msvcrt/internal/file.h>
+
+int _dup2(int handle1, int handle2)
+{
+  return __fileno_dup2(handle1, handle2);
+}
diff --git a/reactos/lib/msvcrt/io/eof.c b/reactos/lib/msvcrt/io/eof.c
new file mode 100644 (file)
index 0000000..5fa959d
--- /dev/null
@@ -0,0 +1,15 @@
+//#include <windows.h>
+#include <msvcrt/io.h>
+
+int _eof(int _fd)
+{
+  __int64 cur_pos = _lseeki64(_fd, 0, SEEK_CUR);
+  __int64 end_pos = _lseeki64(_fd, 0, SEEK_END);
+  if ( cur_pos == -1 || end_pos == -1)
+    return -1;
+
+  if (cur_pos == end_pos)
+    return 1;
+
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/io/filelen.c b/reactos/lib/msvcrt/io/filelen.c
new file mode 100644 (file)
index 0000000..84e9f10
--- /dev/null
@@ -0,0 +1,16 @@
+#include <windows.h>
+#include <msvcrt/io.h>
+
+long _filelength(int _fd)
+{
+  return GetFileSize(_get_osfhandle(_fd),NULL);
+}
+
+__int64 _filelengthi64(int _fd)
+{
+  long lo_length, hi_length;
+
+  lo_length = GetFileSize(_get_osfhandle(_fd), &hi_length);
+
+  return((((__int64)hi_length) << 32) + lo_length);
+}
diff --git a/reactos/lib/msvcrt/io/find.c b/reactos/lib/msvcrt/io/find.c
new file mode 100644 (file)
index 0000000..f7921b8
--- /dev/null
@@ -0,0 +1,285 @@
+#include <windows.h>
+#include <msvcrt/io.h>
+#include <msvcrt/string.h>
+#include <msvcrt/internal/file.h>
+
+
+int _findclose(int handle)
+{
+  // check no wildcards or invalid handle
+  if (handle == 0 || handle == -1)
+    return 0;
+  return FindClose((void *)handle);
+}
+
+int _findfirst(const char *_name, struct _finddata_t *result)
+{
+  WIN32_FIND_DATAA FindFileData;
+  char dir[MAX_PATH];
+  long hFindFile;
+  int len = 0;
+
+  if ( _name == NULL || _name[0] == 0 )
+    {
+      len = GetCurrentDirectoryA(MAX_PATH-4,dir);
+      if (dir[len-1] != '\\')
+       {
+         dir[len] = '\\';
+         dir[len+1] = 0;
+       }
+      strcat(dir,"*.*");
+    }
+  else
+    strcpy(dir,_name);
+
+  hFindFile = (long)FindFirstFileA( dir, &FindFileData );
+  if (hFindFile == -1)
+    {
+      memset(result,0,sizeof(struct _finddata_t));
+      return -1;
+    }
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size = FindFileData.nFileSizeLow;
+  strncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  // if no wildcard the find file handle can be closed right away
+  // a return value of 0 can flag this.
+
+  if (!strchr(dir,'*') && !strchr(dir,'?'))
+    {
+      _findclose(hFindFile);
+      return 0;
+    }
+
+  return hFindFile;
+}
+
+int _findfirsti64(const char *_name, struct _finddatai64_t *result)
+{
+  WIN32_FIND_DATAA FindFileData;
+  char dir[MAX_PATH];
+  long hFindFile;
+  int len = 0;
+
+  if ( _name == NULL || _name[0] == 0 )
+    {
+      len = GetCurrentDirectoryA(MAX_PATH-4,dir);
+      if (dir[len-1] != '\\')
+       {
+         dir[len] = '\\';
+         dir[len+1] = 0;
+       }
+      strcat(dir, "*.*");
+    }
+  else
+    strcpy(dir, _name);
+
+  hFindFile = (long)FindFirstFileA(dir, &FindFileData);
+  if (hFindFile == -1)
+    {
+      memset(result,0,sizeof(struct _finddatai64_t));
+      return -1;
+    }
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size =
+    (((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
+  strncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  // if no wildcard the find file handle can be closed right away
+  // a return value of 0 can flag this.
+
+  if (!strchr(dir,'*') && !strchr(dir,'?'))
+    {
+      _findclose(hFindFile);
+      return 0;
+    }
+
+  return hFindFile;
+}
+
+int _findnext(int handle, struct _finddata_t *result)
+{
+  WIN32_FIND_DATAA FindFileData;
+
+  // check no wildcards or invalid handle
+  if (handle == 0 || handle == -1)
+    return 0;
+
+  if (!FindNextFileA((void *)handle, &FindFileData))
+    return -1;
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size = FindFileData.nFileSizeLow;
+  strncpy(result->name,FindFileData.cFileName, MAX_PATH);
+
+  return 0;
+}
+
+int _findnexti64(int handle, struct _finddatai64_t *result)
+{
+  WIN32_FIND_DATAA FindFileData;
+
+  // check no wildcards or invalid handle
+  if (handle == 0 || handle == -1)
+    return 0;
+
+  if (!FindNextFileA((void *)handle, &FindFileData))
+    return -1;
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size =
+    (((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
+  strncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  return 0;
+}
+
+int _wfindfirst(const wchar_t *_name, struct _wfinddata_t *result)
+{
+  WIN32_FIND_DATAW FindFileData;
+  wchar_t dir[MAX_PATH];
+  long hFindFile;
+  int len = 0;
+
+  if ( _name == NULL || _name[0] == 0 )
+    {
+      len = GetCurrentDirectoryW(MAX_PATH-4, dir);
+      if (dir[len-1] != L'\\')
+       {
+         dir[len] = L'\\';
+         dir[len+1] = 0;
+       }
+      wcscat(dir, L"*.*");
+    }
+  else
+    wcscpy(dir, _name);
+
+  hFindFile = (long)FindFirstFileW(dir, &FindFileData);
+  if (hFindFile == -1)
+    {
+      memset(result,0,sizeof(struct _wfinddata_t));
+      return -1;
+    }
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size = FindFileData.nFileSizeLow;
+  wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  // if no wildcard the find file handle can be closed right away
+  // a return value of 0 can flag this.
+
+  if (!wcschr(dir, L'*') && !wcschr(dir, L'?'))
+    {
+      _findclose(hFindFile);
+      return 0;
+    }
+
+  return hFindFile;
+}
+
+int _wfindfirsti64(const wchar_t *_name, struct _wfinddatai64_t *result)
+{
+  WIN32_FIND_DATAW FindFileData;
+  wchar_t dir[MAX_PATH];
+  long hFindFile;
+  int len = 0;
+
+  if (_name == NULL || _name[0] == 0)
+    {
+      len = GetCurrentDirectoryW(MAX_PATH-4,dir);
+      if (dir[len-1] != L'\\')
+       {
+         dir[len] = L'\\';
+         dir[len+1] = 0;
+       }
+      wcscat(dir, L"*.*");
+    }
+  else
+    wcscpy(dir, _name);
+
+  hFindFile = (long)FindFirstFileW(dir, &FindFileData);
+  if (hFindFile == -1)
+    {
+      memset(result,0,sizeof(struct _wfinddatai64_t));
+      return -1;
+    }
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size =
+    (((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
+  wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  // if no wildcard the find file handle can be closed right away
+  // a return value of 0 can flag this.
+
+  if (!wcschr(dir,L'*') && !wcschr(dir,L'?'))
+    {
+      _findclose(hFindFile);
+      return 0;
+    }
+
+  return hFindFile;
+}
+
+int _wfindnext(int handle, struct _wfinddata_t *result)
+{
+  WIN32_FIND_DATAW FindFileData;
+
+  // check no wildcards or invalid handle
+  if (handle == 0 || handle == -1)
+    return 0;
+
+  if (!FindNextFileW((void *)handle, &FindFileData))
+    return -1;
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size = FindFileData.nFileSizeLow;
+  wcsncpy(result->name,FindFileData.cFileName, MAX_PATH);
+
+  return 0;
+}
+
+int _wfindnexti64(int handle, struct _wfinddatai64_t *result)
+{
+  WIN32_FIND_DATAW FindFileData;
+
+  // check no wildcards or invalid handle
+  if (handle == 0 || handle == -1)
+    return 0;
+
+  if (!FindNextFileW((void *)handle, &FindFileData))
+    return -1;
+
+  result->attrib = FindFileData.dwFileAttributes;
+  result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
+  result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
+  result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
+  result->size =
+    (((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
+  wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
+
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/io/locking.c b/reactos/lib/msvcrt/io/locking.c
new file mode 100644 (file)
index 0000000..ba32830
--- /dev/null
@@ -0,0 +1,10 @@
+#include <windows.h>
+#include <msvcrt/io.h>
+
+int _locking(int _fd, int mode, long nbytes)
+{
+  long offset = _lseek(_fd, 0L, 1);
+  if (!LockFile(_get_osfhandle(_fd),offset,0,nbytes,0))
+    return -1;
+  return 0;
+}
index 2556d3d..34848e4 100644 (file)
@@ -2,8 +2,16 @@
 #include <msvcrt/io.h>
 #include <msvcrt/internal/file.h>
 
+
 long _lseek(int _fildes, long _offset, int _whence)
 {
-  return _llseek((HFILE)filehnd(_fildes),_offset,_whence);
+  return (SetFilePointer((HANDLE)filehnd(_fildes), _offset, NULL, _whence));
 }
 
+__int64 _lseeki64(int _fildes, __int64 _offset, int _whence)
+{
+  ULONG lo_pos, hi_pos;
+
+  lo_pos = SetFilePointer((HANDLE)filehnd(_fildes), _offset, &hi_pos, _whence);
+  return((((__int64)hi_pos) << 32) + lo_pos);
+}
\ No newline at end of file
index b82257f..3041789 100644 (file)
@@ -41,9 +41,6 @@ char __is_text_file(FILE *p)
 }
 
 
-int __fileno_alloc(HANDLE hFile, int mode);
-
-
 int _open(const char *_path, int _oflag,...)
 {
    HANDLE hFile;
diff --git a/reactos/lib/msvcrt/io/pipe.c b/reactos/lib/msvcrt/io/pipe.c
new file mode 100644 (file)
index 0000000..531ee22
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * COPYRIGHT:   See COPYING in the top level directory
+ * PROJECT:     ReactOS system libraries
+ * FILE:        lib/crtdll/io/pipe.c
+ * PURPOSE:     Creates a pipe
+ * PROGRAMER:   DJ Delorie
+ * UPDATE HISTORY:
+ *              28/12/98: Appropriated for Reactos
+ */
+#include <windows.h>
+#include <msvcrt/io.h>
+#include <msvcrt/internal/file.h>
+
+
+int _pipe(int _fildes[2], unsigned int size, int mode )
+{
+  HANDLE hReadPipe, hWritePipe;
+
+  if (!CreatePipe(&hReadPipe,&hWritePipe,NULL,size))
+    return -1;
+
+  _fildes[0] = __fileno_alloc(hReadPipe, mode);
+  _fildes[1] = __fileno_alloc(hWritePipe, mode);
+
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/io/sopen.c b/reactos/lib/msvcrt/io/sopen.c
new file mode 100644 (file)
index 0000000..e98fa85
--- /dev/null
@@ -0,0 +1,12 @@
+#include <msvcrt/io.h>
+
+
+int _sopen(char *path, int access, int shflag, int mode)
+{
+  return _open((path), (access)|(shflag), (mode));
+}
+
+int _wsopen(wchar_t *path, int access, int shflag, int mode)
+{
+  return _wopen((path), (access)|(shflag), (mode));
+}
diff --git a/reactos/lib/msvcrt/io/tell.c b/reactos/lib/msvcrt/io/tell.c
new file mode 100644 (file)
index 0000000..3d7d95b
--- /dev/null
@@ -0,0 +1,14 @@
+/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#include <msvcrt/errno.h>
+#include <msvcrt/io.h>
+
+
+off_t _tell(int _file)
+{
+  return _lseek(_file, 0, SEEK_CUR);
+}
+
+__int64 _telli64(int _file)
+{
+  return _lseeki64(_file, 0, SEEK_CUR);
+}
diff --git a/reactos/lib/msvcrt/io/umask.c b/reactos/lib/msvcrt/io/umask.c
new file mode 100644 (file)
index 0000000..4146b81
--- /dev/null
@@ -0,0 +1,11 @@
+/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+#include <crtdll/sys/stat.h>
+
+unsigned _unMode_dll = 022;
+
+unsigned _umask (unsigned unMode)
+{
+  unsigned old_mask = _unMode_dll;
+  _unMode_dll = unMode;
+  return old_mask;
+}
index e4cbe4c..542e766 100644 (file)
@@ -17,3 +17,10 @@ int _unlink(const char *filename)
     return -1;
   return 0;
 }
+
+int _wunlink(const wchar_t *filename)
+{
+  if (!DeleteFileW(filename))
+    return -1;
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/io/utime.c b/reactos/lib/msvcrt/io/utime.c
new file mode 100644 (file)
index 0000000..7a5b037
--- /dev/null
@@ -0,0 +1,39 @@
+#include <msvcrt/stdio.h>
+#include <msvcrt/io.h>
+#include <msvcrt/errno.h>
+#include <msvcrt/sys/utime.h>
+#include <msvcrt/internal/file.h>
+
+int _utime(const char* filename, struct _utimbuf* buf)
+{
+  int fn;
+  int ret;
+  
+  fn = _open(filename, _O_RDWR);
+  if (fn == -1)
+    {
+      __set_errno(EBADF);
+      return -1;
+    }
+  ret = _futime(fn,buf);
+  if (_close(fn) < 0)
+    return -1;
+  return ret;
+}
+
+int _wutime(const wchar_t* filename, struct _utimbuf* buf)
+{
+  int fn;
+  int ret;
+  
+  fn = _wopen(filename, _O_RDWR);
+  if (fn == -1)
+    {
+      __set_errno(EBADF);
+      return -1;
+    }
+  ret = _futime(fn,buf);
+  if (_close(fn) < 0)
+    return -1;
+  return ret;
+}
index fd0fd21..8c39b6c 100644 (file)
@@ -16,8 +16,7 @@
 #include <msvcrt/internal/file.h>
 
 
-int
-_fstat(int fd, struct stat *statbuf)
+int _fstat(int fd, struct stat *statbuf)
 {
   BY_HANDLE_FILE_INFORMATION  FileInformation;
 
@@ -40,3 +39,29 @@ _fstat(int fd, struct stat *statbuf)
   statbuf->st_size = FileInformation.nFileSizeLow;
   return 0;
 }
+
+__int64 _fstati64 (int fd, struct _stati64* statbuf)
+{
+  BY_HANDLE_FILE_INFORMATION FileInformation;
+
+  if (!statbuf)
+    {
+      __set_errno(EINVAL);
+      return -1;
+    }
+
+  if (!GetFileInformationByHandle(_get_osfhandle(fd),
+                                 &FileInformation))
+    {
+      __set_errno(EBADF);
+      return -1;
+    }
+  statbuf->st_ctime = FileTimeToUnixTime(&FileInformation.ftCreationTime,NULL);
+  statbuf->st_atime = FileTimeToUnixTime(&FileInformation.ftLastAccessTime,NULL);
+  statbuf->st_mtime = FileTimeToUnixTime(&FileInformation.ftLastWriteTime,NULL);
+
+  statbuf->st_dev = fd;
+  statbuf->st_size = (((__int64)FileInformation.nFileSizeHigh) << 32) +
+                    FileInformation.nFileSizeLow;
+  return 0;
+}
diff --git a/reactos/lib/msvcrt/sys_stat/futime.c b/reactos/lib/msvcrt/sys_stat/futime.c
new file mode 100644 (file)
index 0000000..b308d08
--- /dev/null
@@ -0,0 +1,43 @@
+#include <msvcrt/alloc.h>
+#include <msvcrt/stdlib.h>
+#include <msvcrt/sys/utime.h>
+#include <msvcrt/io.h>
+#include <msvcrt/time.h>
+#include <msvcrt/errno.h>
+#include <msvcrt/internal/file.h>
+
+int _futime (int nHandle, struct _utimbuf *pTimes)
+{
+  FILETIME  LastAccessTime;
+  FILETIME  LastWriteTime;
+
+  // check for stdin / stdout  handles ??
+  if (nHandle == -1)
+    {
+      __set_errno(EBADF);
+      return -1;
+    }
+
+  if (pTimes == NULL)
+    {
+      pTimes = alloca(sizeof(struct _utimbuf));
+      time(&pTimes->actime);
+      time(&pTimes->modtime);
+    }
+
+  if (pTimes->actime < pTimes->modtime)
+    {
+      __set_errno(EINVAL);
+      return -1;
+    }
+
+  UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0);
+  UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0);
+  if (!SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime))
+    {
+      __set_errno(EBADF);
+      return -1;
+    }
+
+  return 0;
+}
index 0865195..e4b0cc4 100644 (file)
@@ -14,3 +14,36 @@ int _stat(const char *path, struct stat *buffer)
 
   return ret;
 }
+
+__int64 _stati64 (const char *path, struct _stati64 *buffer)
+{
+  int fd = _open(path,_O_RDONLY);
+  int ret;
+
+  ret = _fstati64(fd,buffer);
+  _close(fd);
+
+  return ret;
+}
+
+int _wstat (const wchar_t *path, struct stat *buffer)
+{
+  int fd = _wopen(path,_O_RDONLY);
+  int ret;
+
+  ret = fstat(fd,buffer);
+  _close(fd);
+
+  return ret;
+}
+
+__int64 _wstati64 (const wchar_t *path, struct _stati64 *buffer)
+{
+  int fd = _wopen(path,_O_RDONLY);
+  int ret;
+
+  ret = _fstati64(fd,buffer);
+  _close(fd);
+
+  return ret;
+}