Show
Ignore:
Timestamp:
06/09/10 14:00:40 (14 years ago)
Author:
mido
Message:

astyle applied all over the library

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/osutils.cpp

    r737 r1064  
    3535void get_fname ( char* filename, string &dirname, string &f ) { 
    3636#ifdef WIN32 
    37         sprintf ( filename, "%s\\%s", dirname.c_str(), f.c_str() ); 
     37    sprintf ( filename, "%s\\%s", dirname.c_str(), f.c_str() ); 
    3838#else 
    39         sprintf ( filename, "%s/%s", dirname.c_str() , f.c_str() ); 
     39    sprintf ( filename, "%s/%s", dirname.c_str() , f.c_str() ); 
    4040#endif 
    4141} 
     
    4343void makedir ( string &dirname, bool rewrite ) { 
    4444#ifdef WIN32 
    45         if ( _mkdir ( dirname.c_str() ) == -1 )   // Create the directory 
     45    if ( _mkdir ( dirname.c_str() ) == -1 )   // Create the directory 
    4646#else 
    47         if ( mkdir ( dirname.c_str(), 00755 ) == -1 )   // Create the directory 
     47    if ( mkdir ( dirname.c_str(), 00755 ) == -1 )   // Create the directory 
    4848#endif 
    49         { 
    50                 if ( ( rewrite ) && ( errno == EEXIST ) ) bdm_warning ( "rewriting directory" ); 
    51                 else bdm_error ( "dirfilelog:: cannot create directory" ); 
    52         } 
     49    { 
     50        if ( ( rewrite ) && ( errno == EEXIST ) ) bdm_warning ( "rewriting directory" ); 
     51        else bdm_error ( "dirfilelog:: cannot create directory" ); 
     52    } 
    5353} 
    5454 
    5555bool remove_all ( const char *path ) { 
    56         DIR *dir; 
    57         dirent *de; 
     56    DIR *dir; 
     57    dirent *de; 
    5858 
    59         bool rv = true; 
    60         if ( ( dir = opendir ( path ) ) != 0 ) { 
    61                 try { 
    62                         std::string top ( path ); 
    63                         top += "/"; 
     59    bool rv = true; 
     60    if ( ( dir = opendir ( path ) ) != 0 ) { 
     61        try { 
     62            std::string top ( path ); 
     63            top += "/"; 
    6464 
    65                         while ( ( de = readdir ( dir ) ) != 0 ) { 
    66                                 if ( strcmp ( de->d_name, "." ) && strcmp ( de->d_name, ".." ) ) { 
    67                                         std::string subpath ( top ); 
    68                                         subpath += de->d_name; 
    69                                         remove_all ( subpath.c_str() ); 
    70                                 } 
    71                         } 
    72                 } catch ( ... ) { 
    73                         closedir ( dir ); 
    74                         throw; 
    75                 } 
     65            while ( ( de = readdir ( dir ) ) != 0 ) { 
     66                if ( strcmp ( de->d_name, "." ) && strcmp ( de->d_name, ".." ) ) { 
     67                    std::string subpath ( top ); 
     68                    subpath += de->d_name; 
     69                    remove_all ( subpath.c_str() ); 
     70                } 
     71            } 
     72        } catch ( ... ) { 
     73            closedir ( dir ); 
     74            throw; 
     75        } 
    7676 
    77                 closedir ( dir ); 
     77        closedir ( dir ); 
    7878 
    79                 if ( rmdir ( path ) ) { 
    80                         std::string msg = "can't remove dir "; 
    81                         msg += path; 
    82                         bdm_error ( msg ); 
    83                 } 
    84         } else { 
    85                 if ( ( errno == ENOTDIR ) || // Linux 
    86                         ( errno == EINVAL ) ) { // Windows 
    87                         if ( unlink ( path ) ) { 
    88                                 std::string msg = "can't remove file "; 
    89                                 msg += path; 
    90                                 bdm_error ( msg ); 
    91                         } 
    92                 } else { 
    93                         if ( errno != ENOENT ) { 
    94                                 std::string msg = "can't remove "; 
    95                                 msg += path; 
    96                                 bdm_error ( msg ); 
    97                         } else { 
    98                                 // it wasn't there in the first place 
    99                                 rv = false; 
    100                         } 
    101                 } 
    102         } 
     79        if ( rmdir ( path ) ) { 
     80            std::string msg = "can't remove dir "; 
     81            msg += path; 
     82            bdm_error ( msg ); 
     83        } 
     84    } else { 
     85        if ( ( errno == ENOTDIR ) || // Linux 
     86                ( errno == EINVAL ) ) { // Windows 
     87            if ( unlink ( path ) ) { 
     88                std::string msg = "can't remove file "; 
     89                msg += path; 
     90                bdm_error ( msg ); 
     91            } 
     92        } else { 
     93            if ( errno != ENOENT ) { 
     94                std::string msg = "can't remove "; 
     95                msg += path; 
     96                bdm_error ( msg ); 
     97            } else { 
     98                // it wasn't there in the first place 
     99                rv = false; 
     100            } 
     101        } 
     102    } 
    103103 
    104         return rv; 
     104    return rv; 
    105105}