-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 133399c
Showing
3 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <windows.h> | ||
#include <stdio.h> | ||
|
||
#define MIN(a,b) (((a)<(b))?(a):(b)) | ||
|
||
HANDLE newFile( size_t cpt ) | ||
{ | ||
HANDLE hOut ; | ||
cpt++ ; | ||
TCHAR szOutputFilename[MAX_PATH]; | ||
sprintf( szOutputFilename, "%05d", cpt ); | ||
hOut = ::CreateFile( szOutputFilename, | ||
GENERIC_WRITE, | ||
FILE_SHARE_WRITE, | ||
NULL, | ||
CREATE_ALWAYS, | ||
FILE_ATTRIBUTE_NORMAL, | ||
NULL ); | ||
if ( hOut == INVALID_HANDLE_VALUE ) | ||
{ | ||
fprintf( stderr, "Err create output file\n" ); | ||
return INVALID_HANDLE_VALUE ; | ||
} | ||
printf("File %s...\n", szOutputFilename); | ||
return hOut ; | ||
} | ||
|
||
|
||
BOOL byFile( HANDLE hIn, int size ) | ||
{ | ||
const int chunk_size = 1024 * size ; | ||
const int BUFF_SIZE = 65535; | ||
|
||
size_t cpt = 0 ; | ||
|
||
HANDLE hOut = newFile(cpt) ; | ||
|
||
size_t to_process = chunk_size ; | ||
|
||
char* buff = new char[BUFF_SIZE] ; | ||
DWORD toRead = BUFF_SIZE ; | ||
DWORD read ; | ||
while( ::ReadFile( hIn, buff, toRead, &read, NULL ) ) { | ||
|
||
DWORD written ; | ||
if ( ::WriteFile( hOut, buff, read, &written, NULL ) == FALSE ) | ||
{ | ||
fprintf( stderr, "Err write output file\n" ); | ||
return FALSE ; | ||
} | ||
|
||
if ( read != toRead ) | ||
break ; //eof | ||
|
||
to_process -= read ; | ||
|
||
if ( to_process == 0 ) | ||
{ | ||
::CloseHandle(hOut); | ||
hOut = newFile(++cpt); | ||
to_process = chunk_size ; | ||
toRead = BUFF_SIZE ; | ||
} | ||
|
||
//take min value to nxt read | ||
toRead = MIN( to_process, toRead ); | ||
} | ||
|
||
delete []buff ; | ||
::CloseHandle(hOut); | ||
return TRUE ; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if ( argc != 3 ) | ||
{ | ||
printf("Program usage:\n\t split.exe input_filename size\nWhere size are in kBytes\n"); | ||
return 1 ; | ||
} | ||
|
||
HANDLE hIn = ::CreateFile( argv[1], | ||
GENERIC_READ, | ||
FILE_SHARE_READ, | ||
NULL, | ||
OPEN_EXISTING, | ||
FILE_ATTRIBUTE_NORMAL, | ||
NULL ); | ||
|
||
size_t chunk_size = atoi( argv[2] ); | ||
|
||
if( hIn == INVALID_HANDLE_VALUE ) { | ||
fprintf( stderr, "Error input file\n"); | ||
return 1 ; | ||
} | ||
|
||
byFile( hIn, chunk_size ); | ||
|
||
::CloseHandle( hIn ); | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?xml version="1.0" encoding="Windows-1252"?> | ||
<VisualStudioProject | ||
ProjectType="Visual C++" | ||
Version="9,00" | ||
Name="split" | ||
ProjectGUID="{4CE4FD2C-BDE0-462E-A0B9-C694B377CECE}" | ||
RootNamespace="split" | ||
Keyword="Win32Proj" | ||
TargetFrameworkVersion="196613" | ||
> | ||
<Platforms> | ||
<Platform | ||
Name="Win32" | ||
/> | ||
</Platforms> | ||
<ToolFiles> | ||
</ToolFiles> | ||
<Configurations> | ||
<Configuration | ||
Name="Debug|Win32" | ||
OutputDirectory="$(SolutionDir)$(ConfigurationName)" | ||
IntermediateDirectory="$(ConfigurationName)" | ||
ConfigurationType="1" | ||
CharacterSet="2" | ||
> | ||
<Tool | ||
Name="VCPreBuildEventTool" | ||
/> | ||
<Tool | ||
Name="VCCustomBuildTool" | ||
/> | ||
<Tool | ||
Name="VCXMLDataGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCWebServiceProxyGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCMIDLTool" | ||
/> | ||
<Tool | ||
Name="VCCLCompilerTool" | ||
Optimization="0" | ||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | ||
MinimalRebuild="true" | ||
BasicRuntimeChecks="3" | ||
RuntimeLibrary="3" | ||
UsePrecompiledHeader="0" | ||
WarningLevel="3" | ||
DebugInformationFormat="4" | ||
/> | ||
<Tool | ||
Name="VCManagedResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCPreLinkEventTool" | ||
/> | ||
<Tool | ||
Name="VCLinkerTool" | ||
LinkIncremental="2" | ||
GenerateDebugInformation="true" | ||
SubSystem="1" | ||
TargetMachine="1" | ||
/> | ||
<Tool | ||
Name="VCALinkTool" | ||
/> | ||
<Tool | ||
Name="VCManifestTool" | ||
/> | ||
<Tool | ||
Name="VCXDCMakeTool" | ||
/> | ||
<Tool | ||
Name="VCBscMakeTool" | ||
/> | ||
<Tool | ||
Name="VCFxCopTool" | ||
/> | ||
<Tool | ||
Name="VCAppVerifierTool" | ||
/> | ||
<Tool | ||
Name="VCPostBuildEventTool" | ||
/> | ||
</Configuration> | ||
<Configuration | ||
Name="Release|Win32" | ||
OutputDirectory="$(SolutionDir)$(ConfigurationName)" | ||
IntermediateDirectory="$(ConfigurationName)" | ||
ConfigurationType="1" | ||
CharacterSet="2" | ||
WholeProgramOptimization="1" | ||
> | ||
<Tool | ||
Name="VCPreBuildEventTool" | ||
/> | ||
<Tool | ||
Name="VCCustomBuildTool" | ||
/> | ||
<Tool | ||
Name="VCXMLDataGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCWebServiceProxyGeneratorTool" | ||
/> | ||
<Tool | ||
Name="VCMIDLTool" | ||
/> | ||
<Tool | ||
Name="VCCLCompilerTool" | ||
Optimization="2" | ||
EnableIntrinsicFunctions="true" | ||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" | ||
RuntimeLibrary="2" | ||
EnableFunctionLevelLinking="true" | ||
UsePrecompiledHeader="0" | ||
WarningLevel="3" | ||
DebugInformationFormat="3" | ||
/> | ||
<Tool | ||
Name="VCManagedResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCResourceCompilerTool" | ||
/> | ||
<Tool | ||
Name="VCPreLinkEventTool" | ||
/> | ||
<Tool | ||
Name="VCLinkerTool" | ||
LinkIncremental="1" | ||
GenerateDebugInformation="true" | ||
SubSystem="1" | ||
OptimizeReferences="2" | ||
EnableCOMDATFolding="2" | ||
TargetMachine="1" | ||
/> | ||
<Tool | ||
Name="VCALinkTool" | ||
/> | ||
<Tool | ||
Name="VCManifestTool" | ||
/> | ||
<Tool | ||
Name="VCXDCMakeTool" | ||
/> | ||
<Tool | ||
Name="VCBscMakeTool" | ||
/> | ||
<Tool | ||
Name="VCFxCopTool" | ||
/> | ||
<Tool | ||
Name="VCAppVerifierTool" | ||
/> | ||
<Tool | ||
Name="VCPostBuildEventTool" | ||
/> | ||
</Configuration> | ||
</Configurations> | ||
<References> | ||
</References> | ||
<Files> | ||
<Filter | ||
Name="Source Files" | ||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" | ||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | ||
> | ||
<File | ||
RelativePath=".\split.cpp" | ||
> | ||
</File> | ||
</Filter> | ||
<Filter | ||
Name="Header Files" | ||
Filter="h;hpp;hxx;hm;inl;inc;xsd" | ||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | ||
> | ||
</Filter> | ||
<Filter | ||
Name="Resource Files" | ||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" | ||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | ||
> | ||
</Filter> | ||
</Files> | ||
<Globals> | ||
</Globals> | ||
</VisualStudioProject> |