[csw-maintainers] [csw-devel] [PATCH 1/4] Test for O_DIRECTORY
Joerg Schilling
Joerg.Schilling at fokus.fraunhofer.de
Fri Mar 2 11:51:51 CET 2012
Maciej (Matchek) Blizi??ski <maciej at opencsw.org> wrote:
> 2012/3/2 Joerg Schilling <Joerg.Schilling at fokus.fraunhofer.de>:
> >> Here's a porting topic. It started with me working on a VLC build.
> >> O_DIRECTORY is not available on Solaris 10 and my patch to set it to 0
> >> has been rejected. I'm looking for a better solution. More below.
> >
> > So they reject the best possible solution?
> >
> > This sounds really strange.
>
> It does sound strange, doesn't it? I've asked for suggestions[1], but
> got no answers. Is there anything online that I could refer to in
> order to demonstrate that this is a sane approach?
As mentioned before, POSIX grants that O_* are #defined, so you can safely rely
on #ifdef O_XXX.
> Maciej
>
> [1] http://mailman.videolan.org/pipermail/vlc-devel/2012-March/086993.html
Sorry, it seems that I confused O_DIRECTORY with O_SEARCH
I entered O_SEARCH into POSIX in order to permit:
int f = open(name, O_SEARCH);
result = fstat(f, &sb);
or
f2 = openat(f, name2, flags);
to work with no restrictions compared to a filename-only case.
The correct way to deal with O_DIRECTORY is:
#ifndef O_DIRECTORY /* Fail if not a directory */
# define O_DIRECTORY 0
#endif
int f = open(dirname, O_DIRECTORY);
#if O_DIRECTORY != 0
if (f >= 0) {
fstat(f, &sb);
if (!S_ISDIR(sb.st_mode)) {
flose(f);
f = -1;
errno = ENOTDIR;
}
}
#endif
if (f < 0)
err(..);
Jörg
--
EMail:joerg at schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js at cs.tu-berlin.de (uni)
joerg.schilling at fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
URL: http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily
More information about the maintainers
mailing list