Refactor: extract platform abstraction for subprocess spawning

Move all Unix-specific syscalls (fork, execvp, waitpid, strerror, /tmp)
into a platform layer so the same spectrogram.c can target Windows
(CreateProcess) and WebAssembly (stubs). Key changes:

- src/platform.h: public API with spawn handle, error codes, path helpers
- src/platform_linux.c: fork/execvp implementation, /tmp, strerror
- src/platform_win32.c: CreateProcess implementation, temp dir lookup
- src/platform_web.c: stub implementations (no subprocess support on web)
- src/spectrogram.c: consume only platform.h; replace pid_t/fork/execvp
  with Platform_SpawnChild/WaitForChild; use Platform_GetTempDir() for
  /tmp path; replace strdup with malloc/memcpy for portability
- Build: add platform_*.c to gmake, Premake, and build_web.sh
This commit is contained in:
2026-05-14 18:16:21 -07:00
parent e42554e6fd
commit b6942d8577
8 changed files with 472 additions and 28 deletions
+6
View File
@@ -119,7 +119,9 @@ GENERATED :=
OBJECTS :=
GENERATED += $(OBJDIR)/spectrogram.o
GENERATED += $(OBJDIR)/platform_linux.o
OBJECTS += $(OBJDIR)/spectrogram.o
OBJECTS += $(OBJDIR)/platform_linux.o
# Rules
# #############################################
@@ -187,6 +189,10 @@ $(OBJDIR)/spectrogram.o: src/spectrogram.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/platform_linux.o: src/platform_linux.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
-include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH))
-include $(PCH_PLACEHOLDER).d