A shim library providing POSIX-compatible APIs on top of Classic Mac OS Toolbox calls, enabling modern Unix software to compile and run on vintage Macintosh computers.
| Platform | CPU | OS Version | Toolchain | Status |
|---|---|---|---|---|
| 68K Mac | 68020+ | System 7.0 - 8.1 | Retro68 (m68k) | Supported |
| PowerPC Mac | G3/G4/G5 | Mac OS 7.5.2 - 9.2.2 | Retro68 (ppc) | Primary |
- File I/O:
open,read,write,close,lseek,stat,fstat,unlink - Directories:
opendir,readdir,closedir,mkdir,rmdir,chdir,getcwd - Path Translation: Automatic POSIX β Mac path conversion
- Sockets: BSD socket API via Open Transport (Mac OS 8.6+)
- Threads: POSIX threads via Thread Manager
- Signals: Emulated signal handling via Deferred Tasks
- Time:
time,localtime,strftime,gettimeofday - Environment:
getenv,setenv,unsetenv
βββββββββββββββββββββββββββββββββββββββ
β POSIX Application (SSH, etc.) β
βββββββββββββββββββββββββββββββββββββββ€
β libposix9.a β
β βββ posix9_file.c (file I/O) β
β βββ posix9_dir.c (directories)β
β βββ posix9_path.c (path xlat) β
β βββ posix9_thread.c (pthreads) β
β βββ posix9_signal.c (signals) β
β βββ posix9_socket.c (networking) β
β βββ posix9_misc.c (utilities) β
βββββββββββββββββββββββββββββββββββββββ€
β Mac OS Toolbox β
β βββ File Manager (FSSpec/HFS) β
β βββ Open Transport (TCP/IP) β
β βββ Thread Manager β
β βββ Time Manager β
βββββββββββββββββββββββββββββββββββββββ
POSIX9 automatically converts between POSIX and Mac paths:
| POSIX Path | Mac Path |
|---|---|
/ |
Volume root (default volume) |
/Volumes/Macintosh HD/Users/scott |
Macintosh HD:Users:scott |
./foo/bar |
:foo:bar |
../parent |
::parent |
- Retro68 Cross-Compiler: https://github.com/autc04/Retro68
# Clone Retro68
git clone https://github.com/autc04/Retro68.git
cd Retro68
# Build for both 68K and PowerPC
mkdir build && cd build
../build-toolchain.bash --ppc-only # PowerPC only (faster)
# OR
../build-toolchain.bash # Full build (68K + PPC)cd posix9
./build-ppc.shThis creates build-ppc/libposix9.a (~50KB) with the following modules:
posix9_dir.o- Directory operationsposix9_file.o- File I/Oposix9_path.o- Path translationposix9_signal.o- Signal emulationposix9_thread.o- POSIX threads
cd posix9
./build-68k.sh# Set environment variables
export RETRO68_PREFIX="$HOME/Retro68/build/toolchain"
export POSIX9_LIB="/path/to/posix9/build-ppc/libposix9.a"
export POSIX9_INC="/path/to/posix9/include"
# Compile (PowerPC)
$RETRO68_PREFIX/bin/powerpc-apple-macos-gcc \
-O2 \
-I"$POSIX9_INC" \
-I"$POSIX9_INC/mac_stubs" \
-c myapp.c -o myapp.o
# Link
$RETRO68_PREFIX/bin/powerpc-apple-macos-gcc \
myapp.o "$POSIX9_LIB" -o myapp.xcoff
# Convert to PEF (Mac executable)
$RETRO68_PREFIX/bin/MakePEF myapp.xcoff -o myapp.pef#include "posix9.h"
int fd = open("/path/to/file", O_RDONLY);
char buf[1024];
ssize_t n = read(fd, buf, sizeof(buf));
close(fd);
// Create file
fd = open("/new/file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
write(fd, "Hello Mac OS 9!
", 16);
close(fd);DIR *dir = opendir("/");
struct dirent *ent;
while ((ent = readdir(dir)) != NULL) {
printf("%s
", ent->d_name);
}
closedir(dir);
mkdir("/new/directory", 0755);
chdir("/some/path");
getcwd(buf, sizeof(buf));char mac_path[256];
posix9_path_to_mac("/Volumes/Macintosh HD/file.txt", mac_path, sizeof(mac_path));
// Result: "Macintosh HD:file.txt"
char posix_path[256];
posix9_path_from_mac("Macintosh HD:Users:scott", posix_path, sizeof(posix_path));
// Result: "/Volumes/Macintosh HD/Users/scott"int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(22);
addr.sin_addr.s_addr = inet_addr("192.168.1.1");
connect(sock, (struct sockaddr*)&addr, sizeof(addr));
send(sock, "Hello
", 6, 0);
close(sock);#include "posix9.h"
void *thread_func(void *arg) {
// Thread code
return NULL;
}
pthread_t tid;
pthread_create(&tid, NULL, thread_func, NULL);
pthread_join(tid, NULL);Mac OS 9 has no true process model. These functions are stubbed:
fork()- Returns -1 withENOSYSexec*()- Launches separate app (doesn't replace current process)getpid()- Always returns 1
- Sockets require Open Transport (Mac OS 8.6+)
- System 7 has no TCP/IP stack by default
- MacTCP is not supported
Signals are emulated via polling. Some behaviors differ from Unix:
- No async signal delivery (polled in event loop)
SIGKILL/SIGSTOPnot implemented
- No symbolic links (HFS/HFS+ limitation)
- 31-character filename limit (HFS)
- No file permissions (mode is ignored)
posix9/
βββ include/
β βββ posix9.h # Main header (include this)
β βββ posix9/
β β βββ types.h # POSIX types
β β βββ errno.h # Error codes
β β βββ socket.h # Socket definitions
β β βββ pthread.h # Thread definitions
β β βββ signal.h # Signal definitions
β β βββ time.h # Time definitions
β β βββ unistd.h # Misc definitions
β βββ mac_stubs/
β βββ Multiverse.h # Retro68 Mac API
β βββ MacCompat.h # Missing Mac definitions
β βββ Timer.h # Time Manager stubs
β βββ Threads.h # Thread Manager stubs
β βββ OpenTransport.h # OT stubs
βββ src/
β βββ posix9_file.c # File operations
β βββ posix9_dir.c # Directory operations
β βββ posix9_path.c # Path translation
β βββ posix9_thread.c # POSIX threads
β βββ posix9_signal.c # Signal emulation
β βββ posix9_socket.c # BSD sockets
β βββ posix9_misc.c # Misc utilities
βββ test/
β βββ posix9_test.c # Test program
β βββ build-test.sh # Test build script
βββ build-ppc.sh # PowerPC build script
βββ build-68k.sh # 68K build script
βββ README.md # This file
- Build the test program:
cd test
./build-test.sh-
Transfer
POSIX9 Testto your Mac via:- Floppy disk
- Network (AppleTalk/AFP)
- Serial connection (Zterm)
- Compact Flash adapter
-
Run on Mac OS 9 - creates
POSIX9 Test Logfile with results
- GUSI - Grand Unified Socket Interface by Matthias Neeracher
- MachTen - Full BSD on Mac OS (commercial, discontinued)
- A/UX - Apple's Unix for 68K Macs
- MPW POSIX - Partial POSIX in Macintosh Programmer's Workshop
- Retro68 - Cross-compiler for Classic Mac OS
POSIX9 was created to port:
- Dropbear SSH - Lightweight SSH server
- curl/wget - HTTP clients
- Python 2.x - Scripting language
- Various Unix utilities
MIT License
Contributions welcome! Areas needing work:
- Complete
posix9_socket.cOpen Transport implementation - Fix
posix9_misc.ctype conflicts with newlib - Add 68K-specific optimizations
- Test on real System 7 hardware
- Port more Unix software
| Module | PPC | 68K | Notes |
|---|---|---|---|
| posix9_file.c | OK | OK | File operations |
| posix9_dir.c | OK | OK | Directory operations |
| posix9_path.c | OK | OK | Path translation |
| posix9_signal.c | OK | OK | Signal emulation |
| posix9_thread.c | OK | OK | POSIX threads |
| posix9_socket.c | WIP | WIP | Needs OT constants |
| posix9_misc.c | WIP | WIP | Type conflicts |
Current library size: ~50KB (5 modules)