1 /* 2 * This work is licensed under the terms of the GNU GPL, version 2 or later. 3 * See the COPYING file in the top-level directory. 4 */ 5 #include "cutils.h" 6 7 #include "qapi/error.h" 8 9 /** 10 * qga_open_cloexec: 11 * @name: the pathname to open 12 * @flags: as in open() 13 * @mode: as in open() 14 * 15 * A wrapper for open() function which sets O_CLOEXEC. 16 * 17 * On error, -1 is returned. 18 */ 19 int qga_open_cloexec(const char *name, int flags, mode_t mode) 20 { 21 int ret; 22 23 #ifdef O_CLOEXEC 24 ret = open(name, flags | O_CLOEXEC, mode); 25 #else 26 ret = open(name, flags, mode); 27 if (ret >= 0) { 28 qemu_set_cloexec(ret); 29 } 30 #endif 31 32 return ret; 33 } 34