views:

80

answers:

2

What is the C++ equivalent of PHP's is_dir() ?

http://www.php.net/manual/en/function.is-dir.php

bool is_dir ( string $filename )
Tells whether the given filename is a directory.

Working on a Linux platform only, what library would you use?

And what if cross-platform support mattered, what method would you use?

+7  A: 

There is nothing in the C++ standard to deal with filesystems across platforms. For cross platform filesystem access, use the Boost Filesystem library.

Grant Limberg
+4  A: 

The POSIX function lstat (and its less secure friend stat) returns a struct that you can query for that information. A convenience macro is provided: S_ISDIR() man 2 lstat for usage information.

Boost also provides the filesystem library, which provides an easy-to-use set of functions, including the free function is_directory().

greyfade
`stat()` isn't "less secure", it's just... different.
caf
@caf: Well, a lot of security issues I come across in software relate to programs that misuse `stat` and end up opening themselves up to symlink attacks. `lstat` simply doesn't follow symlinks and so it doesn't suffer that particular class of attacks.
greyfade