Skip to content

Add OpenBSD support via libmpq abstraction layer - #9

Merged
corepunch merged 6 commits into
mainfrom
copilot/compile-with-libmpq-openbsd
Jan 8, 2026
Merged

corepunch merged 6 commits into
mainfrom
copilot/compile-with-libmpq-openbsd

Conversation

Copilot AI commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

OpenBSD lacks StormLib support but provides libmpq 0.4.2. This PR adds a compile-time MPQ library abstraction to enable OpenBSD builds.

Changes

  • MPQ Abstraction Layer (src/common/mpq_adapter.{h,c})

    • Detects OpenBSD via __OpenBSD__ and uses libmpq; defaults to StormLib elsewhere
    • Wraps StormLib API: SFileOpenArchive, SFileReadFile, SFileGetFileSize, etc.
    • Caches file data in memory on open (libmpq reads entire files, no random access)
    • File enumeration not supported with libmpq (returns NULL from SFileFindFirstFile)
  • Build System

    • Makefile: Sets MPQ_LIB=-lmpq on OpenBSD, -lstorm otherwise
    • premake5.lua: Adds BSD platform config with /usr/local/{include,lib} paths
  • Type Definitions

    • Added missing LPVOID typedef to shared.h
    • Replaced #include <StormLib.h> with #include "mpq_adapter.h" in 6 files
  • Security

    • Overflow checks in malloc sizing and file pointer arithmetic
    • Bounds validation for buffer operations
    • Safe casting between off_t, DWORD, and size types

Example Usage

// Same code works on both platforms
HANDLE archive;
SFileOpenArchive("War3.mpq", 0, 0, &archive);

HANDLE file;
SFileOpenFileEx(archive, "war3map.w3e", SFILE_OPEN_FROM_MPQ, &file);

DWORD size = SFileGetFileSize(file, NULL);
unsigned char* buffer = malloc(size);
SFileReadFile(file, buffer, size, NULL, NULL);

Limitations

File enumeration APIs return NULL on libmpq. Features requiring MPQ file listing may need alternative implementation or will be unavailable on OpenBSD.

Original prompt

This section details on the original issue you should resolve

<issue_title>Can I compile it on OpenBSD?</issue_title>
<issue_description>OpenBSD has:
SDL2: 2.32.8
libmpq: 0.4.2

I don't think StormLIB supports OpenBSD yet, can I use libmpq instead?</issue_description>

<agent_instructions>Check if it's possible to compile using libmpq, update the code with #ifdef for OpenBSD</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@corepunch I think it would take some #ifdef-ing but should be possible!

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits January 8, 2026 16:19
Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
@corepunch
corepunch marked this pull request as ready for review January 8, 2026 16:40
Copilot AI changed the title [WIP] Check compilation support for OpenBSD using libmpq Add OpenBSD support via libmpq abstraction layer Jan 8, 2026
Copilot AI requested a review from corepunch January 8, 2026 16:51
@corepunch
corepunch merged commit 8775d17 into main Jan 8, 2026
1 check passed
@corepunch
corepunch deleted the copilot/compile-with-libmpq-openbsd branch January 8, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can I compile it on OpenBSD?

2 participants