First time posting so if I'm off the mark here let me know.
Basically, in writing server.c I can't figure out how to test my load function now that I've written it. check50 will only work once I've completed the writing the entire program. I was using check50 but when using curl it doesn't stop on the break points set at load. Needless to say, I'm a bit stuck on load because I haven't been able to check it. This is what I've got if it helps:
Load:
bool load(FILE* file, BYTE** content, size_t* length) {
if (file == NULL){
return false;
}
BYTE buffer[BYTES];
size_t numBytes = fread(buffer, sizeof(buffer), 1, file);
*content = &buffer[0];
*length = numBytes;
printf("%zu\n", numBytes);
return false;
}
I realize that this function is NOT efficient as I'm doing this one byte at a time. However, to be clear, I need to be able to run check50 (or similar) so I can stop the program to inspect my values in order to evaluate what is happening. All of the my check50 statements fail on the server2 check and all of my server1 pass.
I have checked through the forums for the last hour trying to find an answer before posting. Thank you to whoever helps. Been on this for a while now.
EDIT: I changed the load function to the below. It now passes all cs50 checks but returns a file size of zero only for my php files. All of the other files in the public director run correctly and I get a error 500 only on the php file. Because this error may be coming from somewhere other than my load function I also posted here my parse function. I did verify that the lookup() function is returning the correct type but am posting that also just in case:
Load:
bool load(FILE* file, BYTE** content, size_t* length)
{
// TODO
int fd = fileno(file);
struct stat st;
int suc = fstat(fd, &st);
if (suc != 0){
error(500);
printf("%d", suc);
}
int size = st.st_size;
*content = malloc(size + 1);
fread(*content, size, 1, file);
printf("%d\n",size);
*length = size;
return true;
}
I previously tried to use fseek() and ftell() but would give me a seg fault, again only on the php file.
PARSE AND LOOKUP FUNCTIONS REMOVED FROM POST
Greatly appreciate any and all help. Hope to get an answer soon so I can take the code down. Thanks!
Directory tree:
.
├── Makefile
├── myserver
├── myserver.c
├── public
│ ├── cat.html
│ ├── cat.jpg
│ ├── favicon.ico
│ ├── hello.html
│ ├── hello.php
│ ├── index.php
│ └── test
│ └── index.html
├── server
├── server.c
└── server2.c
File permissions:
-rw-rw-r-- 1 ubuntu ubuntu 156 Oct 24 2015 cat.html
-rw-rw-r-- 1 ubuntu ubuntu 26860 Oct 24 2015 cat.jpg
-rw-rw-r-- 1 ubuntu ubuntu 318 Oct 24 2015 favicon.ico
-rw-rw-r-- 1 ubuntu ubuntu 316 Oct 24 2015 hello.html
-rw-rw-r-- 1 ubuntu ubuntu 281 Oct 24 2015 hello.php