xref: /minix3/minix/lib/libc/sys/open.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include <sys/cdefs.h>
2*433d6423SLionel Sambuc #include "namespace.h"
3*433d6423SLionel Sambuc #include <lib.h>
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include <fcntl.h>
6*433d6423SLionel Sambuc #include <stdarg.h>
7*433d6423SLionel Sambuc #include <string.h>
8*433d6423SLionel Sambuc 
open(const char * name,int flags,...)9*433d6423SLionel Sambuc int open(const char *name, int flags, ...)
10*433d6423SLionel Sambuc {
11*433d6423SLionel Sambuc   va_list argp;
12*433d6423SLionel Sambuc   message m;
13*433d6423SLionel Sambuc   int call;
14*433d6423SLionel Sambuc 
15*433d6423SLionel Sambuc   memset(&m, 0, sizeof(m));
16*433d6423SLionel Sambuc   va_start(argp, flags);
17*433d6423SLionel Sambuc   /* Depending on whether O_CREAT is set, a different message layout is used,
18*433d6423SLionel Sambuc    * and therefore a different call number as well.
19*433d6423SLionel Sambuc    */
20*433d6423SLionel Sambuc   if (flags & O_CREAT) {
21*433d6423SLionel Sambuc 	m.m_lc_vfs_creat.len = strlen(name) + 1;
22*433d6423SLionel Sambuc 	m.m_lc_vfs_creat.flags = flags;
23*433d6423SLionel Sambuc 	m.m_lc_vfs_creat.mode = va_arg(argp, mode_t);
24*433d6423SLionel Sambuc 	m.m_lc_vfs_creat.name = (vir_bytes)name;
25*433d6423SLionel Sambuc 	call = VFS_CREAT;
26*433d6423SLionel Sambuc   } else {
27*433d6423SLionel Sambuc 	_loadname(name, &m);
28*433d6423SLionel Sambuc 	m.m_lc_vfs_path.flags = flags;
29*433d6423SLionel Sambuc 	call = VFS_OPEN;
30*433d6423SLionel Sambuc   }
31*433d6423SLionel Sambuc   va_end(argp);
32*433d6423SLionel Sambuc   return (_syscall(VFS_PROC_NR, call, &m));
33*433d6423SLionel Sambuc }
34