diff --git a/base/applications/cmdutils/hostname/CMakeLists.txt b/base/applications/cmdutils/hostname/CMakeLists.txt index 50b38605c12..d144c9a31ab 100644 --- a/base/applications/cmdutils/hostname/CMakeLists.txt +++ b/base/applications/cmdutils/hostname/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(hostname hostname.c hostname.rc) set_module_type(hostname win32cui UNICODE) -add_importlibs(hostname user32 msvcrt kernel32) +target_link_libraries(hostname conutils) +add_importlibs(hostname msvcrt kernel32) add_cd_file(TARGET hostname DESTINATION reactos/system32 FOR all) diff --git a/base/applications/cmdutils/hostname/hostname.c b/base/applications/cmdutils/hostname/hostname.c index c9385f1addd..1c507d5bf38 100644 --- a/base/applications/cmdutils/hostname/hostname.c +++ b/base/applications/cmdutils/hostname/hostname.c @@ -1,9 +1,9 @@ /* * PROJECT: ReactOS Hostname Command - * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+) + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) * PURPOSE: Retrieves the current DNS host name of the computer. - * COPYRIGHT: Copyright 2005-2019 Emanuele Aliberti (ea@reactos.com) - * Copyright 2019 Hermes Belusca-Maito + * COPYRIGHT: Copyright 2005 Emanuele Aliberti + * Copyright 2019-2026 Hermès Bélusca-Maïto */ #include @@ -11,13 +11,35 @@ #include #include -#include + +#include #include "resource.h" +static VOID +PrintError( + _In_opt_ PCWSTR Message, + _In_ DWORD dwError) +{ + INT Len; + + if (dwError == ERROR_SUCCESS) + return; + + if (IS_INTRESOURCE(Message)) + ConResPuts(StdErr, PtrToUlong(Message)); + else // if (Message) + ConPuts(StdErr, Message); + Len = ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM, + NULL, dwError, LANG_USER_DEFAULT); + if (Len <= 0) /* Fall back in case the error is not defined */ + ConPrintf(StdErr, L"%lu\n", dwError); +} + int wmain(int argc, WCHAR* argv[]) { - WCHAR Msg[100]; + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); if (argc == 1) { @@ -36,11 +58,9 @@ int wmain(int argc, WCHAR* argv[]) bSuccess = GetComputerNameExW(ComputerNameDnsHostname, HostName, &HostNameSize); } + /* Print out the host name */ if (bSuccess) - { - /* Print out the host name */ - wprintf(L"%s\n", HostName); - } + ConPrintf(StdOut, L"%s\n", HostName); /* If a larger buffer has been allocated, free it */ if (HostName && (HostName != LocalHostName)) @@ -49,8 +69,7 @@ int wmain(int argc, WCHAR* argv[]) if (!bSuccess) { /* Fail in case of error */ - LoadStringW(GetModuleHandle(NULL), IDS_ERROR, Msg, _countof(Msg)); - wprintf(L"%s %lu.\n", Msg, GetLastError()); + PrintError(MAKEINTRESOURCEW(IDS_ERROR), GetLastError()); return 1; } } @@ -59,15 +78,13 @@ int wmain(int argc, WCHAR* argv[]) if ((_wcsicmp(argv[1], L"-s") == 0) || (_wcsicmp(argv[1], L"/s") == 0)) { /* The program doesn't allow the user to set the host name */ - LoadStringW(GetModuleHandle(NULL), IDS_NOSET, Msg, _countof(Msg)); - wprintf(L"%s\n", Msg); + ConResPuts(StdErr, IDS_NOSET); return 1; } else { /* Let the user know what the program does */ - LoadStringW(GetModuleHandle(NULL), IDS_USAGE, Msg, _countof(Msg)); - wprintf(L"\n%s\n\n", Msg); + ConResPuts(StdOut, IDS_USAGE); } } diff --git a/base/applications/cmdutils/hostname/hostname.rc b/base/applications/cmdutils/hostname/hostname.rc index d6d62c1b85d..500431c8bea 100644 --- a/base/applications/cmdutils/hostname/hostname.rc +++ b/base/applications/cmdutils/hostname/hostname.rc @@ -4,9 +4,9 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#define REACTOS_STR_FILE_DESCRIPTION "Host name application" -#define REACTOS_STR_INTERNAL_NAME "hostname" -#define REACTOS_STR_ORIGINAL_FILENAME "hostname.exe" +#define REACTOS_STR_FILE_DESCRIPTION "Host name application" +#define REACTOS_STR_INTERNAL_NAME "hostname" +#define REACTOS_STR_ORIGINAL_FILENAME "hostname.exe" #include /* UTF-8 */ diff --git a/base/applications/cmdutils/hostname/lang/cs-CZ.rc b/base/applications/cmdutils/hostname/lang/cs-CZ.rc index b3298ed0f34..a5fe4acf932 100644 --- a/base/applications/cmdutils/hostname/lang/cs-CZ.rc +++ b/base/applications/cmdutils/hostname/lang/cs-CZ.rc @@ -7,7 +7,7 @@ LANGUAGE LANG_CZECH, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Vypíše současný název hostitele.\n\nhostname" - IDS_NOSET "hostname -s není podporováno." - IDS_ERROR "Win32 chyba" + IDS_USAGE "\nVypíše současný název hostitele.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s není podporováno.\n" + IDS_ERROR "Chyba: " END diff --git a/base/applications/cmdutils/hostname/lang/de-DE.rc b/base/applications/cmdutils/hostname/lang/de-DE.rc index b7a53bf877e..f4d27e5772e 100644 --- a/base/applications/cmdutils/hostname/lang/de-DE.rc +++ b/base/applications/cmdutils/hostname/lang/de-DE.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL STRINGTABLE BEGIN - IDS_USAGE "Zeigt den Computernamen an.\n\nhostname" - IDS_NOSET "Der Befehl hostname -s wird nicht unterstützt." - IDS_ERROR "Win32-Fehler" + IDS_USAGE "\nZeigt den Computernamen an.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nDer Befehl hostname -s wird nicht unterstützt.\n" + IDS_ERROR "Fehler: " END diff --git a/base/applications/cmdutils/hostname/lang/en-US.rc b/base/applications/cmdutils/hostname/lang/en-US.rc index d1ee89e5678..8c72b4c7b73 100644 --- a/base/applications/cmdutils/hostname/lang/en-US.rc +++ b/base/applications/cmdutils/hostname/lang/en-US.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US STRINGTABLE BEGIN - IDS_USAGE "Print the current host's name.\n\nhostname" - IDS_NOSET "hostname -s is not supported." - IDS_ERROR "Win32 error" + IDS_USAGE "\nPrint the current host's name.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s is not supported.\n" + IDS_ERROR "Error: " END diff --git a/base/applications/cmdutils/hostname/lang/et-EE.rc b/base/applications/cmdutils/hostname/lang/et-EE.rc index b4c5eb8bb9c..9f72d2420fe 100644 --- a/base/applications/cmdutils/hostname/lang/et-EE.rc +++ b/base/applications/cmdutils/hostname/lang/et-EE.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_ESTONIAN, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Trükib praeguse hosti nime.\n\nhostname" - IDS_NOSET "hostname -s ei ole toetatud." - IDS_ERROR "Win32 tõrge" + IDS_USAGE "\nTrükib praeguse hosti nime.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s ei ole toetatud.\n" + IDS_ERROR "Tõrge: " END diff --git a/base/applications/cmdutils/hostname/lang/fr-FR.rc b/base/applications/cmdutils/hostname/lang/fr-FR.rc index 020957f7845..aedc4b2eae6 100644 --- a/base/applications/cmdutils/hostname/lang/fr-FR.rc +++ b/base/applications/cmdutils/hostname/lang/fr-FR.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL STRINGTABLE BEGIN - IDS_USAGE "Affiche le nom de l'hôte actuel.\n\nhostname" - IDS_NOSET "hostname -s n'est pas pris en charge." - IDS_ERROR "Erreur Win32" + IDS_USAGE "\nAffiche le nom de l'hôte actuel.\n\nhostname\n" + IDS_NOSET "sethostname: Ouvrez l'onglet ""Nom de l'ordinateur"" de l'élément ""Système""\ndu Panneau de configuration pour modifier le nom de l'hôte.\nhostname -s n'est pas pris en charge.\n" + IDS_ERROR "Erreur : " END diff --git a/base/applications/cmdutils/hostname/lang/it-IT.rc b/base/applications/cmdutils/hostname/lang/it-IT.rc index 9e1db2caeef..a9c4b839cc1 100644 --- a/base/applications/cmdutils/hostname/lang/it-IT.rc +++ b/base/applications/cmdutils/hostname/lang/it-IT.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_ITALIAN, SUBLANG_NEUTRAL STRINGTABLE BEGIN - IDS_USAGE "Stampa il nome dell'host attuale.\n\nhostname" - IDS_NOSET "hostname -s non è supportato." - IDS_ERROR "errore Win32" + IDS_USAGE "\nStampa il nome dell'host attuale.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s non è supportato.\n" + IDS_ERROR "Errore: " END diff --git a/base/applications/cmdutils/hostname/lang/pl-PL.rc b/base/applications/cmdutils/hostname/lang/pl-PL.rc index f61a127fec7..637c07d2f26 100644 --- a/base/applications/cmdutils/hostname/lang/pl-PL.rc +++ b/base/applications/cmdutils/hostname/lang/pl-PL.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_POLISH, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Wyświetla obecną nazwę komputera.\n\nhostname" - IDS_NOSET "Opcja hostname -s nie jest wspierana." - IDS_ERROR "Błąd Win32" + IDS_USAGE "\nWyświetla obecną nazwę komputera.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nOpcja hostname -s nie jest wspierana.\n" + IDS_ERROR "Błąd: " END diff --git a/base/applications/cmdutils/hostname/lang/ro-RO.rc b/base/applications/cmdutils/hostname/lang/ro-RO.rc index 6f64aa6f831..db65c533967 100644 --- a/base/applications/cmdutils/hostname/lang/ro-RO.rc +++ b/base/applications/cmdutils/hostname/lang/ro-RO.rc @@ -4,7 +4,7 @@ LANGUAGE LANG_ROMANIAN, SUBLANG_NEUTRAL STRINGTABLE BEGIN - IDS_USAGE "Tipărește numele gazdei curente.\n\nhostname" - IDS_NOSET "hostname -s nu este acceptat." - IDS_ERROR "Eroare Win32" + IDS_USAGE "\nTipărește numele gazdei curente.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s nu este acceptat.\n" + IDS_ERROR "Eroare: " END diff --git a/base/applications/cmdutils/hostname/lang/ru-RU.rc b/base/applications/cmdutils/hostname/lang/ru-RU.rc index 669b93ae73e..f98e66f8a8d 100644 --- a/base/applications/cmdutils/hostname/lang/ru-RU.rc +++ b/base/applications/cmdutils/hostname/lang/ru-RU.rc @@ -2,7 +2,7 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Печать имени текущего узла.\n\nhostname" - IDS_NOSET "hostname -s не поддерживается." - IDS_ERROR "Ошибка Win32" + IDS_USAGE "\nПечать имени текущего узла.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s не поддерживается.\n" + IDS_ERROR "Ошибка: " END diff --git a/base/applications/cmdutils/hostname/lang/sk-SK.rc b/base/applications/cmdutils/hostname/lang/sk-SK.rc index 0339b98da9c..ef526779119 100644 --- a/base/applications/cmdutils/hostname/lang/sk-SK.rc +++ b/base/applications/cmdutils/hostname/lang/sk-SK.rc @@ -9,7 +9,7 @@ LANGUAGE LANG_SLOVAK, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Vypíše súčasný názov hostiteľa.\n\nhostname" - IDS_NOSET "hostname -s nie je podporovaný." - IDS_ERROR "Chyba Win32" + IDS_USAGE "\nVypíše súčasný názov hostiteľa.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s nie je podporovaný.\n" + IDS_ERROR "Chyba: " END diff --git a/base/applications/cmdutils/hostname/lang/sq-AL.rc b/base/applications/cmdutils/hostname/lang/sq-AL.rc index 5243966bb0e..4861bf50dba 100644 --- a/base/applications/cmdutils/hostname/lang/sq-AL.rc +++ b/base/applications/cmdutils/hostname/lang/sq-AL.rc @@ -6,7 +6,7 @@ LANGUAGE LANG_ALBANIAN, SUBLANG_NEUTRAL STRINGTABLE BEGIN - IDS_USAGE "Print emrin e strehuesit aktual.\n\nhostname" - IDS_NOSET "Strehuesi nuk është i mbështetur." - IDS_ERROR "Win32 error" + IDS_USAGE "\nPrint emrin e strehuesit aktual.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nStrehuesi nuk është i mbështetur.\n" + IDS_ERROR "Error: " END diff --git a/base/applications/cmdutils/hostname/lang/tr-TR.rc b/base/applications/cmdutils/hostname/lang/tr-TR.rc index 5bf61d43bf7..0d5f9924e9f 100644 --- a/base/applications/cmdutils/hostname/lang/tr-TR.rc +++ b/base/applications/cmdutils/hostname/lang/tr-TR.rc @@ -4,7 +4,7 @@ LANGUAGE LANG_TURKISH, SUBLANG_DEFAULT STRINGTABLE BEGIN - IDS_USAGE "Şimdiki anabilgisayarın adını yazdırır.\n\nhostname" - IDS_NOSET "hostname -s desteklenmiyor." - IDS_ERROR "Win32 hatası" + IDS_USAGE "\nŞimdiki anabilgisayarın adını yazdırır.\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s desteklenmiyor.\n" + IDS_ERROR "Hatası: " END diff --git a/base/applications/cmdutils/hostname/lang/zh-CN.rc b/base/applications/cmdutils/hostname/lang/zh-CN.rc index 463dc00d075..75225209da9 100644 --- a/base/applications/cmdutils/hostname/lang/zh-CN.rc +++ b/base/applications/cmdutils/hostname/lang/zh-CN.rc @@ -4,7 +4,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED STRINGTABLE BEGIN - IDS_USAGE "打印当前主机名。\n\nhostname" - IDS_NOSET "hostname -s 不受支持。" - IDS_ERROR "Win32 错误" + IDS_USAGE "\n打印当前主机名。\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\nhostname -s 不受支持。\n" + IDS_ERROR "错误: " END diff --git a/base/applications/cmdutils/hostname/lang/zh-TW.rc b/base/applications/cmdutils/hostname/lang/zh-TW.rc index a65ab6a8173..45f33160744 100644 --- a/base/applications/cmdutils/hostname/lang/zh-TW.rc +++ b/base/applications/cmdutils/hostname/lang/zh-TW.rc @@ -10,7 +10,7 @@ LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL STRINGTABLE BEGIN - IDS_USAGE "列印目前主機的名稱。\n\nhostname" - IDS_NOSET "不支援 hostname -s。" - IDS_ERROR "Win32 錯誤" + IDS_USAGE "\n列印目前主機的名稱。\n\nhostname\n" + IDS_NOSET "sethostname: Open the ""Computer Name"" tab in the ""System"" Control Panel applet\nto change the host name.\n不支援 hostname -s。\n" + IDS_ERROR "錯誤: " END