blob: 2b5cd1f3bed247e238a0fcf78de33204a176e05c [file] [log] [blame] [raw]
/* A part of the Windows CE C Extra Library (celibc)
Copyright 2007-2015 PC GO Ld.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
int access(const char *pathname, int mode) {
if(mode & ~(R_OK | W_OK | X_OK | F_OK)) {
errno = EINVAL;
return -1;
}
if(!pathname) {
errno = EFAULT;
return -1;
}
if(!*pathname) {
errno = ENOENT;
return -1;
}
struct stat st;
if(stat(pathname, &st) < 0) return -1;
if((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
errno = EACCES;
return -1;
}
return 0;
}