Skip to content

Commit a8ce990

Browse files
committed
Switch to C++20 and modernize formatting code.
1 parent f85df63 commit a8ce990

File tree

10 files changed

+338
-446
lines changed

10 files changed

+338
-446
lines changed

.github/jobs/configure-checks/all.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ compiler_assertions () {
106106

107107
compile_assertions_finished () {
108108
assert_line " * CFLAGS..............: -g -O2 -Wall -Wformat -Wformat-security -pedantic -fstack-protector -fPIE -D_FORTIFY_SOURCE=2 -std=c11"
109-
assert_line " * CXXFLAGS............: -g -O2 -Wall -Wformat -Wformat-security -pedantic -fstack-protector -fPIE -D_FORTIFY_SOURCE=2 -std=c++11"
109+
assert_line " * CXXFLAGS............: -g -O2 -Wall -Wformat -Wformat-security -pedantic -fstack-protector -fPIE -D_FORTIFY_SOURCE=2 -std=c++20"
110110
assert_line " * LDFLAGS.............: -fPIE -pie -Wl,-z,relro -Wl,-z,now"
111111
}
112112

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if test "x$JUDGEHOST_BUILD_ENABLED" = xyes; then
7272
AX_APPEND_LINK_FLAGS([-Wl,-z,now], DEF_LDFLAGS)
7373

7474
test "x$enable_CFLAGS_setting" = xyes && AC_SUBST(CFLAGS, "$DEF_CXFLAGS -std=c11")
75-
test "x$enable_CXXFLAGS_setting" = xyes && AC_SUBST(CXXFLAGS, "$DEF_CXFLAGS -std=c++11")
75+
test "x$enable_CXXFLAGS_setting" = xyes && AC_SUBST(CXXFLAGS, "$DEF_CXFLAGS -std=c++20")
7676
test "x$enable_LDFLAGS_setting" = xyes && AC_SUBST(LDFLAGS, $DEF_LDFLAGS)
7777
fi
7878

judge/evict.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
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

2222
extern int errno;
23-
const char *progname;
23+
std::string_view progname;
2424

2525
int be_verbose;
2626
int 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

Comments
 (0)