0

My server.c works perfectly except for .php files. It displays the PHP correctly but is infinitely loading. The code for my load function is: bool load(FILE* file, BYTE** content, size_t* length) {

unsigned int sz;
fseek(file, 0L, SEEK_END);
sz = ftell(file);
rewind(file);
char* filebuffer = malloc(sz);
fread(filebuffer, sz, 1, file);
*content = filebuffer;
*length = sz;
}

When I have a php file, sz becomes -1. Any ideas why? For all other filetpyes it works perfectly.

thanks,

1 Answer 1

2

See the section on "interpret" (around page 8) of the instructions.

Odds are you’re unfamiliar with popen. That function opens a "pipe" to a process (php-cgi in our case), which provides us with a FILE pointer via which we can read that process’s standard output (as though it were an actual file).

You cannot use ftell or fseek on a pipe. This post is an interesting discussion on the topic. (And this post too!)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .