io_status |
Most I/O objects have an
associated status value encapsulated by the os_io_status
class. By using this class, you can obtain and modify the characteristics of an
I/O object, such as its user and group.
There are two ways to obtain an os_io_status
object.
status() . The I/O object
must be open for this function to succeed.os_io_status
object on the file system path of an I/O object. This method only works for os_file
and UNIX-specific objects. The following example shows both
methods of obtaining the os_io_status for an os_file
.
#include <iostream>
#include <ospace/file.h>
#include <ospace/io.h>
#include <ospace/security.h>
const char* path = "/tmp/tmp.txt";
void
main()
{
os_file_toolkit init_file;
os_security_toolkit init_security;
os_file file( path, O_CREAT | O_TRUNC, O_WRONLY );
file.write( "junk", 4 );
os_io_status status( path );
cout << "group = " << os_group( status.group() ) << endl;
cout << "user = " << os_user( status.user() ) << endl;
os_io_status status2 = file.status();
cout << "size = " << status2.size() << endl;
}
group = os_group( bigred, 100 )
user = os_user( wku, 200 )
size = 4
Once you have an os_io_status
object, you can send it functions to modify its attributes. Not all attributes
can be altered.
The following example shows how
to alter the mode of a file using os_io_status on
a UNIX machine.
#include <iostream>
#include <ospace/file.h>
#include <ospace/io.h>
const char* path = "/tmp/tmp.txt";
void
main()
{
os_file_toolkit initialize;
os_file_system::remove_if_exists( path ); // Remove existing file.
os_file file( path, O_CREAT | O_TRUNC, O_WRONLY, 0644 );
file.write( "junk", 4 );
os_io_status status( path );
cout << "mode = " << os_mode( status.mode() ) << endl;
cout << "Changing file mode to 0600" << endl;
status.mode( 0600 );
cout << "New mode = " << os_mode( os_io_status( path ).mode() );
cout << endl;
}
mode = -rw-r--r--
Changing file mode to 0600
New mode = -rw-------
Refer to the dir4.cpp example in
File<ToolKit> for another example using the os_io_status
class.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.