Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

+ Linux compatibility

  • Loading branch information...
commit 212e71f81fd9de5fd48b321fffe2e89f212004e3 1 parent 64441e7
authored November 14, 2011
2  lib/oexlib/src/os/posix/base_file.cpp
@@ -437,7 +437,7 @@ CBaseFile::t_HFIND CBaseFile::FindFirst( oexCSTR x_pPath, oexCSTR x_pMask, CBase
437 437
         return CBaseFile::c_InvalidFindHandle;
438 438
 
439 439
 	DIR *hDir = opendir( oexStrToMbPtr( x_pPath ) );
440  
-	if ( CBaseFile::c_InvalidFindHandle == hDir )
  440
+	if ( !hDir )
441 441
 		return CBaseFile::c_InvalidFindHandle;
442 442
 
443 443
 	errno = 0;
2  tools/cii/Makefile
@@ -8,7 +8,7 @@ default_target: all
8 8
 # Project
9 9
 #-------------------------------------------------------------------
10 10
 PRJ_NAME := cii
11  
-PRJ_DEPS := qt-win
  11
+#PRJ_DEPS := qt-win
12 12
 PRJ_TYPE := exe
13 13
 PRJ_INCS := 
14 14
 PRJ_LIBS := 
195  tools/cii/disk.cpp
@@ -2,22 +2,29 @@
2 2
 
3 3
 #if defined( _WIN32 )
4 4
 #	include <Windows.h>
5  
-#	include <stdio.h>
6 5
 #else
  6
+#	include <errno.h>
  7
+#	include <sys/stat.h>
  8
+#	include <sys/types.h>
  9
+#	if !defined( CII_NODIRENT )
  10
+#		include <dirent.h>
  11
+#	endif
7 12
 #endif
8 13
 
  14
+#include <stdio.h>
9 15
 #include <string>
  16
+#include <string.h>
10 17
 #include "str.h"
11 18
 #include "disk.h"
12 19
 
13 20
 namespace disk
14 21
 {
15 22
 
16  
-#if defined( _WIN32 )
  23
+//#if defined( _WIN32 )
17 24
 		typedef FILE* tHFILE;
18  
-#else
19  
-		typedef int tHFILE;
20  
-#endif
  25
+//#else
  26
+//		typedef int tHFILE;
  27
+//#endif
21 28
 
22 29
 HFILE Open( const char *x_pFile, const char *x_pMode )
23 30
 {
@@ -158,6 +165,182 @@ bool FindClose( HFIND x_hFind )
158 165
 
159 166
 #else
160 167
 
  168
+bool mkdir( const char *x_pPath )
  169
+{
  170
+	if ( !x_pPath || !*x_pPath )
  171
+		return false;
  172
+
  173
+	bool bRet = !::mkdir( x_pPath, 0755 ) ? true : false;
  174
+	if ( bRet )
  175
+	{	::chmod( x_pPath, 0755 );
  176
+		return true;
  177
+	} // end if
  178
+
  179
+	return false;
  180
+}
  181
+
  182
+bool exists( const char *x_pPath )
  183
+{
  184
+#if defined( CII_NOSTAT64 )
  185
+	struct stat s;
  186
+	return ::stat( x_pPath, &s ) ? false : true;
  187
+#else
  188
+	struct stat64 s64;
  189
+	return	::stat64( x_pPath, &s64 ) ? false : true;
  190
+#endif
  191
+}
  192
+
  193
+bool unlink( const char *x_pFile )
  194
+{
  195
+	if ( !x_pFile )
  196
+		return false;
  197
+
  198
+	::chmod( x_pFile, 0xffff );
  199
+	return ::unlink( x_pFile ) ? false : true;
  200
+}
  201
+
  202
+bool rmdir( const char *x_pPath )
  203
+{
  204
+	if ( !x_pPath )
  205
+		return false;
  206
+
  207
+	::chmod( x_pPath, 0xffff );
  208
+	return ::rmdir( x_pPath ) ? false : true;
  209
+}
  210
+
  211
+str::tc_int64 Size( const char *x_pFile )
  212
+{
  213
+	if ( !x_pFile || !*x_pFile )
  214
+		return 0;
  215
+
  216
+#if defined( CII_NOSTAT64 )
  217
+
  218
+	struct stat s;
  219
+	if ( stat( x_pFile, &s ) )
  220
+		return 0;
  221
+
  222
+	return s.st_size;
  223
+
  224
+#else
  225
+
  226
+	// +++ Ensure this works correctly
  227
+	struct stat64 s64;
  228
+	if ( stat64( x_pFile, &s64 ) )
  229
+		return 0;
  230
+
  231
+	return s64.st_size;
  232
+
  233
+#endif
  234
+}
  235
+
  236
+str::tc_int64 Size( HFILE x_hFile )
  237
+{
  238
+	// Ensure valid handle
  239
+	if ( c_invalid_hfile == x_hFile ) 
  240
+		return 0;
  241
+
  242
+#if defined( CII_NOSTAT64 )
  243
+
  244
+	struct stat s;
  245
+	if ( fstat( x_hFile, &s ) )
  246
+		return 0;
  247
+
  248
+	return s.st_size;
  249
+
  250
+#else
  251
+
  252
+	struct stat64 s64;
  253
+
  254
+	// +++ Ensure this works correctly
  255
+	if ( fstat64( x_hFile, &s64 ) )
  256
+		return 0;
  257
+
  258
+	return s64.st_size;
  259
+
  260
+#endif
  261
+}
  262
+
  263
+
  264
+static void disk_InitFindData( SFindData *x_pFd )
  265
+{   x_pFd->llSize = 0;
  266
+    *x_pFd->szName = 0;
  267
+    x_pFd->uFileAttributes = 0;
  268
+    x_pFd->ftCreated = 0;
  269
+    x_pFd->ftLastAccess = 0;
  270
+    x_pFd->ftLastModified = 0;
  271
+}
  272
+
  273
+static void disk_SetFindData( SFindData *x_pFd, const dirent *x_pD )
  274
+{
  275
+	if ( ! x_pFd || !x_pD )
  276
+		return;
  277
+
  278
+	// Init structure
  279
+	disk_InitFindData( x_pFd );
  280
+
  281
+	// Save file name
  282
+	zstr::Copy( x_pFd->szName, sizeof( x_pFd->szName ), x_pD->d_name );
  283
+
  284
+	// Is it a directory?
  285
+	if ( DT_DIR & x_pD->d_type )
  286
+		x_pFd->uFileAttributes |= disk::eFileAttribDirectory;
  287
+}
  288
+
  289
+HFIND FindFirst( const char *x_pPath, const char *x_pMask, SFindData *x_pFd )
  290
+{
  291
+#if defined( CII_NODIRENT )
  292
+	return c_invalid_hfind;
  293
+#else
  294
+
  295
+    // Sanity checks
  296
+    if ( !x_pPath || ! x_pMask || ! x_pFd )
  297
+        return c_invalid_hfind;
  298
+
  299
+	DIR *hDir = opendir( x_pPath );
  300
+	if ( !hDir )
  301
+		return c_invalid_hfind;
  302
+
  303
+	errno = 0;
  304
+	struct dirent *pD = readdir( hDir );
  305
+	if ( !pD || errno )
  306
+	{	closedir( hDir );
  307
+		return c_invalid_hfind;
  308
+	} // end if
  309
+
  310
+	// Set file data
  311
+	disk_SetFindData( x_pFd, pD );
  312
+
  313
+    return (HFIND)hDir;
  314
+#endif
  315
+}
  316
+
  317
+bool FindNext( HFIND x_hFind, SFindData *x_pFd )
  318
+{
  319
+#if defined( CII_NODIRENT )
  320
+	return false;
  321
+#else
  322
+	DIR *hDir = (DIR*)x_hFind;
  323
+
  324
+	errno = 0;
  325
+	struct dirent *pD = readdir( hDir );
  326
+	if ( !pD || errno )
  327
+		return false;
  328
+
  329
+	disk_SetFindData( x_pFd, pD );
  330
+
  331
+    return true;
  332
+#endif
  333
+}
  334
+
  335
+bool FindClose( HFIND x_hFind )
  336
+{
  337
+#if defined( CII_NODIRENT )
  338
+	return false;
  339
+#else
  340
+	return closedir( (DIR*)x_hFind ) ? false : true;
  341
+#endif
  342
+}
  343
+
161 344
 #endif
162 345
 
163  
-}; // namespace ff
  346
+}; // namespace ff
4  tools/cii/disk.h
@@ -116,7 +116,7 @@ namespace disk
116 116
 				   + sep
117 117
 				   + LTrim( LTrim( s2, tcTC( T, '\\' ) ), tcTC( T, '/' ) );
118 118
 #else
119  
-			return WebPath( s1, s2 );
  119
+			return WebPath< T, T_STR >( s1, s2 );
120 120
 #endif
121 121
 		}
122 122
 
@@ -295,4 +295,4 @@ namespace disk
295 295
 			return sData;
296 296
 		}
297 297
 
298  
-}; // namespace ff
  298
+}; // namespace ff
3  tools/cii/process_cpp.h
... ...
@@ -1,6 +1,7 @@
1 1
 
2 2
 #pragma once
3 3
 
  4
+#include <string.h>
4 5
 #include "str.h"
5 6
 
6 7
 /// Returns non-zero if the character is a valid html character
@@ -52,7 +53,7 @@ template< typename T, typename T_STR >
52 53
 			return T_STR();
53 54
 		
54 55
 		T_STR ret;
55  
-		T_STR::size_type nStart = 0, nPos = 0;
  56
+		typename T_STR::size_type nStart = 0, nPos = 0;
56 57
 
57 58
 		while ( nPos < x_lSize )
58 59
 		{
13  tools/cii/str.cpp
@@ -3,11 +3,16 @@
3 3
 #include <stdio.h>
4 4
 #include <stdlib.h>
5 5
 
6  
-#if defined( _WIN32_WCE ) || defined( __MINGW32__ )
  6
+#if !defined( _WIN32 ) || defined( _WIN32_WCE ) || defined( __MINGW32__ )
  7
+#	include <stdarg.h>
7 8
 #	include <wchar.h>
8 9
 #	define VSNPRINTF		vsnprintf
9 10
 #	define STRTOLL			strtoll
  11
+#if defined( __MINGW32__ )
10 12
 #	define VSNWPRINTF		vsnwprintf
  13
+#else
  14
+#	define VSNWPRINTF		vswprintf
  15
+#endif
11 16
 #	define WCSTOLL			wcstoll
12 17
 #	define CAST_VL			tcVaList
13 18
 #else
@@ -153,7 +158,11 @@ long vStrFmt( wchar_t *x_pDst, unsigned long x_uMax, const wchar_t *x_pFmt, tcVa
153 158
 		return -1;
154 159
 
155 160
 	// Create format string
  161
+#if !defined( _WIN32 )
156 162
 	long nRet = (long)VSNWPRINTF( x_pDst, x_uMax, x_pFmt, (CAST_VL)x_pArgs );
  163
+#else
  164
+	long nRet = (long)VSNWPRINTF( x_pDst, x_pFmt, (CAST_VL)x_pArgs );
  165
+#endif
157 166
 	if ( 0 > nRet || x_uMax < (unsigned long)nRet )
158 167
 	{
159 168
 		// Null terminate buffer
@@ -234,4 +243,4 @@ double StrToDouble( const wchar_t *x_pStr )
234 243
 
235 244
 #endif
236 245
 
237  
-}; // namespace str
  246
+}; // namespace str

0 notes on commit 212e71f

Please sign in to comment.
Something went wrong with that request. Please try again.