2

One of the Units of Functionality that POSIX states an OS needs to provide to be POSIX compliant is POSIX_C_LANG_SUPPORT. Basically this is the whole C Standard Library with some more things.

My question is simple: developers of POSIX compliant OSes usually just download an open source version of C Standard Library (e.g. glib or uClibc) and adapt it to fit POSIX or they implement everything from scratch? Is there any advantage in rewriting the C Library instead of just picking one of the very known implementations and adjust it to my needs?

Brett Hale
  • 21,653
  • 2
  • 61
  • 90
  • Have a look at the C library on your target platform and see where it originates. This is usually well documented for copyright reasons. – tadman Mar 21 '18 at 21:50
  • 2
    And rarely, if ever (for practical reasons), rewritten from scratch. There is no advantage to rewriting -- the libraries available have years of testing -- you can't rewrite and expect to avoid the years it takes to fully bugfix a complex library while keeping track of all updates and changes on your own. – David C. Rankin Mar 21 '18 at 21:53
  • Since POSIX compatibility is so widely desired, I suspect that most C library implementors ensure that they're compliant to begin with, so OS developers don't need to do much. – Barmar Mar 21 '18 at 21:59
  • **Counterpoint**: Look at [musl-libc](https://www.musl-libc.org/). While not technically written from scratch, (most maths, or *libm*, parts of C libraries are re-used), sometimes a fresh start with - importantly - *modern* dev tools and compilers is worth it. You should investigate `musl` for your needs - it's clean, efficient, and already forms the basis of some distributions and embedded projects. I hope to see it refined and more widely adopted. – Brett Hale Mar 22 '18 at 00:35
  • *an open source version of C Standard Library*, well proprietary will fit as well. – Jean-Baptiste Yunès Mar 28 '18 at 08:20

2 Answers2

1

Really, it is done in the inverse way.

We have different Unix versions: two main families: SystemV and BSD, different manufacturers, and so there was a need to standardize. US government wanted also standardized programs, so POSIX (version 1) was created, by standardizing OS interfaces (a step further than just C standard).

Windows NT is also POSIX (version 1) compatible, just because government wanted standardized tools. So POSIX was designed very very broad.

Then with time, there were need to standardize some more Unix (and similar) systems. Not as just one system, one API, but as common API, and so programs (e.g. GUI libraries or databases) could eventually use extension, but also make sure that program that follow the standard works on compatible system.

This was SUS (Single Unix Specification). This required a UNIX like system (unlike POSIX 1).

Then POSIX became not so important: application that in theory could work on all POSIX systems didn't really work on POSIX Windows.

So the new version of POSIX merged old POSIX plus SUS plus new useful function missing in SUS.

Now Linux is important, so Linux implementations (e.g. glibc) is taken into account when updating POSIX. You will see in the mailing list, that POSIX is defined by "vendors" of different Unix and similar systems.

So, it is not that operating systems extend POSIX, it is just that POSIX takes the most useful and standard options from different OS. It creates new interfaces just when existing interfaces are so incompatible, that by standardizing, it will break existing programs.

For the "second" question: when you develop a new operating system, you choose what way to go. Usually it is just derivation and fork (and distributions): again from the two Unix families, of just deriving Linuxes from RedHat or Debian). Sometime system is build from scratch, because of the design. Kernel provides most of system calls, so e.g. glibc needs a lot of systemcall (given by kernel) implemented in a similar way as POSIX. Glibc is not complete. Note: early Linux distributions used other libraries. GLibc was also written from scratch.

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
0

Well, we are all dwarves standing on the shoulders of giants.

Writing a new OS is a huge undertaking, so the wise one will re-use whatever (design, libraries, compilers, other software) they can. It's still in all likelyhood far too much work, so why make it even harder by rewriting everything from scratch?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118