libc: Add creat()

This commit is contained in:
apio 2022-11-12 14:12:49 +01:00
parent a3896c2546
commit 5fa8569ff9
2 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#ifndef _FCNTL_H
#define _FCNTL_H
#include <sys/types.h>
/* Open for reading only. */
#define O_RDONLY 1
/* Open for writing only. */
@ -42,6 +44,10 @@ extern "C"
/* Opens the file specified by pathname. Returns a file descriptor on success, or -1 on error. */
int open(const char* pathname, int flags, ...);
/* Opens the file specified by pathname, creating it if it doesn't exist or overwriting it otherwise. Calling this
* function is equivalent to calling open(pathname, O_WRONLY|O_CREAT|O_TRUNC, mode) */
int creat(const char* pathname, mode_t mode);
/* Performs an operation on the file descriptor fd determined by cmd. */
int fcntl(int fd, int cmd, ...);

View File

@ -15,6 +15,13 @@ extern "C"
return (int)result;
}
int creat(const char* pathname, mode_t mode)
{
return (int)__lc_fast_syscall3(SYS_open, pathname, O_WRONLY | O_CREAT | O_TRUNC,
mode); // we don't need to pass this through to open(), we can avoid variadic
// stuff since we're sure mode exists.
}
int fcntl(int fd, int cmd, ...)
{
va_list ap;