0

Based on the staff's use of access() in server.c and the documentation, I figured I could use it to see if the index.html/php exist. Unfortunately, whenever I try to use access, GDB tells me this whenever the function is called:

No symbol "F_OK" in current context.

I tried googling but foind nothing, so any hints and tips as to what is wrong would be appreciated.

My code is as follows:

char* indexes(const char* path)
{
    // copy path into test string
    char* test = malloc(BYTES);
    strcpy(test, path);

    // create separate string for index.php
    char* index_php = "index.php";
    // concatenate index.php to test string = newString
    char* new_string = strcat(test, index_php);

    // check that newString exists
    if(access(new_string, F_OK) == 0)
    {
        free(test);
        return new_string;
   }
   else 
   {   
        // create separate string for index.html
        char* index_html = "index.html";
        // concatenate index.html to test string = newString
        strcat(test, index_html);

        // check that newString exists
        if(access(new_string, F_OK) == 0)
        {
            free(test);
            return new_string;
        }
}
free(test);
return NULL;
}

1 Answer 1

0

Yeah, gdb is "funny" about constants defined elsewhere. It has to do with optimization and compiler switches (and other stuff I know I don't know). Here's how the *_OKs are defined in unistd.h.

/* Values for the second argument to access. These may be OR'd together. /
#define R_OK 4 /
Test for read permission. /
#define W_OK 2 /
Test for write permission. /
#define X_OK 1 /
Test for execute permission. /
#define F_OK 0 /
Test for existence. */

You could inspect access(new_string,0) to get the result you want.

Not sure if you are also asking what is wrong with your code. Hover to get that answer.

You're stuffing a bunch of stuff into new_string with strcat, but haven't allocated any memory to it. Then you concatenate index.html to test, but your second access() is still tests new_string.

1
  • Thank you, everything works fine now :)
    – iCode95
    Commented Aug 11, 2016 at 11:26

You must log in to answer this question.

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