Build para Windows 2000: make exe-w2k (i686 + shims do uniwin)

A build de 32 bits normal nao abre no Windows 2000: o SDL2_ttf do MSYS2
puxa harfbuzz -> glib (threadpool do Vista, funcoes _s do CRT) e ate a
dwrite.dll; o msvcrt.dll antigo nao entende %zu/%lld no printf; e um
programa de janela pode nao ter stdout.

- FreeType e SDL2_ttf do codigo-fonte, estaticas e sem harfbuzz
  (packaging/windows/w2k_ttf.sh).
- O .exe e as DLLs tem os imports trocados pelos shims do uniwin, que vem
  junto no pacote; w2k_check.py confere cada funcao contra as DLLs reais do
  Windows 2000 e para a build se faltar alguma.
- -D__USE_MINGW_ANSI_STDIO=1 para o printf do proprio mingw.
- main.c reabre stdout/stderr em NUL quando nao existem; o editor captura o
  escreva por fileno(stdout), nao STDOUT_FILENO.
- compat: tmpfile na pasta temporaria do usuario e gethostname por
  GetComputerNameA.

Testado na VM com Windows 2000 pelo MCP: o programa roda e o escreva chega
na saida.
This commit is contained in:
mguinhos committed 2026-10-27 03:48:05 -03:00
1 parent e1d1d65eaa
commit 84513080ab
9 files changed
+244 -9

No files matched your search

+15
View File
@@ -108,6 +108,21 @@ int tb_win_fclose(FILE* f) {
return fclose(f);
}
#undef gethostname
int tb_win_gethostname(char* name, size_t len) {
DWORD n = (DWORD)len;
return GetComputerNameA(name, &n) ? 0 : -1;
}
/* tmpfile na pasta temporaria do usuario; "D" = o msvcrt apaga ao fechar */
FILE* tb_win_tmpfile(void) {
char dir[MAX_PATH], path[MAX_PATH];
if (!GetTempPathA(sizeof(dir), dir) || !GetTempFileNameA(dir, "tbt", 0, path)) return NULL;
FILE* f = fopen(path, "w+bD");
if (!f) DeleteFileA(path);
return f;
}
/* -- dlfcn ------------------------------------------------------------- */
static char s_dl_err[256];
+7
View File
@@ -11,7 +11,11 @@
* setenv / unsetenv -> _putenv_s
* readlink("/proc/self/exe") -> GetModuleFileName (com '/')
* strndup, getline
* tb_win_gethostname -> GetComputerNameA (o gethostname do Winsock
* pede WSAStartup e tem outra convencao no i686)
* open_memstream -> arquivo temporario; o fclose devolve o texto
* tmpfile -> na pasta temporaria do usuario (o do msvcrt
* cria na raiz do disco e pode falhar)
*/
#ifndef TB_WIN_COMPAT_H
#define TB_WIN_COMPAT_H
@@ -26,10 +30,12 @@ int tb_win_setenv(const char* k, const char* v, int over);
int tb_win_unsetenv(const char* k);
ssize_t tb_win_readlink(const char* path, char* buf, size_t cap);
char* tb_win_strndup(const char* s, size_t n);
int tb_win_gethostname(char* name, size_t len);
#include <stdio.h>
ssize_t tb_win_getline(char** line, size_t* cap, FILE* f);
FILE* tb_win_open_memstream(char** buf, size_t* len);
int tb_win_fclose(FILE* f);
FILE* tb_win_tmpfile(void);
/* Os headers do sistema antes das macros: a declaracao original fica intacta */
#include <direct.h>
@@ -51,6 +57,7 @@ int tb_win_fclose(FILE* f);
#define getline(l, c, f) tb_win_getline((l), (c), (f))
#define open_memstream(b, n) tb_win_open_memstream((b), (n))
#define fclose(f) tb_win_fclose(f)
#define tmpfile() tb_win_tmpfile()
#endif /* _WIN32 */
#endif