[csw-maintainers] [csw-devel] [PATCH 1/4] Test for O_DIRECTORY

Joerg Schilling Joerg.Schilling at fokus.fraunhofer.de
Fri Mar 2 12:05:46 CET 2012


Joerg.Schilling at fokus.fraunhofer.de (Joerg Schilling) wrote:

> 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(..);

Sorry for the typo, this should be:

#if O_DIRECTORY == 0

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