Index: reactos/base/applications/cmdutils/mode/mode.c =================================================================== --- reactos/base/applications/cmdutils/mode/mode.c (revision 74045) +++ reactos/base/applications/cmdutils/mode/mode.c (working copy) @@ -4,6 +4,7 @@ * mode.c * * Copyright (C) 2002 Robert Dickenson + * Copyright (C) 2017 Katayama Hirofumi MZ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +27,7 @@ * PURPOSE: Provides fast mode setup for DOS devices. * PROGRAMMERS: Robert Dickenson * Hermes Belusca-Maito + * Katayama Hirofumi MZ */ #include @@ -69,8 +71,7 @@ szMsgBuffer[i] = L'-'; szMsgBuffer[Len] = UNICODE_NULL; - // FIXME: Use ConStreamWrite instead. - ConPuts(Stream, szMsgBuffer); + ConStreamWrite(Stream, szMsgBuffer, Len); return Len; } @@ -77,43 +78,61 @@ int QueryDevices(VOID) { - WCHAR buffer[20240]; - WCHAR* ptr = buffer; + WCHAR *Buffer, *ptr; + DWORD dwLen = 64; - *ptr = L'\0'; - // FIXME: Dynamically allocate 'buffer' in a loop. - if (QueryDosDeviceW(NULL, buffer, ARRAYSIZE(buffer))) + Buffer = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR)); + if (Buffer == NULL) + return 0; /* failure */ + + for (;;) { - while (*ptr != L'\0') + *Buffer = UNICODE_NULL; + if (QueryDosDeviceW(NULL, Buffer, dwLen)) + break; /* OK */ + + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - if (wcsstr(ptr, L"COM")) - { - ConResPrintf(StdOut, IDS_QUERY_SERIAL_FOUND, ptr); - } - else if (wcsstr(ptr, L"PRN")) - { - ConResPrintf(StdOut, IDS_QUERY_PRINTER_FOUND, ptr); - } - else if (wcsstr(ptr, L"LPT")) - { - ConResPrintf(StdOut, IDS_QUERY_PARALLEL_FOUND, ptr); - } - else if (wcsstr(ptr, L"AUX") || wcsstr(ptr, L"NUL")) - { - ConResPrintf(StdOut, IDS_QUERY_DOSDEV_FOUND, ptr); - } - else - { - // ConResPrintf(StdOut, IDS_QUERY_MISC_FOUND, ptr); - } - ptr += (wcslen(ptr) + 1); + wprintf(L"ERROR: QueryDosDeviceW(...) failed: 0x%lx\n", GetLastError()); + HeapFree(GetProcessHeap(), 0, Buffer); + return 0; /* failure */ } + + dwLen *= 2; + Buffer = HeapReAlloc(GetProcessHeap(), 0, Buffer, dwLen * sizeof(WCHAR)); + if (Buffer == NULL) + { + return 0; /* failure */ + } } - else + + for (ptr = Buffer; *ptr != UNICODE_NULL; ptr += wcslen(ptr) + 1) { - wprintf(L"ERROR: QueryDosDeviceW(...) failed: 0x%lx\n", GetLastError()); + if (wcsstr(ptr, L"COM")) + { + ConResPrintf(StdOut, IDS_QUERY_SERIAL_FOUND, ptr); + } + else if (wcsstr(ptr, L"PRN")) + { + ConResPrintf(StdOut, IDS_QUERY_PRINTER_FOUND, ptr); + } + else if (wcsstr(ptr, L"LPT")) + { + ConResPrintf(StdOut, IDS_QUERY_PARALLEL_FOUND, ptr); + } + else if (wcsstr(ptr, L"AUX") || wcsstr(ptr, L"NUL")) + { + ConResPrintf(StdOut, IDS_QUERY_DOSDEV_FOUND, ptr); + } + else + { + /* FIXME */ + /* ConResPrintf(StdOut, IDS_QUERY_MISC_FOUND, ptr); */ + } } - return 1; + + HeapFree(GetProcessHeap(), 0, Buffer); + return 1; /* success */ } int ShowParallelStatus(INT nPortNum) @@ -1166,8 +1185,14 @@ } else if (_wcsnicmp(argStr, L"/STA", 4) == 0) { - // FIXME: Check if there are other "parameters" after the status, - // in which case this is invalid. + if (wcschr(argStr + 4, L'/') != NULL || + wcschr(argStr + 4, L'=') != NULL) + { + // if there are other "parameters" after the status, + // in which case this is invalid. + ConResPuts(StdOut, IDS_USAGE); + goto Quit; + } goto show_status; } else if (_wcsnicmp(argStr, L"LPT", 3) == 0)