Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / opendir.c
blob34bbe6e20a004fd1c366e10cc6b886b638517c05
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function opendir().
6 */
8 #include <dos/dos.h>
9 #include <proto/dos.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <fcntl.h>
16 #include "__open.h"
17 #include "__errno.h"
19 /*****************************************************************************
21 NAME */
22 #include <dirent.h>
24 DIR *opendir(
26 /* SYNOPSIS */
27 const char *name)
29 /* FUNCTION
30 Opens a directory
32 INPUTS
33 pathname - Path and filename of the directory you want to open.
35 RESULT
36 NULL for error or a directory stream
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
45 open(), readdir(), closedir(), rewinddir(), seekdir(),
46 telldir(), scandir()
48 INTERNALS
50 ******************************************************************************/
52 DIR *dir;
53 int fd;
54 fdesc *desc;
56 if (!name)
58 errno = EFAULT;
59 goto err1;
62 dir = malloc(sizeof(DIR));
63 if (!dir) goto err1;
65 dir->priv = malloc(sizeof(struct FileInfoBlock));
66 if (!dir->priv) goto err2;
68 fd = open(name, O_RDONLY);
69 desc = __getfdesc(fd);
70 if (!desc) goto err3;
72 if (!ExamineFH(desc->fh, dir->priv))
74 errno = IoErr2errno(IoErr());
75 goto err4;
78 if (((struct FileInfoBlock *)dir->priv)->fib_DirEntryType<=0)
80 errno = ENOTDIR;
81 goto err4;
84 dir->fd = fd;
85 dir->pos = 0;
86 dir->ent.d_name[NAME_MAX] = '\0';
88 return dir;
90 err4:
91 close(fd);
92 err3:
93 free(dir->priv);
94 err2:
95 free(dir);
96 err1:
97 return NULL;