Check Access Permissions (continued.) #include /* standard input/output routines. */ #include /* access(), R_OK etc. */ #include /* strchr(), etc. */ #include /* malloc(), etc. */ /* * function: check_Access. * input: full path to a file, and pointer to error string. * output: '1' if permission is granted, or '0' and a * detailed explanation if some problem was found. */ int check_access(char* file_path, char** error_msg) { char* dir_path; /* full path to a directory. */ char* p_slash; /* location of next '/' in path. */ static char err_msg[1024]; /* static memory for error message. */ /* prepare for returning error message. */ *error_msg = err_msg; dir_path = (char*)malloc(strlen(file_path)+1); if (!dir_path) { sprintf(err_msg, "out of memory"); return 0; }