mode


You can specify an object's permissions for any constructor that takes an os_mode_t . Note that this functionality is not supported on non-UNIX platforms. A parameter of this type accepts either an os_mode object or a numeric representation of the permissions.

The default os_mode_t value for all I/O objects except directories is 0660 . Note that most UNIX permissions are written in octal. This value indicates that the I/O object is readable and writable by processes with the same user or group.

The default os_mode_t value for directories is 0770 , which indicates that processes with the same user or group can search those directories.

You can set os_mode class characteristics without either remembering the names of the POSIX flags, such as S_IRWXU and S_IRWXG defined in /usr/include/sys/stat.h, or remembering the flags' numeric representations. However, there is a slight overhead incurred when an os_mode object is converted into an os_mode_t .

The following example shows how to specify a file's mode during its creation. This example uses only the traditional POSIX flag interface for demonstration.

Example <ospace/unix/examples/mode1.cpp>
#include <iostream>
#include <ospace/file.h>
#include <ospace/io.h>

void
main()
{
os_file_toolkit initialize;

//Specify read and write permissions for owner only at creation.
cout << "Creating mode1a.txt with 0600" << end1;
os_file file1( "mode1a.txt", O_CREAT, O_WRONLY, 0600 );

os_mode new_mode;
new_mode.user_read( true );
new_mode.user_write( true );
cout << "Creating mode1b.txt with new_mode = " << new_mode << end1;
os_file file2( "mode1b.txt", O_CREAT, O_WRONLY, new_mode );
}

Creating mode1a.txt with 0600
Creating mode1b.txt with new_mode = -rw-------

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.