2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function opendir().
12 #ifndef ExNext_IS_WORKING_WITHOUT_ASSIGN
21 #include "__dirdesc.h"
24 #include <aros/debug.h>
26 /*****************************************************************************
40 pathname - Path and filename of the directory you want to open.
43 NULL for error or a directory stream
52 open(), readdir(), closedir(), rewinddir(), seekdir(),
57 ******************************************************************************/
65 #ifndef ExNext_IS_WORKING_WITHOUT_ASSIGN
75 dir
= malloc(sizeof(DIR));
82 dir
->priv
= AllocDosObject(DOS_FIB
, NULL
);
89 /* Lock is used instead of open to allow opening "" */
90 aname
= __path_u2a(name
);
91 lock
= Lock(aname
, SHARED_LOCK
);
94 errno
= __stdc_ioerr2errno(IoErr());
98 #ifndef ExNext_IS_WORKING_WITHOUT_ASSIGN
99 sprintf(assign
, "READDIR%p", dir
);
101 if (!AssignLock(assign
, DupLock(lock
)))
103 D(bug("!AssignLock err=%d\n", IoErr()));
107 lock
= Lock(aname
, SHARED_LOCK
);
109 AssignLock(assign
, BNULL
);
112 if (!Examine(lock
, dir
->priv
))
114 errno
= __stdc_ioerr2errno(IoErr());
118 if (((struct FileInfoBlock
*)dir
->priv
)->fib_DirEntryType
<=0)
124 cblock
= AllocVec(sizeof(fcb
), MEMF_ANY
| MEMF_CLEAR
);
130 desc
= __alloc_fdesc();
138 desc
->fcb
->handle
= lock
;
139 desc
->fcb
->flags
= O_RDONLY
;
140 desc
->fcb
->opencount
= 1;
141 desc
->fcb
->privflags
|= _FCB_ISDIR
;
143 fd
= __getfdslot(__getfirstfd(3));
144 __setfdesc(fd
, desc
);
148 dir
->ent
.d_name
[NAME_MAX
] = '\0';
150 D(bug("opendir(%s) fd=%d\n", name
, fd
));
158 FreeDosObject(DOS_FIB
, dir
->priv
);
162 D(bug("opendir(%s) errno=%d\n", name
, errno
));