view src/lib/fd-set-nonblock.c @ 9354:687ac828b964 HEAD

lib-index: modseqs weren't tracked properly within session when changes were done.
author Timo Sirainen <tss@iki.fi>
date Tue, 01 Sep 2009 13:05:03 -0400
parents b9faf4db2a9f
children 00cd9aacd03c
line wrap: on
line source

/* Copyright (c) 1999-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "fd-set-nonblock.h"

#include <fcntl.h>

int fd_set_nonblock(int fd, bool nonblock)
{
	int flags;

	flags = fcntl(fd, F_GETFL, 0);
	if (flags < 0) {
		i_error("fcntl(%d, F_GETFL) failed: %m", fd);
		return -1;
	}

	if (nonblock)
		flags |= O_NONBLOCK;
	else
		flags &= ~O_NONBLOCK;

	if (fcntl(fd, F_SETFL, flags) < 0) {
		i_error("fcntl(%d, F_SETFL) failed: %m", fd);
		return -1;
	}
	return 0;
}