From 902da46de3ea790abb48e30b6dbf3a5272c2a3ab Mon Sep 17 00:00:00 2001 From: OetkenPurveyorOfCode Date: Wed, 18 Oct 2023 23:34:01 +0200 Subject: [PATCH] Add build instructions. --- README.md | 18 +++++++++++++++++- main.c | 19 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bffe54a..f23468f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,23 @@ Added Directory to path ``` # Building -Building with gcc +Building with gcc: +``` +gcc main.c -o addtopath.exe +``` +Building with clang: +``` +clang main.c -o addtopath.exe +``` +Building with MSVC: +``` +cl main.c /Fe:addtopath.exe +``` +Building with Zig: +``` +zig cc main.c -o main.exe +``` +For contributions make sure that the source compiles with no errors or warnings and use the following compiler flags: Example clang: ``` ``` diff --git a/main.c b/main.c index cf48217..415a179 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #pragma comment(lib, "Advapi32.lib") #if LOG @@ -11,6 +12,11 @@ #define add_to_path_log(...) #endif +#ifdef __TINYC__ +typedef long LSTATUS; +#define wcscat_s(a, b, c) wcscat(a, c) +#endif + typedef enum { ATP_FailedToSetRegistryKey, ATP_FailedToOpenRegistryKey, @@ -20,7 +26,7 @@ typedef enum { AddToPathErr add_to_path(const wchar_t* input_path) { wchar_t path[32*1024] = {'%', 'P', 'A', 'T', 'H', '%', ';'}; - wcscat(path, input_path); + wcscat_s(path, 16*1024, input_path); HKEY key_handle = 0; DWORD disposition = 0; LSTATUS status = RegCreateKeyExW( @@ -54,7 +60,7 @@ AddToPathErr add_to_path(const wchar_t* input_path) { 0, REG_EXPAND_SZ, (BYTE*) path_expanded, - 2 *wcslen(path_expanded) + 1 + (DWORD)(2*wcslen(path_expanded) + 1) ); if (status2 == ERROR_SUCCESS) { return ATP_Ok; @@ -62,8 +68,15 @@ AddToPathErr add_to_path(const wchar_t* input_path) { return ATP_FailedToSetRegistryKey; } } - + +#ifdef __GNUC__ +int main(int _argc, char** _argv) { + (void) _argc; (void) _argv; + int argc = 0; + wchar_t ** argv = CommandLineToArgvW(GetCommandLineW(), &argc); +#else int wmain(int argc, wchar_t** argv) { +#endif if (argc == 2) { wchar_t path[MAX_PATH]; if(GetFullPathNameW(argv[1], MAX_PATH, path, NULL) == 0) {