-
Notifications
You must be signed in to change notification settings - Fork 19
posix: implement missing directory functions #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| #include <sys/stat.h> | ||
| #include <sys/file.h> | ||
| #include <posix/utils.h> | ||
| #include <fcntl.h> | ||
|
|
||
|
|
||
| static struct { | ||
|
|
@@ -440,6 +441,69 @@ DIR *opendir(const char *dirname) | |
| } | ||
|
|
||
|
|
||
| DIR *fdopendir(int fd) | ||
| { | ||
| DIR *s; | ||
| struct stat statbuf; | ||
| int fd_flags; | ||
|
|
||
| fd_flags = fcntl(fd, F_GETFL); | ||
| if (fd_flags < 0) { | ||
| return NULL; | ||
| } | ||
| if ((fd_flags & O_RDONLY) == 0) { | ||
| errno = EBADF; | ||
| return NULL; /* EBADF */ | ||
| } | ||
|
|
||
| if (fstat(fd, &statbuf) < 0) { | ||
| return NULL; | ||
| } | ||
|
|
||
| msg_t msg = { | ||
| .type = mtGetAttr, | ||
| .oid = { .port = statbuf.st_dev, .id = statbuf.st_ino }, | ||
| .i.attr.type = atType, | ||
| }; | ||
|
|
||
| if ((msgSend(statbuf.st_dev, &msg) < 0) || (msg.o.err < 0)) { | ||
| errno = EIO; | ||
| return NULL; /* EIO */ | ||
| } | ||
|
|
||
| if (msg.o.attr.val != otDir) { | ||
| errno = ENOTDIR; | ||
| return NULL; /* ENOTDIR */ | ||
| } | ||
|
|
||
| if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { | ||
| return NULL; | ||
| } | ||
|
|
||
| s = calloc(1, sizeof(DIR)); | ||
| if (s == NULL) { | ||
| errno = ENOMEM; | ||
| return NULL; | ||
| } | ||
| s->oid = msg.oid; | ||
| s->dirent = NULL; | ||
|
|
||
| return s; | ||
| } | ||
|
|
||
|
|
||
| void seekdir(DIR *dirp, long loc) | ||
| { | ||
| dirp->pos = loc; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other libphoenix functions don't validate whether dirp is non NULL pointer
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right, although I think that this might be a good opportunity to introduce those checks here. |
||
| } | ||
|
|
||
R4ken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| long telldir(DIR *dirp) | ||
| { | ||
| return dirp->pos; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this behavior exists in Linux, POSIX does not specify it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
| } | ||
|
|
||
|
|
||
| void rewinddir(DIR *dirp) | ||
| { | ||
| dirp->pos = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
O_RDWRis set, soO_RDONLYis not? I think a file descriptor open for reading can be as well open for writing, as long as it is still readableUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openfrom libphoenix setsEISDIRon errno while opening directory with eitherO_WRONLYorO_RDWRflag.Thus opening directory with
O_RDWRis not possibleFragment of
openfunction from libphoenixThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour seems common, I can replicate it on both Linux and one of the BSD's, I think we can keep it like that for the sake of compatibility.