Getting file contents from stdio FILE*

hello everyone,
as i’ve previously said, i want to compile the script into a file
using SDL_RWops
i’ve coded it from the ground-up which use’s stdio FILE*, but i think
it doesn’t retrieve the file contents
this is my code:
//our writer function that use’s SDL’s rwops API
SQInteger rwops_write(SQUserPointer dest, SQUserPointer src, SQInteger sz)
{
SDL_RWops* rw = (SDL_RWops*)dest;
return SDL_RWwrite(rw, src, sz, 1) == 1 ? SQ_OK : SQ_ERROR;
}

char* compile()
{
FILE f=tmpfile(); //create a temporary file to store script byte-code in it
if(!f) //checks whether it’s null or not
{
Error::Throw(scr.GetVM(), “unable to start compilation!”);
return false;
}
SDL_RWops rw=SDL_RWFromFP(f, 1); //create a SDL_RWops from our FILE pointer
if(!rw) //this must not be nulled two
{
Error::Throw(scr.GetVM(), “unable to compile the script”);
fclose(f);
return false;
}
sq_writeclosure(scr.GetVM(), rwops_write, (void
)rw ); //now we write
our byte-code in the file
sq_pop(scr.GetVM(), 1); //this must be here to avoid memory leeks
char
buf=new char[SDL_RWtell(rw)]; //we need this to store byte-code in it
SDL_RWread(rw, buf, SDL_RWtell(rw), 1);
}

it doesn’t work, what is the problem?
the buf is empty
what i’ve did wrong?
thanks a lot