Skip to content

Commit

Permalink
FIX: simplified request-password native code and fixed Win32 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jun 17, 2023
1 parent 8082761 commit bbbabb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
11 changes: 4 additions & 7 deletions src/core/n-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,11 @@ static REBSER *Read_All_File(char *fname)

OS_REQUEST_PASSWORD(&req);

if (req.file.path == NULL) return R_NONE;
if (req.data == NULL) return R_NONE;

#ifdef TO_WINDOWS
str = Decode_UTF_String(req.file.path, req.file.size, 16, 0, 0);
#else
str = Decode_UTF_String(req.file.path, req.file.size, 8, 0, 0);
#endif
FREE_MEM(req.file.path);
str = Copy_OS_Str(req.data, req.actual);

FREE_MEM(req.data);
SET_STRING(D_RET, str);
return R_RET;
}
Expand Down
6 changes: 3 additions & 3 deletions src/os/posix/host-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ static int Try_Browser(char *browser, REBCHR *url)
REBYTE *str = malloc(size);
REBYTE c;

req->file.path = NULL;
req->data = NULL;

while (read(STDIN_FILENO, &c, 1) && c != '\r') {
if (c == 27) { // ESC
Expand All @@ -1400,8 +1400,8 @@ static int Try_Browser(char *browser, REBCHR *url)
str = realloc(str, size);
}
}
req->file.path = str;
req->file.size = pos;
req->data = str;
req->actual = pos;
str[pos++] = 0; // null terminate the tail.. just in case
}

Expand Down
14 changes: 7 additions & 7 deletions src/os/win32/host-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,28 +1445,28 @@ static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPAR
{
REBCNT size = 64;
REBCNT pos = 0;
REBUNI *str = (REBUNI*)malloc(size * sizeof(REBUNI));
REBUNI c;
REBCHR *str = (REBUNI*)malloc(size * sizeof(REBCHR));
REBCHR c;

req->file.path = NULL;
req->data = NULL;

while ((c = _getwch()) != '\r') {
if (c == 27) { // ESC
free(str);
return;
}
if (c == 127) { // backspace
if (c == '\b') { // backspace
if (pos > 0) pos--;
continue;
}
str[pos++] = c;
if (pos+1 == size) {
size += 64;
str = (REBUNI*)realloc(str, size * sizeof(REBUNI));
str = (REBCHR *)realloc(str, size * sizeof(REBCHR));
}
}
req->file.path = (REBYTE*)str;
req->file.size = pos * sizeof(REBUNI);
req->data = (REBYTE*)str;
req->actual = pos;
str[pos++] = 0;
}

0 comments on commit bbbabb0

Please sign in to comment.