Navigation Menu

Skip to content

Commit

Permalink
windows: remove a trailing new line from system error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 14, 2015
1 parent b1f7443 commit 6f6cbf0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/error.c
Expand Up @@ -30,15 +30,26 @@ grn_current_error_message(void)
# define ERROR_MESSAGE_BUFFER_SIZE 4096
int error_code = GetLastError();
static char message[ERROR_MESSAGE_BUFFER_SIZE];
DWORD written_bytes;

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message,
ERROR_MESSAGE_BUFFER_SIZE,
NULL);
written_bytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message,
ERROR_MESSAGE_BUFFER_SIZE,
NULL);
if (written_bytes >= 2) {
if (message[written_bytes - 1] == '\n') {
message[written_bytes - 1] = '\0';
written_bytes--;
}
if (message[written_bytes - 1] == '\r') {
message[written_bytes - 1] = '\0';
written_bytes--;
}
}

return message;

Expand Down

0 comments on commit 6f6cbf0

Please sign in to comment.