libc: Add creat()
This commit is contained in:
parent
a3896c2546
commit
5fa8569ff9
@ -1,6 +1,8 @@
|
|||||||
#ifndef _FCNTL_H
|
#ifndef _FCNTL_H
|
||||||
#define _FCNTL_H
|
#define _FCNTL_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
/* Open for reading only. */
|
/* Open for reading only. */
|
||||||
#define O_RDONLY 1
|
#define O_RDONLY 1
|
||||||
/* Open for writing only. */
|
/* 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. */
|
/* Opens the file specified by pathname. Returns a file descriptor on success, or -1 on error. */
|
||||||
int open(const char* pathname, int flags, ...);
|
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. */
|
/* Performs an operation on the file descriptor fd determined by cmd. */
|
||||||
int fcntl(int fd, int cmd, ...);
|
int fcntl(int fd, int cmd, ...);
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@ extern "C"
|
|||||||
return (int)result;
|
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, ...)
|
int fcntl(int fd, int cmd, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
Loading…
Reference in New Issue
Block a user