1 /* $Id: opendir.c,v 1.2 2002/02/20 09:17:56 hyperion Exp $
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/dirent/opendir.c
7 * PURPOSE: Open a directory
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
11 * 13/02/2002: KJK::Hyperion: modified to use file descriptors
14 #include <sys/types.h>
19 #include <psx/debug.h>
20 #include <psx/stdlib.h>
21 #include <psx/dirent.h>
22 #include <psx/safeobj.h>
24 DIR *opendir(const char *dirname
)
26 ANSI_STRING strDirName
;
27 UNICODE_STRING wstrDirName
;
30 RtlInitAnsiString(&strDirName
, (PCSZ
)dirname
);
31 RtlAnsiStringToUnicodeString(&wstrDirName
, &strDirName
, TRUE
);
33 pdData
= (DIR *)_Wopendir(wstrDirName
.Buffer
);
35 RtlFreeUnicodeString(&wstrDirName
);
41 DIR *_Wopendir(const wchar_t *dirname
)
43 struct __internal_DIR
*pidData
;
46 /* allocate internal object */
47 pidData
= __malloc(sizeof(*pidData
));
49 /* allocation failed */
56 /* open the directory */
57 nFileNo
= _Wopen(dirname
, O_RDONLY
| _O_DIRFILE
);
66 /* directory file descriptors must be closed on exec() */
67 if(fcntl(nFileNo
, F_SETFD
, FD_CLOEXEC
) == -1)
70 "couldn't set FD_CLOEXEC flag on file number %u, errno %u",
75 /* associate the internal data to the file descriptor */
76 if(fcntl(nFileNo
, F_SETXP
, pidData
) == -1)
79 "couldn't associate the object at 0x%X to the file number %u, errno %u",
85 if(fcntl(nFileNo
, F_SETXS
, sizeof(*pidData
)) == -1)
88 "couldn't set the extra data size of the file number %u, errno %u",
93 pidData
->signature
= __IDIR_MAGIC
;
96 return ((DIR *)pidData
);