LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2013, 02:35 AM   #1
rohaanembedded
Member
 
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Question coopying bin file in buff problem not copying whole bin


Dear sir i have tried copying binary file of my firmware in to buffer but its not copying completely please help me in this

copying part of my code


Code:
              if ((fp = fopen("/home/usb/FPR/firmware/fw.bix", "rb"))==NULL){
                printf("Cannot open file \n");
                }

                int fileLen;

                //Get file length
                fseek(fp, 0, SEEK_END);
                fileLen=ftell(fp);
                fseek(fp, 0, SEEK_SET);


                printf("\nfileLen = %d\n", fileLen);

                fread(buf, fileLen, 1 ,fp);

                cBuf = (const char*) buf;

                int len = strlen(cBuf);

                printf("\nBuf_len_aftr_Write = %d\n",len);


                while(len!=0)
                {
                printf("%c", *cBuf);
                len--;
                }

                int orglen = size;

                printf("\n\n");

                while(orglen!=0)
                {
                printf("%c", *buf);
                orglen--;
                }


                fclose(fp);
thanks
rohaan
 
Old 07-10-2013, 05:37 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Don't use strlen, use the return value of fread... also check for EOF/errors. Manual is your friend, enter this command: man 3 fread

Also add a part like this:

Code:
void *buf= malloc (fileLen);
if (!buf) {
    fprintf (stderr, "Error in malloc(%d)\n", (int)fileLen);
    exit (99);
}

Last edited by NevemTeve; 07-10-2013 at 05:39 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in copying bin file into buffer in my firmware download code rohaanembedded Programming 8 07-12-2013 02:25 PM
copy /bin/perl to /opt/bin/perl. What all things to consider while copying? rohit.dhaval1 Linux - Software 4 02-20-2011 04:06 PM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM
Installing .bin-files, leave the file in /usr/local/bin/ ? lagu2653 Linux - Software 1 11-08-2005 08:30 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration