#include "filesystem.h" #if _WIN32 #include #elif __APPLE__ #include #include #include #include #include #include #include #include #elif __linux #include #include #include #include #include #else #include #include #include #include #include #endif namespace bbFileSystem{ bbString _appDir; bbString _appPath; bbArray _appArgs; struct GCRoot : public bbGCRoot{ void gcMark(){ bbGCMark( _appArgs ); } }; GCRoot root; void init(){ static bool done; if( done ) return; done=true; _appArgs=bbArray( bb_argc ); for( int i=0;i0 && i appArgs(){ init(); return _appArgs; } bbBool copyFile( bbString srcPath,bbString dstPath ){ #if _WIN32 return CopyFileA( bbTString( srcPath ),bbTString( dstPath ),FALSE ); #elif __APPLE__ int ret=copyfile( bbTString( srcPath ),bbTString( dstPath ),0,COPYFILE_ALL ); if( ret>=0 ) return true; // printf( "copyfile failed, ret=%i\n",ret ); // printf( "src=%s\n",srcPath.c_str() ); // printf( "dst=%s\n",dstPath.c_str() ); return false; #else //TODO: use sendfile() here? // int err=-1; if( FILE *srcp=fopen( bbTString( srcPath ),"rb" ) ){ err=-2; if( FILE *dstp=fopen( bbTString( dstPath ),"wb" ) ){ err=0; char buf[1024]; while( int n=fread( buf,1,1024,srcp ) ){ if( fwrite( buf,1,n,dstp )!=n ){ err=-3; break; } } fclose( dstp ); }else{ // printf( "FOPEN 'wb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) ); fflush( stdout ); } fclose( srcp ); }else{ // printf( "FOPEN 'rb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) ); fflush( stdout ); } return err==0; #endif } }