[filesystem] status() semantics?

To nail down the semantics of status(), let's try a different approach. Some of the difficulty may be a matter of miscommunication, so perhaps actual code will add clarity. Perhaps Peter or others who have views on what the semantics of boost::filesystem::status() should be could change the code below to implement those semantics. Hopefully that will eliminate any confusion as to exactly meaning. --Beman --------- status_flag status_imp( const char * path, system_error_type * ec ) { struct stat path_stat; if ( ::stat( path, &path_stat ) != 0 ) { if ( ec != 0 ) *ec = errno; return ((errno == ENOENT) || (errno == ENOTDIR)) ? fs::not_found_flag : fs::error_flag; } system_error_type result(0); if ( S_ISDIR( path_stat.st_mode ) ) result |= fs::directory_flag; if ( S_ISREG( path_stat.st_mode ) ) result |= fs::file_flag; return result; }

Beman Dawes wrote:
status_flag status_imp( const char * path, system_error_type * ec ) { struct stat path_stat;
if ( ::stat( path, &path_stat ) != 0 ) { if ( ec != 0 ) *ec = errno; return ((errno == ENOENT) || (errno == ENOTDIR)) ? fs::not_found_flag : fs::error_flag; }
system_error_type result(0);
status_flag result( 0 );
if ( S_ISDIR( path_stat.st_mode ) ) result |= fs::directory_flag; if ( S_ISREG( path_stat.st_mode ) ) result |= fs::file_flag;
return result; }
This makes perfect sense; what changes did you expect from me? :-)

At 02:54 PM 5/12/2005, Peter Dimov wrote:
Beman Dawes wrote:
status_flag status_imp( const char * path, system_error_type * ec ) { struct stat path_stat;
if ( ::stat( path, &path_stat ) != 0 ) { if ( ec != 0 ) *ec = errno; return ((errno == ENOENT) || (errno == ENOTDIR)) ? fs::not_found_flag : fs::error_flag; }
system_error_type result(0);
status_flag result( 0 );
Oops! Right.
if ( S_ISDIR( path_stat.st_mode ) ) result |= fs::directory_flag; if ( S_ISREG( path_stat.st_mode ) ) result |= fs::file_flag;
return result; }
This makes perfect sense; what changes did you expect from me? :-)
Seemed better to ask than guess:-) One possible change would be to add, just before the final return: if ( ec != 0 ) *ec = 0; But that seems gratuitous to me; the user can always set *ec = 0 before the call to status() if desired. --Beman
participants (2)
-
Beman Dawes
-
Peter Dimov