Monday, April 30, 2012

My DD

Here's a pretty simple dd in ANSI C.
I am really planning do more with it, like the dd for linux!

Code (Very much simplistic)

// by iamjuza, iamjuza [at] gmail [dot] com, 2012
#include "commons.h"
#include <stdio.h>
int main(int argc, char** argv)
{
if (argc == 3)
{
FILE* pFileIf;
FILE* pFileOf;
PUBYTE pBuffer;
UDWORD dwLength;
pFileIf = fopen(*(argv + 1) ,"rb");
pFileOf = fopen(*(argv + 2) ,"wb");
if (NULL == pFileIf)
{
perror("Error: If not valid ");
exit(1);
}
if (NULL == pFileOf)
{
perror("Error: Of not valid ");
exit(2);
}
pBuffer = (PUBYTE) malloc(MAX_PATH * sizeof(PUBYTE));
if (NULL == pBuffer)
{
perror("Error: Can't alloc the required memory ");
exit(3);
}
while(dwLength = fread(pBuffer, 1, MAX_BUFFER, pFileIf))
fwrite(pBuffer, 1, dwLength, pFileOf);
fclose(pFileIf);
fclose(pFileOf);
free(pBuffer);
}
else
{
printf("Please CAUTION!"
"\nUsage: %s <if> <of>\n", *(argv));
}
return 0;
}
view raw gistfile1.c hosted with ❤ by GitHub


Example:


Output:



Download the full code here!

Enjoy!

No comments: