mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-23 04:44:16 +08:00
Support O_CLOEXEC open() flag
Make sure this flag is ignored and does not prevent a successful open. Close #3547.
This commit is contained in:
@@ -57,6 +57,8 @@ char test_write_buffer[ 1024 ];
|
||||
rtems_filesystem_operations_table IMFS_ops_no_evalformake;
|
||||
rtems_filesystem_operations_table IMFS_ops_no_rename;
|
||||
|
||||
static const char somefile[] = "somefile";
|
||||
|
||||
/*
|
||||
* File test support routines.
|
||||
*/
|
||||
@@ -132,11 +134,10 @@ void stat_a_file(
|
||||
|
||||
static void test_open_directory(void)
|
||||
{
|
||||
static const char file[] = "somefile";
|
||||
int status;
|
||||
int fd;
|
||||
|
||||
fd = open( file, O_CREAT, S_IRWXU );
|
||||
fd = open( somefile, O_CREAT, S_IRWXU );
|
||||
rtems_test_assert( fd >= 0 );
|
||||
|
||||
status = close( fd );
|
||||
@@ -144,12 +145,34 @@ static void test_open_directory(void)
|
||||
|
||||
#ifdef O_DIRECTORY
|
||||
errno = 0;
|
||||
fd = open( file, O_DIRECTORY, S_IRWXU );
|
||||
fd = open( somefile, O_DIRECTORY, S_IRWXU );
|
||||
rtems_test_assert( fd == -1 );
|
||||
rtems_test_assert( errno == ENOTDIR );
|
||||
#endif
|
||||
|
||||
status = unlink( file );
|
||||
status = unlink( somefile );
|
||||
rtems_test_assert( status == 0 );
|
||||
}
|
||||
|
||||
static void test_open_cloexec(void)
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
mode_t mode;
|
||||
|
||||
mode = O_CREAT;
|
||||
|
||||
#ifdef O_CLOEXEC
|
||||
mode |= O_CLOEXEC;
|
||||
#endif
|
||||
|
||||
fd = open( somefile, mode, S_IRWXU );
|
||||
rtems_test_assert( fd >= 0 );
|
||||
|
||||
status = close( fd );
|
||||
rtems_test_assert( status == 0 );
|
||||
|
||||
status = unlink( somefile );
|
||||
rtems_test_assert( status == 0 );
|
||||
}
|
||||
|
||||
@@ -185,6 +208,7 @@ int main(
|
||||
TEST_BEGIN();
|
||||
|
||||
test_open_directory();
|
||||
test_open_cloexec();
|
||||
|
||||
/*
|
||||
* Grab the maximum size of an in-memory file.
|
||||
|
||||
Reference in New Issue
Block a user