2.3 确定文件描述符数

lib/openmax.c

#include "apue.h"
#include <errno.h>
#include <limits.h>
#ifdef	OPEN_MAX
static long	openmax = OPEN_MAX;
#else
static long	openmax = 0;
#endif
/*
 * If OPEN_MAX is indeterminate, we're not
 * guaranteed that this is adequate.
 */
#define	OPEN_MAX_GUESS	256
long
open_max(void)
{
	if (openmax == 0) {		/* first time through */
		errno = 0;
		if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) {
			if (errno == 0)
				openmax = OPEN_MAX_GUESS;	/* it's indeterminate */
			else
				err_sys("sysconf error for _SC_OPEN_MAX");
		}
	}
	return(openmax);
}
posted @ 2014-07-16 23:01  paullam  阅读(236)  评论(0编辑  收藏  举报