Detect windows line endings when executing a file

Fixes #2783.
This commit is contained in:
Fabian Homborg
2020-09-25 16:44:02 +02:00
parent d636918795
commit 0d0ee473fa
2 changed files with 21 additions and 4 deletions

View File

@@ -360,10 +360,17 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const *
const char *interpreter =
get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff);
if (interpreter && 0 != access(interpreter, X_OK)) {
debug_safe(0,
"The file '%s' specified the interpreter '%s', which is not an "
"executable command.",
actual_cmd, interpreter);
// Detect windows line endings and complain specifically about them.
auto len = strlen(interpreter);
if (len && interpreter[len - 1] == '\r') {
debug_safe(0,
"The file uses windows line endings (\\r\\n). Run dos2unix or similar to fix it.");
} else {
debug_safe(0,
"The file '%s' specified the interpreter '%s', which is not an "
"executable command.",
actual_cmd, interpreter);
}
} else {
debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd);
}