# --- T2-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # T2 SDE: package/.../dietlibc/fdopendir.patch # Copyright (C) 2011 The T2 SDE Project # # More information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # --- T2-COPYRIGHT-NOTE-END --- Of course for udev, too, what else, ... - Rene Rebe --- dietlibc/include/dirent.h.vanilla 2011-01-06 12:29:39.000000000 +0100 +++ dietlibc/include/dirent.h 2011-01-06 12:30:04.000000000 +0100 @@ -33,6 +33,7 @@ typedef struct __dirstream DIR; DIR *opendir (const char *__name) __THROW; +DIR *fdopendir(int fd) __THROW; int closedir (DIR *__dirp) __THROW; struct dirent *readdir (DIR *__dirp) __THROW; struct dirent64 *readdir64 (DIR *__dirp) __THROW; --- dietlibc/lib/fdopendir.c.vanilla 2011-01-06 12:30:22.000000000 +0100 +++ dietlibc/lib/fdopendir.c 2011-01-06 12:33:58.000000000 +0100 @@ -0,0 +1,28 @@ +#include "dietdirent.h" +#include +#include +#include +#include +#include + +DIR* fdopendir (int fd) { + DIR* t = NULL; + int flags = fcntl (fd, F_GETFL); + if (flags == -1 || (flags & O_DIRECTORY) == 0) + goto lose; /* TODO: set errno = ENOTDIR; */ + + if ( fd >= 0 ) { + if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) + goto lose; + t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (t == MAP_FAILED) +lose: + close (fd); + else + t->fd = fd; + } + + + return t; +}