libposix: return PosixENOTDIR according to O_DIRECTORY specification

This commit is contained in:
Giacomo Tesio 2017-08-22 02:34:00 +02:00
parent 004dd6bff1
commit 965d316ac4
1 changed files with 39 additions and 3 deletions

View File

@ -113,6 +113,7 @@ POSIX_open(int *errnop, const char *name, int flags, int mode)
{ {
long omode = 0, cperm = 0; long omode = 0, cperm = 0;
PosixError e; PosixError e;
Dir *d;
int f; int f;
if(name == nil){ if(name == nil){
@ -120,9 +121,16 @@ POSIX_open(int *errnop, const char *name, int flags, int mode)
return -1; return -1;
} }
e = __libposix_open_translation(flags, mode, &omode, &cperm); e = __libposix_open_translation(flags, mode, &omode, &cperm);
if(e != 0){ if(e != 0)
*errnop = __libposix_get_errno(e); goto FailWithError;
return -1; if(omode & DMDIR){
d = dirstat(name);
if((d->mode & DMDIR) == 0)
e = PosixENOTDIR;
free(d);
if(e != 0)
goto FailWithError;
omode &= ~DMDIR;
} }
if(cperm == 0){ if(cperm == 0){
f = sys_open(name, omode); f = sys_open(name, omode);
@ -133,6 +141,10 @@ POSIX_open(int *errnop, const char *name, int flags, int mode)
return f; return f;
*errnop = __libposix_translate_errstr((uintptr_t)POSIX_open); *errnop = __libposix_translate_errstr((uintptr_t)POSIX_open);
return -1; return -1;
FailWithError:
*errnop = __libposix_get_errno(e);
return -1;
} }
long long
@ -360,6 +372,30 @@ POSIX_stat(int *errnop, const char *file, void *pstat)
return -1; return -1;
} }
int
POSIX_chmod(int *errnop, const char *path, int mode)
{
long cmode = 0;
PosixError e;
e = __libposix_open_translation(0, mode, nil, &cperm);
if(e != 0){
*errnop = __libposix_get_errno(e);
return -1;
}
return -1;
}
int
POSIX_fchmodat(int *errnop, int fd, const char *path, long mode, int flag)
{
return -1;
}
/* getdents is not POSIX, but is used in POSIX C library to implement
* readdir.
*/
int int
libposix_getdents(int *errnop, int fd, char *buf, int buf_bytes) libposix_getdents(int *errnop, int fd, char *buf, int buf_bytes)
{ {