Re: Drawing an image (osd)

"Morten Nilsen" <[email protected]>
Newsgroups gmane.comp.video.xine.user
Message-ID <3vWY0lG7.1196675171.1420240.mortenn@localhost>
On 3/12/2007, "Hal far" <[email protected]> wrote:
>         FILE * f;
>	f=fopen("osd-mid.gif","r");
>	int size;  // size file
>	char c;
>
>	size=0;
>	while(c!=EOF)
> 	{
>		c=fgetc(f);
>		size++;
>	}
>
>	uint8_t * immagine = xine_xmalloc(size);

I'm sorry, but I can't refrain from commenting that piece of code..
Quite frankly, that is a candidate for tdwtf..
You should use stat() to garner the file size, not by counting bytes..

Something similar to this ought to do the trick;

struct stat data;
if(stat("osd-mid.gif", &data) != 0)
  return; // Abort
uint8_t *immagine = xine_xmalloc(data.st_size);

--
Cheers,
Morten
:wq

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.