summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src/open.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-10-11 10:51:21 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-10-18 11:11:24 +0200
commit4af18b34f4193eb1ffa0415d50f952aa781ef2da (patch)
tree7db7a5e7abf5386765588f147d5b22535bc01563 /cpukit/libcsupport/src/open.c
parentbsp/atsam: Add const qualifier to AES_SetInput() (diff)
downloadrtems-4af18b34f4193eb1ffa0415d50f952aa781ef2da.tar.bz2
Support O_DIRECTORY open() flag
Close #3545.
Diffstat (limited to 'cpukit/libcsupport/src/open.c')
-rw-r--r--cpukit/libcsupport/src/open.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c
index 8558e207d3..554311c5aa 100644
--- a/cpukit/libcsupport/src/open.c
+++ b/cpukit/libcsupport/src/open.c
@@ -73,6 +73,7 @@ static int do_open(
bool make = (oflag & O_CREAT) == O_CREAT;
bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
bool truncate = (oflag & O_TRUNC) == O_TRUNC;
+ bool open_dir;
int eval_flags = RTEMS_FS_FOLLOW_LINK
| (read_access ? RTEMS_FS_PERMS_READ : 0)
| (write_access ? RTEMS_FS_PERMS_WRITE : 0)
@@ -86,14 +87,24 @@ static int do_open(
create_regular_file( &ctx, mode );
}
- if ( write_access ) {
+#ifdef O_DIRECTORY
+ open_dir = ( oflag & O_DIRECTORY ) == O_DIRECTORY;
+#else
+ open_dir = false;
+#endif
+
+ if ( write_access || open_dir ) {
const rtems_filesystem_location_info_t *currentloc =
rtems_filesystem_eval_path_get_currentloc( &ctx );
mode_t type = rtems_filesystem_location_type( currentloc );
- if ( S_ISDIR( type ) ) {
+ if ( write_access && S_ISDIR( type ) ) {
rtems_filesystem_eval_path_error( &ctx, EISDIR );
}
+
+ if ( open_dir && !S_ISDIR( type ) ) {
+ rtems_filesystem_eval_path_error( &ctx, ENOTDIR );
+ }
}
rtems_filesystem_eval_path_extract_currentloc( &ctx, &iop->pathinfo );