xref: /openbsd-src/lib/libc/sys/w_open.c (revision fe38b55cb0aae270de3f844146814682e8cd345c)
1*fe38b55cSguenther /*	$OpenBSD: w_open.c,v 1.1 2016/05/07 19:05:22 guenther Exp $ */
2*fe38b55cSguenther /*
3*fe38b55cSguenther  * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
4*fe38b55cSguenther  *
5*fe38b55cSguenther  * Permission to use, copy, modify, and distribute this software for any
6*fe38b55cSguenther  * purpose with or without fee is hereby granted, provided that the above
7*fe38b55cSguenther  * copyright notice and this permission notice appear in all copies.
8*fe38b55cSguenther  *
9*fe38b55cSguenther  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*fe38b55cSguenther  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*fe38b55cSguenther  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*fe38b55cSguenther  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*fe38b55cSguenther  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*fe38b55cSguenther  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*fe38b55cSguenther  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*fe38b55cSguenther  */
17*fe38b55cSguenther 
18*fe38b55cSguenther #include <fcntl.h>
19*fe38b55cSguenther #include <stdarg.h>
20*fe38b55cSguenther #include "cancel.h"
21*fe38b55cSguenther 
22*fe38b55cSguenther int
open(const char * path,int flags,...)23*fe38b55cSguenther open(const char *path, int flags, ...)
24*fe38b55cSguenther {
25*fe38b55cSguenther 	va_list ap;
26*fe38b55cSguenther 	mode_t mode = 0;
27*fe38b55cSguenther 	int ret;
28*fe38b55cSguenther 
29*fe38b55cSguenther 	if (flags & O_CREAT) {
30*fe38b55cSguenther 		va_start(ap, flags);
31*fe38b55cSguenther 		mode = va_arg(ap, int);
32*fe38b55cSguenther 		va_end(ap);
33*fe38b55cSguenther 	}
34*fe38b55cSguenther 
35*fe38b55cSguenther 	ENTER_CANCEL_POINT(1);
36*fe38b55cSguenther 	ret = HIDDEN(open)(path, flags, mode);
37*fe38b55cSguenther 	LEAVE_CANCEL_POINT(ret == -1);
38*fe38b55cSguenther 
39*fe38b55cSguenther 	return (ret);
40*fe38b55cSguenther }
41*fe38b55cSguenther DEF_CANCEL(open);
42