Permalink
Browse files

+ Linux compatibility

  • Loading branch information...
1 parent 64441e7 commit 212e71f81fd9de5fd48b321fffe2e89f212004e3 ru committed Nov 15, 2011
Showing with 206 additions and 13 deletions.
  1. +1 −1 lib/oexlib/src/os/posix/base_file.cpp
  2. +1 −1 tools/cii/Makefile
  3. +189 −6 tools/cii/disk.cpp
  4. +2 −2 tools/cii/disk.h
  5. +2 −1 tools/cii/process_cpp.h
  6. +11 −2 tools/cii/str.cpp
@@ -437,7 +437,7 @@ CBaseFile::t_HFIND CBaseFile::FindFirst( oexCSTR x_pPath, oexCSTR x_pMask, CBase
return CBaseFile::c_InvalidFindHandle;
DIR *hDir = opendir( oexStrToMbPtr( x_pPath ) );
- if ( CBaseFile::c_InvalidFindHandle == hDir )
+ if ( !hDir )
return CBaseFile::c_InvalidFindHandle;
errno = 0;
View
@@ -8,7 +8,7 @@ default_target: all
# Project
#-------------------------------------------------------------------
PRJ_NAME := cii
-PRJ_DEPS := qt-win
+#PRJ_DEPS := qt-win
PRJ_TYPE := exe
PRJ_INCS :=
PRJ_LIBS :=
View
@@ -2,22 +2,29 @@
#if defined( _WIN32 )
# include <Windows.h>
-# include <stdio.h>
#else
+# include <errno.h>
+# include <sys/stat.h>
+# include <sys/types.h>
+# if !defined( CII_NODIRENT )
+# include <dirent.h>
+# endif
#endif
+#include <stdio.h>
#include <string>
+#include <string.h>
#include "str.h"
#include "disk.h"
namespace disk
{
-#if defined( _WIN32 )
+//#if defined( _WIN32 )
typedef FILE* tHFILE;
-#else
- typedef int tHFILE;
-#endif
+//#else
+// typedef int tHFILE;
+//#endif
HFILE Open( const char *x_pFile, const char *x_pMode )
{
@@ -158,6 +165,182 @@ bool FindClose( HFIND x_hFind )
#else
+bool mkdir( const char *x_pPath )
+{
+ if ( !x_pPath || !*x_pPath )
+ return false;
+
+ bool bRet = !::mkdir( x_pPath, 0755 ) ? true : false;
+ if ( bRet )
+ { ::chmod( x_pPath, 0755 );
+ return true;
+ } // end if
+
+ return false;
+}
+
+bool exists( const char *x_pPath )
+{
+#if defined( CII_NOSTAT64 )
+ struct stat s;
+ return ::stat( x_pPath, &s ) ? false : true;
+#else
+ struct stat64 s64;
+ return ::stat64( x_pPath, &s64 ) ? false : true;
+#endif
+}
+
+bool unlink( const char *x_pFile )
+{
+ if ( !x_pFile )
+ return false;
+
+ ::chmod( x_pFile, 0xffff );
+ return ::unlink( x_pFile ) ? false : true;
+}
+
+bool rmdir( const char *x_pPath )
+{
+ if ( !x_pPath )
+ return false;
+
+ ::chmod( x_pPath, 0xffff );
+ return ::rmdir( x_pPath ) ? false : true;
+}
+
+str::tc_int64 Size( const char *x_pFile )
+{
+ if ( !x_pFile || !*x_pFile )
+ return 0;
+
+#if defined( CII_NOSTAT64 )
+
+ struct stat s;
+ if ( stat( x_pFile, &s ) )
+ return 0;
+
+ return s.st_size;
+
+#else
+
+ // +++ Ensure this works correctly
+ struct stat64 s64;
+ if ( stat64( x_pFile, &s64 ) )
+ return 0;
+
+ return s64.st_size;
+
+#endif
+}
+
+str::tc_int64 Size( HFILE x_hFile )
+{
+ // Ensure valid handle
+ if ( c_invalid_hfile == x_hFile )
+ return 0;
+
+#if defined( CII_NOSTAT64 )
+
+ struct stat s;
+ if ( fstat( x_hFile, &s ) )
+ return 0;
+
+ return s.st_size;
+
+#else
+
+ struct stat64 s64;
+
+ // +++ Ensure this works correctly
+ if ( fstat64( x_hFile, &s64 ) )
+ return 0;
+
+ return s64.st_size;
+
+#endif
+}
+
+
+static void disk_InitFindData( SFindData *x_pFd )
+{ x_pFd->llSize = 0;
+ *x_pFd->szName = 0;
+ x_pFd->uFileAttributes = 0;
+ x_pFd->ftCreated = 0;
+ x_pFd->ftLastAccess = 0;
+ x_pFd->ftLastModified = 0;
+}
+
+static void disk_SetFindData( SFindData *x_pFd, const dirent *x_pD )
+{
+ if ( ! x_pFd || !x_pD )
+ return;
+
+ // Init structure
+ disk_InitFindData( x_pFd );
+
+ // Save file name
+ zstr::Copy( x_pFd->szName, sizeof( x_pFd->szName ), x_pD->d_name );
+
+ // Is it a directory?
+ if ( DT_DIR & x_pD->d_type )
+ x_pFd->uFileAttributes |= disk::eFileAttribDirectory;
+}
+
+HFIND FindFirst( const char *x_pPath, const char *x_pMask, SFindData *x_pFd )
+{
+#if defined( CII_NODIRENT )
+ return c_invalid_hfind;
+#else
+
+ // Sanity checks
+ if ( !x_pPath || ! x_pMask || ! x_pFd )
+ return c_invalid_hfind;
+
+ DIR *hDir = opendir( x_pPath );
+ if ( !hDir )
+ return c_invalid_hfind;
+
+ errno = 0;
+ struct dirent *pD = readdir( hDir );
+ if ( !pD || errno )
+ { closedir( hDir );
+ return c_invalid_hfind;
+ } // end if
+
+ // Set file data
+ disk_SetFindData( x_pFd, pD );
+
+ return (HFIND)hDir;
+#endif
+}
+
+bool FindNext( HFIND x_hFind, SFindData *x_pFd )
+{
+#if defined( CII_NODIRENT )
+ return false;
+#else
+ DIR *hDir = (DIR*)x_hFind;
+
+ errno = 0;
+ struct dirent *pD = readdir( hDir );
+ if ( !pD || errno )
+ return false;
+
+ disk_SetFindData( x_pFd, pD );
+
+ return true;
+#endif
+}
+
+bool FindClose( HFIND x_hFind )
+{
+#if defined( CII_NODIRENT )
+ return false;
+#else
+ return closedir( (DIR*)x_hFind ) ? false : true;
+#endif
+}
+
#endif
-}; // namespace ff
+}; // namespace ff
View
@@ -116,7 +116,7 @@ namespace disk
+ sep
+ LTrim( LTrim( s2, tcTC( T, '\\' ) ), tcTC( T, '/' ) );
#else
- return WebPath( s1, s2 );
+ return WebPath< T, T_STR >( s1, s2 );
#endif
}
@@ -295,4 +295,4 @@ namespace disk
return sData;
}
-}; // namespace ff
+}; // namespace ff
@@ -1,6 +1,7 @@
#pragma once
+#include <string.h>
#include "str.h"
/// Returns non-zero if the character is a valid html character
@@ -52,7 +53,7 @@ template< typename T, typename T_STR >
return T_STR();
T_STR ret;
- T_STR::size_type nStart = 0, nPos = 0;
+ typename T_STR::size_type nStart = 0, nPos = 0;
while ( nPos < x_lSize )
{
View
@@ -3,11 +3,16 @@
#include <stdio.h>
#include <stdlib.h>
-#if defined( _WIN32_WCE ) || defined( __MINGW32__ )
+#if !defined( _WIN32 ) || defined( _WIN32_WCE ) || defined( __MINGW32__ )
+# include <stdarg.h>
# include <wchar.h>
# define VSNPRINTF vsnprintf
# define STRTOLL strtoll
+#if defined( __MINGW32__ )
# define VSNWPRINTF vsnwprintf
+#else
+# define VSNWPRINTF vswprintf
+#endif
# define WCSTOLL wcstoll
# define CAST_VL tcVaList
#else
@@ -153,7 +158,11 @@ long vStrFmt( wchar_t *x_pDst, unsigned long x_uMax, const wchar_t *x_pFmt, tcVa
return -1;
// Create format string
+#if !defined( _WIN32 )
long nRet = (long)VSNWPRINTF( x_pDst, x_uMax, x_pFmt, (CAST_VL)x_pArgs );
+#else
+ long nRet = (long)VSNWPRINTF( x_pDst, x_pFmt, (CAST_VL)x_pArgs );
+#endif
if ( 0 > nRet || x_uMax < (unsigned long)nRet )
{
// Null terminate buffer
@@ -234,4 +243,4 @@ double StrToDouble( const wchar_t *x_pStr )
#endif
-}; // namespace str
+}; // namespace str

0 comments on commit 212e71f

Please sign in to comment.