Fix issues with stdio needed for Lua

See #61
This commit is contained in:
Justine Tunney 2021-03-06 16:06:15 -08:00
parent c3ed8d6c7f
commit d769df3482
17 changed files with 102 additions and 155 deletions

View file

@ -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;
}