In server.c to ensure the path exists I use this code:
if (access(path, F_OK) == -1)
{
error(404);
continue;
}
This leads to a 404 error even when the path exists. For example, if the request (using telnet) is
GET /cat.html HTTP/1.1
Using gdb or printf statements, path is:
/home/jharvard/Dropbox/pset6/public/cat.html
Yet the return value of access (if stored in a variable and printed) is -1. What is causing this?
UPDATE: This is how I form path:
// concatenate root and absolute-path
char path[strlen(root) + rt_l + 1];
strcpy(path, root);
if (qptr == NULL)
{
strcpy(path + strlen(root), request_target);
}
else
{
strncpy(path + strlen(root), request_target, qptr - space1 - 1);
path[qptr - space1] = '\0';
}
rt_l is is simply the length of the request target
printf("path=%s\n);
inside the if statement, just beforeerror(404);
? And have you checked that all the permissions are right? Since you're getting a -1, the server code thinks it doesn't exist. Either it doesn't exist, it's not visible to the server code, or the path/filename aren't an exact match, including case.