2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

Add function get_null_fd(), to reduce code redundancy.

This commit is contained in:
Ben Pfaff
2009-07-15 10:54:51 -07:00
parent aec7d2fba6
commit a8b5f8b423
5 changed files with 32 additions and 21 deletions

View File

@@ -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)
{