Could it be that you are not using the binary file switch. For fopen it would be a b suffix as in
"wb"Create a binary file for writing
I don't have my reference available for open, however it would probably be O_BINARY or O_BIN or some such thing.
Dmitry Sidorov <si...@si...> wrote:
Hello, dev-cpp-users.
I try to save binary data recieved from TCP socket into the file
...
#define DATA_BUFSIZE 4096
long totalRcvd = 0;
long nFileSize = 0;
int bytesRecv = SOCKET_ERROR;
char recvbuf[DATA_BUFSIZE];
int fd = open( "filename", O_CREAT|O_WRONLY );
while( bytesRecv == SOCKET_ERROR || bytesRecv > 0 ) {
bytesRecv = recv( sock, recvbuf, DATA_BUFSIZE, 0 );
totalRcvd += bytesRecv;
nFileSize += write( fd, recvbuf, bytesRecv );
}
close( fd );
totalRcvd and nFileSize are equal
nFileSize value is valid (I sent the same quantity of bytes to socket)
But real file size is bigger as nFileSize
And it is broken :(
When I use fopen, fwrite and fclose functions the result is rhe same
Why?
--
Dmitry
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
Alfred P. Reaud
|