{"id":16987433,"url":"https://github.com/stanislaw/posix-macos-addons","last_synced_at":"2025-04-12T03:31:54.567Z","repository":{"id":46514946,"uuid":"231221634","full_name":"stanislaw/posix-macos-addons","owner":"stanislaw","description":"Some missing bits of POSIX for macOS.","archived":false,"fork":false,"pushed_at":"2021-10-06T16:38:46.000Z","size":442,"stargazers_count":16,"open_issues_count":9,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-31T09:36:49.386Z","etag":null,"topics":["macos","posix"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stanislaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-01T13:45:39.000Z","updated_at":"2024-10-01T02:33:56.000Z","dependencies_parsed_at":"2022-09-10T00:30:57.822Z","dependency_job_id":null,"html_url":"https://github.com/stanislaw/posix-macos-addons","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislaw%2Fposix-macos-addons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislaw%2Fposix-macos-addons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislaw%2Fposix-macos-addons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanislaw%2Fposix-macos-addons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanislaw","download_url":"https://codeload.github.com/stanislaw/posix-macos-addons/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223494313,"owners_count":17154526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macos","posix"],"created_at":"2024-10-14T02:49:42.246Z","updated_at":"2024-11-07T10:04:25.573Z","avatar_url":"https://github.com/stanislaw.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# POSIX addons for macOS\n\nThis is a collection of the POSIX functions which are not available on macOS.\n\nThe status of the code: hacky, experimental.\n\n![](https://github.com/stanislaw/posix-macos-addons/workflows/Tests%20on%20macOS/badge.svg?branch=main)\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Disclaimer](#disclaimer)\n- [Background](#background)\n- [Founding Principles](#founding-principles)\n- [Contents](#contents)\n  - [mqueue (POSIX message queues)](#mqueue-posix-message-queues)\n  - [pthread](#pthread)\n  - [semaphore](#semaphore)\n  - [time](#time)\n  - [timer](#timer)\n- [Known experimental uses](#known-experimental-uses)\n- [Not implemented yet](#not-implemented-yet)\n- [Similar repositories](#similar-repositories)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Disclaimer\n\nPlease note that the exact implementation of the same functionality for every\nPOSIX function is not always possible because certain bigger parts simply do not\nexist on macOS and implementing them would be a much serious effort. The outcome\nof this fact is that most of the functions in this repository are\n**emulations**: the code follows all or the most of the original API and tries\nto do the job like specified on the Man pages but there is no guarantee that you\nget a 100% Linux behavior. Please check the Contents for the specific details\nbelow.\n\n## Background\n\nThere are two opinions on the internet:\n\n1. macOS should match Linux 100% so if something POSIX exists on Linux it should\n   be available on macOS.\n\n2. macOS has enough of POSIX. The uninimplemented parts are actually POSIX\n   extensions so it is ok to not have them.\n\nWe can agree or disagree with either or both of these points of view but\nmeanwhile we also need to run some Linux software on macOS and sometimes at\nwork.\n\nThe idea behind this repository is to finally have a single place for these\nmarginal POSIX functions and the hope is that they should be a good-enough\nreplacement for their real POSIX equivalents.\n\n## Founding Principles\n\n- This repo is based on the\n  [Cunningham's Law](https://en.wikipedia.org/wiki/Ward_Cunningham#Cunningham%27s_Law):\n  the code in this repository can be wrong but at least it is there which makes\n  it available for use and further improvement.\n\n- Every port should have at least basic test code coverage but it would be great\n  to have tests that ensure the exact behavior of the code on macOS compared to\n  the real POSIX equivalents.\n\n- The code is located in the `src` folder with every port in a subfolder. It\n  should be possible to use both full `posix-macos-addons` CMake project and each\n  and every of the sub-folders standalone.\n\n## Contents\n\n### mqueue (POSIX message queues)\n\nThe mqueue does not exist on macOS.\n\nThe implementation is adapted from the book\n[\"UNIX Network Programming, Volume 2\"](http://www.kohala.com/start/unpv22e/unpv22e.html)\nby W. Richard Stevens. The book provides source code where there is an\nimplementation based on the memory-mapped files written by the author. The code\nwas adapted to macOS and all of the original author's test programs were\nconverted to a Google Test suite.\n\n**Status:** the code seems to work, but needs some further cleanups.\n\n#### Known limitations\n\n1. this implementation uses `sigqueue` for asynchronous notifications via\n   `mq_notify`. `sigqueue` and the real-time signals functionality is not\n   available on macOS. This is not a problem if you want to use `mqueue` with\n   synchronous calls only.\n\n2. The Linux implementation uses a virtual file system while memory-mapped files\n   on macOS are created in a user's file system. This means that the naming\n   conventions are different: for example you cannot create mqueue in your root\n   directory like `/queue-1`.\n\n### pthread\n\n`pthread_setschedprio` function is implemented as a call to the\n`pthread_setschedparam` function which is available on macOS.\n\n### semaphore\n\nUnnamed semaphores: `sem_init`, `sem_wait`, `sem_post`, `sem_destroy` are\ndeprecated on macOS. Additionally, the `sem_timedwait` does not exist.\n\nThere are two implementations: `mac_sem_*` and `mac_sem2_*`.\n\nThe `mac_sem_*` implementation is based on `pthread_mutex` and `pthread_cond`\nand is taken from this StackOverflow thread with minor adaptations:\n[POSIX Semaphores on Mac OS X: sem_timedwait alternative](https://stackoverflow.com/a/48778462/598057).\n\nThe `mac_sem2_*` implementation is based on GCD semaphores.\n\n#### Known issue\n\nGCD semaphores crash with `BUG IN CLIENT OF LIBDISPATCH` when you destroy a\nsemaphore which is being waited on this is why there is a debug version of the\nsecond implementation: `mac_sem2_debug_*` where there is a layer that tracks how\nmany times a certain semaphore was waited/posted to release the semaphore\nmanually when it gets destroyed. This behavior was needed to make one important\nproject's tests to pass without crashing.\n\n### time\n\nThe `clock_nanosleep` is implemented as a call to `nanosleep`. The code is\ninspired by this implementation:\n[btest-opensource/timing_mach.h](https://github.com/samm-git/btest-opensource/blob/236d9a79b03c5c696832a1f5134c792a7ecb3ef1/timing_mach.h).\n\nPossible issue:\n[nasa/osal#337](https://github.com/nasa/osal/issues/337#issuecomment-570807421).\n\n### timer\n\nA rather limited implementation based on the GCD timers.\n\nThe implementation has an additional method `timer_poll` to simulate polling for\nthe timer's ticks to substitute waiting on `sigwait` to receive a signal from a\ntimer when configured with `SIGEV_SIGNAL`.\n\n## Known experimental uses\n\nThis code is being tested as part of the experimental macOS ports of the\nfollowing projects:\n\n- [nasa/osal](https://github.com/nasa/osal)\n\n- [DLR-RY/OUTPOST](https://github.com/DLR-RY/outpost-core)\n\n## Similar repositories\n\n- [libUnixToOSX](https://github.com/cooljeanius/libUnixToOSX)\n- https://github.com/ChisholmKyle/PosixMachTiming\n- https://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x\n- https://speakerdeck.com/jj1bdx/how-i-discover-a-working-implementation-of-clock-nanosleep-for-macos-in-cpan-time-hires?slide=8\n- [macports-legacy-support](https://github.com/macports/macports-legacy-support)\n\nThese are similar repositories. We haven't checked these implementations yet,\nthere might be better implementations hiding.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislaw%2Fposix-macos-addons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanislaw%2Fposix-macos-addons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanislaw%2Fposix-macos-addons/lists"}