From 4ab197add10847d4ba3036ed525f96db00a9849f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 10 Jul 2025 15:32:21 +0200 Subject: checkpoint --- code/linux_handmade.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) (limited to 'code/linux_handmade.cpp') diff --git a/code/linux_handmade.cpp b/code/linux_handmade.cpp index bf33f72..ba75aed 100644 --- a/code/linux_handmade.cpp +++ b/code/linux_handmade.cpp @@ -1,14 +1,14 @@ #include -#include -#include #include -#include -#include +#include #include #include + #include #include - +#include +#include +#include #include #include #include @@ -629,6 +629,62 @@ DEBUG_PLATFORM_READ_ENTIRE_FILE(DEBUGPlatformReadEntireFile) return Result; } +PLATFORM_RUN_COMMAND_AND_GET_OUTPUT(PlatformRunCommandAndGetOutput) +{ + int Result = 0; + + int HandlesLink[2] = {0}; + int WaitStatus = 0; + pid_t ChildPID = 0; + int Ret = 0; + + char *FilePath = Command[0]; + int AccessMode = F_OK | X_OK; + Ret = access(FilePath, AccessMode); + + if(Ret == 0) + { + Ret = pipe(HandlesLink); + if(Ret != -1) + { + ChildPID = fork(); + if(ChildPID != -1) + { + if(ChildPID == 0) + { + dup2(HandlesLink[1], STDOUT_FILENO); + execve(Command[0], Command, 0); + } + else + { + wait(&WaitStatus); + + Result = read(HandlesLink[0], OutputBuffer, 4096); + if(Result == -1) + { + Result = 0; + } + } + + } + else + { + // TODO: Logging + } + } + else + { + // TODO: Logging + } + } + else + { + // TODO: Logging + } + + return Result; +} + DEBUG_PLATFORM_FREE_FILE_MEMORY(DEBUGPlatformFreeFileMemory) { munmap(Memory, MemorySize); @@ -754,7 +810,9 @@ int main(int ArgC, char *Args[]) { XSetWindowAttributes WindowAttributes = {}; WindowAttributes.bit_gravity = StaticGravity; +#if HANDMADE_INTERNAL WindowAttributes.background_pixel = 0xFF00FF; +#endif WindowAttributes.colormap = XCreateColormap(DisplayHandle, RootWindow, WindowVisualInfo.visual, AllocNone); WindowAttributes.event_mask = (StructureNotifyMask | KeyPressMask | KeyReleaseMask | @@ -805,6 +863,7 @@ int main(int ArgC, char *Args[]) GameMemory.DEBUGPlatformReadEntireFile = DEBUGPlatformReadEntireFile; GameMemory.DEBUGPlatformFreeFileMemory = DEBUGPlatformFreeFileMemory; GameMemory.DEBUGPlatformWriteEntireFile = DEBUGPlatformWriteEntireFile; + GameMemory.PlatformRunCommandAndGetOutput = PlatformRunCommandAndGetOutput; #if HANDMADE_INTERNAL void *BaseAddress = (void *)Terabytes(2); -- cgit v1.2.3