windows: getline fixes & discard trailing CRLF
This commit is contained in:
parent
c88b7c6a14
commit
381460e92e
@ -908,6 +908,7 @@ int main(int argc, char* argv[]) {
|
||||
i64 read = getline(&ln, &gl, stdin);
|
||||
if (read<=0 || ln[0]==0) { if(!silentREPL) putchar('\n'); break; }
|
||||
if (ln[read-1]==10) ln[--read] = 0;
|
||||
if (ln[read-1]==13) ln[--read] = 0;
|
||||
cbqn_runLine(ln, read);
|
||||
free(ln);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ ssize_t getline (char **lptr, size_t *n, FILE *fp) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
convertResult = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
|
||||
convertResult = WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
|
||||
if (convertResult == 0) {
|
||||
fprintf(stderr, "Failed to get MultiByte length: %d", GetLastError());
|
||||
goto error;
|
||||
@ -27,13 +27,13 @@ ssize_t getline (char **lptr, size_t *n, FILE *fp) {
|
||||
|
||||
m = *lptr = (char*) calloc(convertResult, sizeof(char));
|
||||
|
||||
if (WideCharToMultiByte(CP_ACP, 0, buf, -1, m, convertResult, NULL, NULL) == 0 ) {
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, buf, -1, m, convertResult, NULL, NULL) == 0 ) {
|
||||
fprintf(stderr, "Failed to convert wide characters: %d", GetLastError());
|
||||
free(m);
|
||||
goto error;
|
||||
}
|
||||
|
||||
return convertResult;
|
||||
return convertResult-1;
|
||||
|
||||
error:
|
||||
CloseHandle(hIn);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user