http://www.perlmonks.org?node_id=1017751


in reply to Re^2: open(): Is there a simple way to map between numeric open modes and "symbol modes"?
in thread open(): Is there a simple way to map between numeric open modes and "symbol modes"? (solved)

how do I un-OR OR results, against the other flags, to get back to these basic constants?

(From MSVC header files:

#define _O_RDONLY 0x0000 /* open for reading only */ #define _O_WRONLY 0x0001 /* open for writing only */ #define _O_RDWR 0x0002 /* open for reading and writing */ #define _O_APPEND 0x0008 /* writes done at eof */ #define _O_CREAT 0x0100 /* create and open file */ #define _O_TRUNC 0x0200 /* open and truncate */ #define _O_EXCL 0x0400 /* open only if file doesn't already e +xist */ #define _O_TEXT 0x4000 /* file mode is text (translated) */ #define _O_BINARY 0x8000 /* file mode is binary (untranslated) +*/ #define _O_WTEXT 0x10000 /* file mode is UTF16 (translated) */ #define _O_U16TEXT 0x20000 /* file mode is UTF16 no BOM (translat +ed) */ #define _O_U8TEXT 0x40000 /* file mode is UTF8 no BOM (translat +ed) */

So, assuming the variable $mode contains the OR'd values; you can check which bits are set something like:

if( $mode & 1 ) { ## _O_WRONLY say "File is opend WRITE only }

But note: not all of the bits that can be set when opening a file are retained in FILE*->_flag.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: open(): Is there a simple way to map between numeric open modes and "symbol modes"?
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: open(): Is there a simple way to map between numeric open modes and "symbol modes"?
by isync (Hermit) on Feb 08, 2013 at 14:06 UTC
    Thumbs up for this load of code!! Thank you BrowserUk!