#include "wx/utils.h"
#include "wx/intl.h"
-#include "wx/file.h"
+#include "wx/file.h" // This does include filefn.h
#include "wx/filename.h"
#include "wx/dir.h"
#include "wx/mac/private.h" // includes mac headers
#endif
-#ifdef __WXWINCE__
-#include "wx/msw/wince/time.h"
-#include "wx/msw/private.h"
-#else
-#include <time.h>
-#endif
-
-#ifdef __WXWINCE__
-// Nothing
-#elif !defined(__MWERKS__)
- #include <sys/types.h>
- #include <sys/stat.h>
-#else
-#ifdef __MACH__
-#include <sys/types.h>
-#include <utime.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#else
- #include <stat.h>
- #include <unistd.h>
- #include <unix.h>
- #include <fcntl.h>
-#endif
-#endif
-
-#ifdef __OS2__
-// need to check for __OS2__ first since currently both
-// __OS2__ and __UNIX__ are defined.
- #include <process.h>
- #include "wx/os2/private.h"
-#ifdef __EMX__
- #include <unistd.h>
-#endif
-#elif defined(__UNIX__)
- #include <unistd.h>
- #include <dirent.h>
- #include <fcntl.h>
-#endif
-
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
-#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__)
- #include <direct.h>
- #include <dos.h>
- #include <io.h>
-#endif // __WINDOWS__
-#endif // native Win compiler
-
-#if defined(__DOS__)
- #ifdef __WATCOMC__
- #include <direct.h>
- #include <dos.h>
- #include <io.h>
- #endif
- #ifdef __DJGPP__
- #include <unistd.h>
- #endif
-#endif
-
-#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
- // this (3.1 I believe) and how to test for it.
- // If this works for Borland 4.0 as well, then no worries.
- #include <dir.h>
-#endif
-
-#ifdef __SALFORDC__
- #include <dir.h>
- #include <unix.h>
-#endif
-
#include "wx/log.h"
-// No, Cygwin doesn't appear to have fnmatch.h after all.
-#if defined(HAVE_FNMATCH_H)
- #include "fnmatch.h"
-#endif
-
#ifdef __WINDOWS__
- #include "wx/msw/wrapwin.h"
+ #include "wx/msw/private.h"
#include "wx/msw/mslu.h"
- // for _getcwd
- #ifdef __MINGW32__
- #include <io.h>
- #endif
-
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
//
// note that it must be included after <windows.h>
#include <sys/cygwin.h>
#endif
#endif // __GNUWIN32__
+
+ // io.h is needed for _get_osfhandle()
+ // Already included by filefn.h for many Windows compilers
+ #if defined __MWERKS__ || defined __CYGWIN__
+ #include <io.h>
+ #endif
#endif // __WINDOWS__
+#if defined(__VMS__)
+ #include <fab.h>
+#endif
+
// TODO: Borland probably has _wgetcwd as well?
#ifdef _MSC_VER
#define HAVE_WGETCWD
// VisualAge C++ V4.0 cannot have any external linkage const decs
// in headers included by more than one primary source
//
-const off_t wxInvalidOffset = (off_t)-1;
+const int wxInvalidOffset = -1;
#endif
// ----------------------------------------------------------------------------
path such as "C:\Program Files" would be split into 2 paths:
"C:\Program" and "Files"
*/
-// wxT(" ;"); // Don't seperate with colon in DOS (used for drive)
- wxT(";"); // Don't seperate with colon in DOS (used for drive)
+// wxT(" ;"); // Don't separate with colon in DOS (used for drive)
+ wxT(";"); // Don't separate with colon in DOS (used for drive)
#else
wxT(" :;");
#endif
- wxChar *val = wxGetenv (WXSTRINGCAST envVariable);
- if (val && *val)
+ wxString val ;
+ if (wxGetEnv (WXSTRINGCAST envVariable, &val))
{
wxChar *s = MYcopystring (val);
wxChar *save_ptr, *token = wxStrtok (s, PATH_TOKS, &save_ptr);
delete [] s;
}
-#endif
+#else // __WXWINCE__
+ wxUnusedVar(envVariable);
+#endif // !__WXWINCE__/__WXWINCE__
}
// Given a full filename (with path), ensure that that file can
void wxPathList::EnsureFileAccessible (const wxString& path)
{
wxString path_only(wxPathOnly(path));
- if ( !path_only.IsEmpty() )
+ if ( !path_only.empty() )
{
if ( !Member(path_only) )
Add(path_only);
{
wxString path2( node->GetData() );
if (
-#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined (__WXMAC__)
+#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined(__WXMAC__)
// Case INDEPENDENT
path.CompareTo (path2, wxString::ignoreCase) == 0
#else
bool
wxFileExists (const wxString& filename)
{
+#if defined(__WXPALMOS__)
+ return false;
+#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
// we must use GetFileAttributes() instead of the ANSI C functions because
// it can cope with network (UNC) paths unlike them
-#if defined(__WIN32__) && !defined(__WXMICROWIN__)
DWORD ret = ::GetFileAttributes(filename);
return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else // !__WIN32__
wxStructStat st;
- return wxStat(filename, &st) == 0 && (st.st_mode & S_IFREG);
+#ifndef wxNEED_WX_UNISTD_H
+ return wxStat( filename.fn_str() , &st) == 0 && (st.st_mode & S_IFREG);
+#else
+ return wxStat( filename , &st) == 0 && (st.st_mode & S_IFREG);
+#endif
#endif // __WIN32__/!__WIN32__
}
bool
wxIsAbsolutePath (const wxString& filename)
{
- if (filename != wxT(""))
+ if (!filename.empty())
{
#if defined(__WXMAC__) && !defined(__DARWIN__)
// Classic or Carbon CodeWarrior like
void wxStripExtension(wxChar *buffer)
{
- int len = wxStrlen(buffer);
- int i = len-1;
- while (i > 0)
- {
- if (buffer[i] == wxT('.'))
+ int len = wxStrlen(buffer);
+ int i = len-1;
+ while (i > 0)
{
- buffer[i] = 0;
- break;
+ if (buffer[i] == wxT('.'))
+ {
+ buffer[i] = 0;
+ break;
+ }
+ i --;
}
- i --;
- }
}
void wxStripExtension(wxString& buffer)
{
- size_t len = buffer.Length();
- size_t i = len-1;
- while (i > 0)
- {
- if (buffer.GetChar(i) == wxT('.'))
+ //RN: Be careful about the handling the case where
+ //buffer.Length() == 0
+ for(size_t i = buffer.Length() - 1; i != wxString::npos; --i)
{
- buffer = buffer.Left(i);
- break;
+ if (buffer.GetChar(i) == wxT('.'))
+ {
+ buffer = buffer.Left(i);
+ break;
+ }
}
- i --;
- }
}
// Destructive removal of /./ and /../ stuff
// Must be destroyed
wxChar *wxCopyAbsolutePath(const wxString& filename)
{
- if (filename == wxT(""))
+ if (filename.empty())
return (wxChar *) NULL;
if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer, filename))) {
trimchars[3] = 0;
#ifdef __WXMSW__
- const wxChar SEP = wxT('\\');
+ const wxChar SEP = wxT('\\');
#else
- const wxChar SEP = wxT('/');
+ const wxChar SEP = wxT('/');
#endif
buf[0] = wxT('\0');
if (name == NULL || *name == wxT('\0'))
if (nm[1] == SEP || nm[1] == 0)
{ /* ~/filename */
// FIXME: wxGetUserHome could return temporary storage in Unicode mode
- if ((s = WXSTRINGCAST wxGetUserHome(wxT(""))) != NULL) {
+ if ((s = WXSTRINGCAST wxGetUserHome(wxEmptyString)) != NULL) {
if (*++nm)
nm++;
}
{
static wxChar dest[_MAXPATHLEN];
- if (filename == wxT(""))
+ if (filename.empty())
return (wxChar *) NULL;
wxStrcpy (dest, WXSTRINGCAST filename);
const wxChar *val;
#ifndef __WXWINCE__
wxChar *tcp;
- if (envname != WXSTRINGCAST NULL && (val = wxGetenv (WXSTRINGCAST envname)) != NULL &&
+ if (!envname.empty() && (val = wxGetenv (WXSTRINGCAST envname)) != NULL &&
(tcp = wxStrstr (dest, val)) != NULL)
{
wxStrcpy (wxFileFunctionsBuffer, tcp + wxStrlen (val));
wxStrcat (tcp, wxT("}"));
wxStrcat (tcp, wxFileFunctionsBuffer);
}
+#else
+ wxUnusedVar(envname);
#endif
// Handle User's home (ignore root homes!)
if (wxStrncmp(dest, val, len) == 0)
{
wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
- if (user != wxT(""))
+ if (!user.empty())
wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
wxStrcat(wxFileFunctionsBuffer, dest + len);
wxStrcpy (dest, wxFileFunctionsBuffer);
// Return just the directory, or NULL if no directory
wxString wxPathOnly (const wxString& path)
{
- if (path != wxT(""))
+ if (!path.empty())
{
wxChar buf[_MAXPATHLEN];
}
#endif
}
- return wxString(wxT(""));
+ return wxEmptyString;
}
// Utility for converting delimiters in DOS filenames to UNIX style
#define kDefaultPathStyle kCFURLHFSPathStyle
#endif
-wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent )
+wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent )
{
- CFURLRef fullURLRef;
+ CFURLRef fullURLRef;
fullURLRef = CFURLCreateFromFSRef(NULL, fsRef);
if ( additionalPathComponent )
{
additionalPathComponent,false);
CFRelease( parentURLRef ) ;
}
- CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle);
- CFRelease( fullURLRef ) ;
- return wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
+ CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle);
+ CFRelease( fullURLRef ) ;
+ return wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
}
-OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef )
+OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef )
{
OSStatus err = noErr ;
- CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, wxMacCFStringHolder(path ,wxLocale::GetSystemEncoding() ) , kDefaultPathStyle, false);
- if ( NULL != url )
- {
- if ( CFURLGetFSRef(url, fsRef) == false )
- err = fnfErr ;
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, wxMacCFStringHolder(path ,wxLocale::GetSystemEncoding() ) , kDefaultPathStyle, false);
+ if ( NULL != url )
+ {
+ if ( CFURLGetFSRef(url, fsRef) == false )
+ err = fnfErr ;
CFRelease( url ) ;
}
else
return err ;
}
-wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname )
+wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname )
{
CFStringRef cfname = CFStringCreateWithCharacters( kCFAllocatorDefault,
uniname->unicode,
*s = _T('/');
#ifdef __WXMSW__
else
- *s = wxTolower (*s); // Case INDEPENDENT
+ *s = (wxChar)wxTolower (*s); // Case INDEPENDENT
#endif
s++;
}
bool
wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& file3)
{
- wxString outfile;
- if ( !wxGetTempFileName( wxT("cat"), outfile) )
- return false;
-
- FILE *fp1 wxDUMMY_INITIALIZE(NULL);
- FILE *fp2 = NULL;
- FILE *fp3 = NULL;
- // Open the inputs and outputs
- if ((fp1 = wxFopen ( file1, wxT("rb"))) == NULL ||
- (fp2 = wxFopen ( file2, wxT("rb"))) == NULL ||
- (fp3 = wxFopen ( outfile, wxT("wb"))) == NULL)
+#if wxUSE_FILE
+
+ wxFile in1(file1), in2(file2);
+ wxTempFile out(file3);
+
+ if ( !in1.IsOpened() || !in2.IsOpened() || !out.IsOpened() )
+ return false;
+
+ ssize_t ofs;
+ unsigned char buf[1024];
+
+ for( int i=0; i<2; i++)
{
- if (fp1)
- fclose (fp1);
- if (fp2)
- fclose (fp2);
- if (fp3)
- fclose (fp3);
- return false;
+ wxFile *in = i==0 ? &in1 : &in2;
+ do{
+ if ( (ofs = in->Read(buf,WXSIZEOF(buf))) == wxInvalidOffset ) return false;
+ if ( ofs > 0 )
+ if ( !out.Write(buf,ofs) )
+ return false;
+ } while ( ofs == (ssize_t)WXSIZEOF(buf) );
}
- int ch;
- while ((ch = getc (fp1)) != EOF)
- (void) putc (ch, fp3);
- fclose (fp1);
+ return out.Commit();
- while ((ch = getc (fp2)) != EOF)
- (void) putc (ch, fp3);
- fclose (fp2);
+#else
+
+ wxUnusedVar(file1);
+ wxUnusedVar(file2);
+ wxUnusedVar(file3);
+ return false;
- fclose (fp3);
- bool result = wxRenameFile(outfile, file3);
- return result;
+#endif
}
// Copy files
return false;
}
#elif defined(__OS2__)
- if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
+ if ( ::DosCopy((PSZ)file1.c_str(), (PSZ)file2.c_str(), overwrite ? DCPY_EXISTING : 0) != 0 )
return false;
-#else // !Win32
+#elif defined(__PALMOS__)
+ // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
+ return false;
+#elif wxUSE_FILE // !Win32
wxStructStat fbuf;
// get permissions of file1
return false;
}
-#ifdef __UNIX__
// reset the umask as we want to create the file with exactly the same
// permissions as the original one
- mode_t oldUmask = umask( 0 );
-#endif // __UNIX__
+ wxCHANGE_UMASK(0);
// create file2 with the same permissions than file1 and open it for
// writing
if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
return false;
-#ifdef __UNIX__
- /// restore the old umask
- umask(oldUmask);
-#endif // __UNIX__
-
// copy contents of file1 to file2
char buf[4096];
size_t count;
return false;
}
#endif // OS/2 || Mac
+
+#else // !Win32 && ! wxUSE_FILE
+
+ // impossible to simulate with wxWidgets API
+ wxUnusedVar(file1);
+ wxUnusedVar(file2);
+ wxUnusedVar(overwrite);
+ return false;
+
#endif // __WXMSW__ && __WIN32__
return true;
bool
wxRenameFile (const wxString& file1, const wxString& file2)
{
-#ifndef __WXWINCE__
+#if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
// Normal system call
if ( wxRename (file1, file2) == 0 )
return true;
|| defined(__DMC__) \
|| defined(__GNUWIN32__) \
|| (defined(__MWERKS__) && defined(__MSL__))
- int res = wxRemove(file);
+ int res = wxRemove(file);
#elif defined(__WXMAC__)
- int res = unlink(wxFNCONV(file));
+ int res = unlink(wxFNCONV(file));
+#elif defined(__WXPALMOS__)
+ int res = 1;
+ // TODO with VFSFileDelete()
#else
- int res = unlink(OS_FILENAME(file));
+ int res = unlink(OS_FILENAME(file));
#endif
- return res == 0;
+ return res == 0;
}
bool wxMkdir(const wxString& dir, int perm)
{
-#if defined(__WXMAC__) && !defined(__UNIX__)
- return (mkdir( wxFNCONV(dir) , 0 ) == 0);
+#if defined(__WXPALMOS__)
+ return false;
+#elif defined(__WXMAC__) && !defined(__UNIX__)
+ return (mkdir( wxFNCONV(dir) , 0 ) == 0);
#else // !Mac
const wxChar *dirname = dir.c_str();
#error "Unsupported DOS compiler!"
#endif
#else // !MSW, !DOS and !OS/2 VAC++
- (void)perm;
+ wxUnusedVar(perm);
#ifdef __WXWINCE__
if ( !CreateDirectory(dirname, NULL) )
#else
- if ( wxMkDir(wxFNSTRINGCAST wxFNCONV(dirname)) != 0 )
+ if ( wxMkDir(dir.fn_str()) != 0 )
#endif
#endif // !MSW/MSW
{
bool wxRmdir(const wxString& dir, int WXUNUSED(flags))
{
-#ifdef __VMS__
+#if defined(__VMS__)
return false; //to be changed since rmdir exists in VMS7.x
#elif defined(__OS2__)
return (::DosDeleteDir((PSZ)dir.c_str()) == 0);
-#else
-
-#ifdef __WXWINCE__
+#elif defined(__WXWINCE__)
return (CreateDirectory(dir, NULL) != 0);
+#elif defined(__WXPALMOS__)
+ // TODO with VFSFileRename()
+ return false;
#else
return (wxRmDir(OS_FILENAME(dir)) == 0);
#endif
-
-#endif
}
// does the path exists? (may have or not '/' or '\\' at the end)
-bool wxPathExists(const wxChar *pszPathName)
+bool wxDirExists(const wxChar *pszPathName)
{
wxString strPath(pszPathName);
strPath << _T('.');
#endif
-#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+#if defined(__WXPALMOS__)
+ return false;
+#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
// stat() can't cope with network paths
DWORD ret = ::GetFileAttributes(strPath);
return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY);
+#elif defined(__OS2__)
+ return (::DosSetCurrentDir((PSZ)(WXSTRINGCAST strPath)));
#else // !__WIN32__
wxStructStat st;
// Get a temporary filename, opening and closing the file.
wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf)
{
+#if wxUSE_FILE
wxString filename = wxFileName::CreateTempFileName(prefix);
if ( filename.empty() )
return NULL;
buf = MYcopystring(filename);
return buf;
+#else
+ wxUnusedVar(prefix);
+ wxUnusedVar(buf);
+ // wxFileName::CreateTempFileName needs wxFile class enabled
+ return NULL;
+#endif
}
bool wxGetTempFileName(const wxString& prefix, wxString& buf)
{
- buf = wxFileName::CreateTempFileName(prefix);
+ buf = wxGetTempFileName(prefix);
return !buf.empty();
}
wxString wxFindFirstFile(const wxChar *spec, int flags)
{
wxSplitPath(spec, &gs_dirPath, NULL, NULL);
- if ( gs_dirPath.IsEmpty() )
+ if ( gs_dirPath.empty() )
gs_dirPath = wxT(".");
if ( !wxEndsWithPathSeparator(gs_dirPath ) )
gs_dirPath << wxFILE_SEP_PATH;
wxString result;
gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags);
- if ( result.IsEmpty() )
+ if ( result.empty() )
{
wxDELETE(gs_dir);
return result;
wxString result;
gs_dir->GetNext(&result);
- if ( result.IsEmpty() )
+ if ( result.empty() )
{
wxDELETE(gs_dir);
return result;
// copies into buf.
wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
{
-#ifdef __WXWINCE__
+#if defined(__WXPALMOS__)
+ // TODO ?
+ return NULL;
+#elif defined(__WXWINCE__)
+ // TODO
+ wxUnusedVar(buf);
+ wxUnusedVar(sz);
return NULL;
#else
if ( !buf )
if ( getcwd( lbuf , sizeof( lbuf ) ) )
{
wxString res( lbuf , *wxConvCurrent ) ;
- wxStrcpy( buf , res ) ;
+ wxStrcpy( buf , res ) ;
ok = true;
}
else
APIRET rc;
ULONG ulDriveNum = 0;
ULONG ulDriveMap = 0;
- rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
+ rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
ok = rc == 0;
- if (ok)
- {
- sz -= 3;
- rc = ::DosQueryCurrentDir( 0 // current drive
+ if (ok)
+ {
+ sz -= 3;
+ rc = ::DosQueryCurrentDir( 0 // current drive
,cbuf + 3
,(PULONG)&sz
);
#elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
return (chdir(wxFNSTRINGCAST d.fn_str()) == 0);
#elif defined(__WINDOWS__)
-
+
#ifdef __WIN32__
#ifdef __WXWINCE__
// No equivalent in WinCE
+ wxUnusedVar(d);
return false;
#else
return (bool)(SetCurrentDirectory(d) != 0);
if (isDriveSpec)
{
wxChar firstChar = d[0];
-
+
// To upper case
if (firstChar > 90)
firstChar = firstChar - 32;
-
+
// To a drive number
unsigned int driveNo = firstChar - 64;
if (driveNo > 0)
}
}
bool success = (chdir(WXSTRINGCAST d) == 0);
-
+
return success;
#endif
-
+
#endif
}
time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
{
-#ifdef __WXWINCE__
+#if defined(__WXPALMOS__)
+ return 0;
+#elif defined(__WXWINCE__)
FILETIME creationTime, lastAccessTime, lastWriteTime;
HANDLE fileHandle = ::CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
0, FILE_ATTRIBUTE_NORMAL, 0);
{
wxLogLastError(_T("FileTimeToLocalFileTime"));
}
-
+
SYSTEMTIME st;
if ( !::FileTimeToSystemTime(&ftLocal, &st) )
{
wxLogLastError(_T("FileTimeToSystemTime"));
}
-
+
dateTime.Set(st.wDay, wxDateTime::Month(st.wMonth - 1), st.wYear,
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
return dateTime.GetTicks();
// autocompletion
for( size_t j = 0 ; j < descriptions.GetCount() ; j++ )
{
- if ( descriptions[j] == wxEmptyString && filters[j] != wxEmptyString )
+ if ( descriptions[j].empty() && !filters[j].empty() )
{
descriptions[j].Printf(_("Files (%s)"), filters[j].c_str());
}
}
}
+// Return the type of an open file
+//
+// Some file types on some platforms seem seekable but in fact are not.
+// The main use of this function is to allow such cases to be detected
+// (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
+//
+// This is important for the archive streams, which benefit greatly from
+// being able to seek on a stream, but which will produce corrupt archives
+// if they unknowingly seek on a non-seekable stream.
+//
+// wxFILE_KIND_DISK is a good catch all return value, since other values
+// disable features of the archive streams. Some other value must be returned
+// for a file type that appears seekable but isn't.
+//
+// Known examples:
+// * Pipes on Windows
+// * Files on VMS with a record format other than StreamLF
+//
+wxFileKind wxGetFileKind(int fd)
+{
+#if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
+ switch (::GetFileType(wxGetOSFHandle(fd)) & ~FILE_TYPE_REMOTE)
+ {
+ case FILE_TYPE_CHAR:
+ return wxFILE_KIND_TERMINAL;
+ case FILE_TYPE_DISK:
+ return wxFILE_KIND_DISK;
+ case FILE_TYPE_PIPE:
+ return wxFILE_KIND_PIPE;
+ }
+
+ return wxFILE_KIND_UNKNOWN;
+
+#elif defined(__UNIX__)
+ if (isatty(fd))
+ return wxFILE_KIND_TERMINAL;
+
+ struct stat st;
+ fstat(fd, &st);
+
+ if (S_ISFIFO(st.st_mode))
+ return wxFILE_KIND_PIPE;
+ if (!S_ISREG(st.st_mode))
+ return wxFILE_KIND_UNKNOWN;
+
+ #if defined(__VMS__)
+ if (st.st_fab_rfm != FAB$C_STMLF)
+ return wxFILE_KIND_UNKNOWN;
+ #endif
+
+ return wxFILE_KIND_DISK;
+
+#else
+ #define wxFILEKIND_STUB
+ (void)fd;
+ return wxFILE_KIND_DISK;
+#endif
+}
+
+wxFileKind wxGetFileKind(FILE *fp)
+{
+ // Note: The watcom rtl dll doesn't have fileno (the static lib does).
+ // Should be fixed in version 1.4.
+#if defined(wxFILEKIND_STUB) || \
+ (defined(__WATCOMC__) && __WATCOMC__ <= 1230 && defined(__SW_BR))
+ (void)fp;
+ return wxFILE_KIND_DISK;
+#else
+ return wxGetFileKind(fileno(fp));
+#endif
+}
#ifdef __VISUALC__
#pragma warning(default:4706) // assignment within conditional expression