Home > Software engineering >  Linux download software programming
Linux download software programming

Time:10-09

 
Void do_write (int s, char * buf, int len)
{
Int retcount;
Do {
Retcount=write (s, buf, len);
Buf +=retcount;
Len -=retcount;
} while (len & gt; 0);
}

Void the transmit ()
{
Int fd.
Int sd=file_info. Sd;
Int read_count read_sum=0;
Char * buf=(char *) malloc (102500);
Fd=file_info. Fd=open (file_info path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
If (fd & lt; 0 {
Printf (" local file open error \ n ");
exit(1);
}
While (read_sum & lt; File_info. Size) {//file_info. The size of the size of the download file
Read_count=read (sd, buf, 102400);
Do_write (fd, buf, read_count);
Read_sum +=read_count;
}
Printf (" read_sum: % d \ n ", read_sum);
Printf (" the file size: % d \ n ", file_info. Size);
Free (buf);
}


In the above code is used to download files, while loop reads data from the network, and then written to a local, testing found that read data is always more than the size of the file was few bytes (namely read_sum than file_info. Size), so the download file cannot be used, where do I write wrong

CodePudding user response:

File_info. The size is how to get, how do you know the file size

CodePudding user response:

Recommended WinHex software to check the hard disk or file or original bytes of memory content,

Don't put the
Fopen ("... ", "... "); Fscanf fprintf, the fgets, fgetc, fclose//read the replaced \ r \ n \ n, write to replace the \ n \ r \ n. EOF is read \ x1a set; When the content of the read and write characters see
And
Fopen ("... ", "... "); Fseek, ftell, fread and fwrite fgetc, fclose//do not make the above replacement, encounter \ x1a continued to read; When the content of the read and write bytes see
Confused by the
  • Related