X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsocket-util.c;h=086a329eab937897f7c7412c18487774e00777be;hb=3c303e5fe1061b8715be018ae8e535cbc24303c9;hp=33e179e1cf55e93321a508dabc2639a9d12388e7;hpb=a14bc59fb8f27db193d74662dc9c5cb8237177ef;p=openvswitch diff --git a/lib/socket-util.c b/lib/socket-util.c index 33e179e1..086a329e 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -299,6 +299,24 @@ guess_netmask(uint32_t ip) : htonl(0)); /* ??? */ } +/* Returns a readable and writable fd for /dev/null, if successful, otherwise + * a negative errno value. The caller must not close the returned fd (because + * the same fd will be handed out to subsequent callers). */ +int +get_null_fd(void) +{ + static int null_fd = -1; + if (null_fd < 0) { + null_fd = open("/dev/null", O_RDWR); + if (null_fd < 0) { + int error = errno; + VLOG_ERR("could not open /dev/null: %s", strerror(error)); + return -error; + } + } + return null_fd; +} + int read_fully(int fd, void *p_, size_t size, size_t *bytes_read) {