Subject: Re: implementing closeall via a syscall
To: Matt Thomas <matt@3am-software.com>
From: mouss <usebsd@free.fr>
List: tech-kern
Date: 01/07/2004 10:10:01
This is a multi-part message in MIME format.
--------------040602090002010109050807
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Matt Thomas wrote:
> + case F_MAXFD:
> + return (fdp->fd_lastfile);
This is erroneous as it puts the value in errno.
should be
case F_MAXFD:
*retval = fdp->fd_lastfile;
return 0;
instead.
Also, attached are implementations of closefrom and fdwalk, similar to
solaris versions.
cheers,
mouss
--------------040602090002010109050807
Content-Type: text/plain;
name="closefrom.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="closefrom.c"
/* $Id$ */
/*
* Written by mouss <usebsd@free.fr>
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$Id$");
#endif /* LIBC_SCCS and not lint */
#include <fcntl.h>
#include <stdlib.h>
void
closefrom(int fdlow)
{
(void) fcntl(fdlow, F_CLOSEM, 0);
return;
}
--------------040602090002010109050807
Content-Type: text/plain;
name="fdwalk.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="fdwalk.c"
/* $Id$ */
/*
* Written by mouss <usebsd@free.fr>
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$Id$");
#endif /* LIBC_SCCS and not lint */
#include <fcntl.h>
#include <assert.h>
#include <stdlib.h>
int
fdwalk(int (*func)(void *, int), void *arg)
{
int fd;
int maxfd;
int error;
_DIAGASSERT(func != NULL);
maxfd = fcntl(0, F_MAXFD, 0);
if (maxfd < 0) { /* should never happen */
return -1;
}
for (fd=0; fd <= maxfd; fd++) {
error = func(arg, fd);
if (error != 0) {
return error;
}
}
return 0;
}
--------------040602090002010109050807
Content-Type: text/plain;
name="stdlib.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="stdlib.diff"
*** stdlib.h.orig Wed Jan 7 09:51:56 2004
--- stdlib.h Wed Jan 7 09:53:59 2004
***************
*** 289,294 ****
--- 289,299 ----
#endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
#if defined(_NETBSD_SOURCE)
+ int fdwalk(int (*func)(void *, int), void *arg);
+ void closefrom(int fdlow);
+ #endif /* _NETBSD_SOURCE */
+
+ #if defined(_NETBSD_SOURCE)
qdiv_t qdiv __P((quad_t, quad_t));
#endif
__END_DECLS
--------------040602090002010109050807--