Skip to content

Commit 50e26db

Browse files
committed
fix(ci): GNU-extension array literal + macOS-only basename_r
Two more GCC errors from CI on Ubuntu: - `cgi.cpp` was passing `(char *[]){NULL}` as argv to `execvp` — a C99 compound literal that GCC accepts in C but not in C++ (the addresses of the temporary array are then dereferenced by execvp). Replaced with a proper `char* argv[]` local that carries the script path as argv[0] (which is what execvp expects anyway). - `mime_types.cpp::choiceMimeType` called Apple-only `basename_r`, with `PATH_MAX` from `<libgen.h>`, but the result `bname` was never used. Deleted the dead code; the function only needs `path.find_last_of('.')`.
1 parent 0f5209c commit 50e26db

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

src/http/cgi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ pid_t CGI::spawn(int *fds, const int &fileno) {
7474

7575
init();
7676
setenv();
77-
execvp(_scriptFileName.c_str(), (char *[]){NULL});
77+
char *argv[] = { const_cast<char *>(_scriptFileName.c_str()), NULL };
78+
execvp(_scriptFileName.c_str(), argv);
7879
perror("execvp");
7980
exit(1);
8081
}

src/http/mime_types.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,11 @@ MimeType::MimeType(void) {
117117
(*this)[""] = DEFAULT_MIME_TYPE;
118118
}
119119

120-
#include <libgen.h>
121-
122120
MimeType::mapped_type &MimeType::choiceMimeType(const string &path) {
123-
124-
char bname[PATH_MAX] = {0};
125-
basename_r(path.c_str(), bname);
126-
127-
size_t idx = path.find_last_of('.');
128-
121+
const size_t idx = path.find_last_of('.');
129122
if (idx == string::npos)
130123
return (*this)[""];
131-
string ext = path.substr(idx + 1);
132-
133-
return (*this)[ext];
124+
return (*this)[path.substr(idx + 1)];
134125
}
135126

136127
MimeType::mapped_type &MimeType::operator[](const key_type &key) {

0 commit comments

Comments
 (0)