1414
1515#include " lib.misc.h"
1616
17- #include " lib.error.h "
17+ #include " lib.error.hpp "
1818
1919#define PROGRAM " evict"
2020#define VERSION DOMJUDGE_VERSION " /" REVISION
2121
2222extern int errno;
23- const char * progname;
23+ std::string_view progname;
2424
2525int be_verbose;
2626int show_help;
@@ -51,7 +51,7 @@ void evict_directory(const std::string& dirname) {
5151
5252 dir = opendir (dirname.c_str ());
5353 if (dir != NULL ) {
54- if (be_verbose) logmsg (LOG_INFO, " Evicting all files in directory: %s " , dirname. c_str () );
54+ if (be_verbose) logmsg (LOG_INFO, " Evicting all files in directory: {} " , dirname);
5555
5656 /* Read everything in the directory */
5757 while ( (entry = readdir (dir)) != NULL ) {
@@ -64,14 +64,14 @@ void evict_directory(const std::string& dirname) {
6464 std::string entry_path = dirname + " /" + entry->d_name ;
6565 fd = open (entry_path.c_str (), O_RDONLY, 0 );
6666 if (fd == -1 ) {
67- warning (errno, " Unable to open file: %s " , entry_path. c_str () );
67+ warning (errno, " Unable to open file: {} " , entry_path);
6868 continue ;
6969 }
7070
7171 if (fstat (fd, &s) < 0 ) {
72- if (be_verbose) logerror (errno, " Unable to stat file/directory: %s \n " , entry_path. c_str () );
72+ if (be_verbose) logerror (errno, " Unable to stat file/directory: {} \n " , entry_path);
7373 if ( close (fd)!=0 ) {
74- warning (errno, " Unable to close file: %s " , entry_path. c_str () );
74+ warning (errno, " Unable to close file: {} " , entry_path);
7575 }
7676 continue ;
7777 }
@@ -81,21 +81,21 @@ void evict_directory(const std::string& dirname) {
8181 } else {
8282 /* evict this file from the cache */
8383 if (posix_fadvise (fd, 0 , 0 , POSIX_FADV_DONTNEED)) {
84- warning (errno, " Unable to evict file: %s \n " , entry_path. c_str () );
84+ warning (errno, " Unable to evict file: {} \n " , entry_path);
8585 } else {
86- if (be_verbose) logmsg (LOG_DEBUG, " Evicted file: %s " , entry_path. c_str () );
86+ if (be_verbose) logmsg (LOG_DEBUG, " Evicted file: {} " , entry_path);
8787 }
8888 }
8989
9090 if ( close (fd)!=0 ) {
91- warning (errno, " Unable to close file: %s " , entry_path. c_str () );
91+ warning (errno, " Unable to close file: {} " , entry_path);
9292 }
9393 }
9494 if ( closedir (dir)!=0 ) {
95- warning (errno, " Unable to close directory: %s " , dirname. c_str () );
95+ warning (errno, " Unable to close directory: {} " , dirname);
9696 }
9797 } else {
98- warning (errno, " Unable to open directory: %s " , dirname. c_str () );
98+ warning (errno, " Unable to open directory: {} " , dirname);
9999 }
100100}
101101
@@ -118,10 +118,10 @@ int main(int argc, char *argv[])
118118 break ;
119119 case ' :' : /* getopt error */
120120 case ' ?' :
121- logmsg (LOG_ERR, " unknown option or missing argument `%c' " , optopt);
121+ logmsg (LOG_ERR, " unknown option or missing argument `{}` " , ( char ) optopt);
122122 break ;
123123 default :
124- logmsg (LOG_ERR, " getopt returned character code `%c' ??" , (char )opt);
124+ logmsg (LOG_ERR, " getopt returned character code `{}` ??" , (char )opt);
125125 }
126126 }
127127
0 commit comments