mailing list of musl libc
 help / color / mirror / code / Atom feed
* fdopendir (BUG?)
@ 2019-01-28 12:37 Jorge Almeida
  2019-01-28 16:16 ` Rich Felker
  2019-01-28 18:53 ` Adhemerval Zanella
  0 siblings, 2 replies; 7+ messages in thread
From: Jorge Almeida @ 2019-01-28 12:37 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Calling fdopendir with a file descriptor obtained with O_PATH yields a
bad directory  stream descriptor (as it should, if I understood
correctly the documentation of open() re O_PATH). However, the call
doesn't fail (it should fail with EBADF). A subsequent call to readdir
(3) detects the error.

(the problem also occurs with glibc, besides the fact that glibc
requires also _GNU_SOURCE to compile, contradicting  the linux man
page)

Am I  missing something? (Complete test program in attachement, so
that Gmail doesn't crap it.)

Thanks,

Jorge Almeida

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 792 bytes --]

#define _POSIX_C_SOURCE 200809L
//#define _GNU_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>

/* "somedir" should be an existing subdirectory of the current directory */

int main(int argc, char* argv[]){
		int fd=open("somedir", O_RDONLY|O_PATH|O_DIRECTORY);
//		int fd=open("somedir", O_RDONLY|O_DIRECTORY);
		if(fd == -1){
				fprintf(stderr, "open: %d\n", errno);
				exit(1);
		}
		DIR* dir=fdopendir(fd);
//		DIR* dir=opendir("somedir");
		if(dir == NULL){
				fprintf(stderr, "fdopendir: %d\n", errno);
				exit(1);
		}
		struct dirent* de;
		errno=0;
		de=readdir(dir);
		if(de == NULL && errno){
				fprintf(stderr, "readdir: %d\n", errno);
				exit(1);
		}
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-01-29  1:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 12:37 fdopendir (BUG?) Jorge Almeida
2019-01-28 16:16 ` Rich Felker
2019-01-28 18:53 ` Adhemerval Zanella
2019-01-28 19:42   ` Jorge Almeida
2019-01-28 20:30     ` Adhemerval Zanella
2019-01-28 21:33       ` Jorge Almeida
2019-01-29  1:50         ` Adhemerval Zanella

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).