mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
parent
c3ed8d6c7f
commit
d769df3482
17 changed files with 102 additions and 155 deletions
|
@ -16,29 +16,32 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
/**
|
||||
* Turns stdio flags description string into bitmask.
|
||||
*/
|
||||
int fopenflags(const char *mode) {
|
||||
unsigned flags = 0;
|
||||
unsigned omode, flags;
|
||||
omode = flags = 0;
|
||||
do {
|
||||
if (*mode == 'r') {
|
||||
flags |= O_RDONLY;
|
||||
omode = O_RDONLY;
|
||||
} else if (*mode == 'w') {
|
||||
flags |= O_WRONLY | O_CREAT | O_TRUNC;
|
||||
omode = O_WRONLY;
|
||||
flags |= O_CREAT | O_TRUNC;
|
||||
} else if (*mode == 'a') {
|
||||
flags |= O_WRONLY | O_CREAT | O_APPEND;
|
||||
omode = O_WRONLY;
|
||||
flags |= O_CREAT | O_APPEND;
|
||||
} else if (*mode == '+') {
|
||||
flags |= O_RDWR;
|
||||
omode = O_RDWR;
|
||||
} else if (*mode == 'x') {
|
||||
flags |= O_EXCL;
|
||||
} else if (*mode == 'e') {
|
||||
flags |= O_CLOEXEC;
|
||||
}
|
||||
} while (*mode++);
|
||||
return flags;
|
||||
return omode | flags;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue