Skip to content

libc: Add POSIX headers & stubs - #773

Open
ReenigneArcher wants to merge 1 commit into
XboxDev:masterfrom
ReenigneArcher:libc-moonlight
Open

libc: Add POSIX headers & stubs#773
ReenigneArcher wants to merge 1 commit into
XboxDev:masterfrom
ReenigneArcher:libc-moonlight

Conversation

@ReenigneArcher

Copy link
Copy Markdown
Contributor

@glebm

glebm commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This stubs out a bunch of functions like opendir/readdir/closedir/read/write/lseek. Even if a program using these functions compiles, it probably won't work. Probably not a good idea to pretend functions are available when they're not?

@ReenigneArcher

Copy link
Copy Markdown
Contributor Author

Yet it's working here -> https://github.com/LizardByte/Moonlight-XboxOG

@glebm

glebm commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

I guess it's working for you because your program doesn't call these functions (for sure, never? then why are they there?).

The main issue is that programs that detect availability of these functions and use them when available would break in a bad way.

@ReenigneArcher

Copy link
Copy Markdown
Contributor Author

Correct, because moonlight-common-c needs just a tiny part of OpenSSL, not every possible thing it can do. Typically OpenSSL is just available from the distro or package managers so for Moonlight no one ever had to worry about compiling it manually... and of course you can't expect a project like that to care about supporting NXDK.

@glebm

glebm commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

nxdk implements many Windows APIs, it's basically a Windows platform with API level similar to Windows 9x. Consider the ossl_time_now function from OpenSSL:

https://github.com/openssl/openssl/blob/33482fbddcf137dde9bd84ae12f2f02cbc358c78/crypto/time.c#L15-L49

With #if defined(_WIN32), it uses GetSystemTime and SystemTimeToFileTime, both of which are availble in nxdk.
On the other hand, the gettimeofday stub here will result in the function always returning 0 time, possibly resulting in all kinds of shenanigans.

Similarly for LP_find_file. While it uses opendir on POSIX, which is stubbed out in this PR, in the Windows implementation (https://github.com/openssl/openssl/blame/master/crypto/LPdir_win.c) it uses FindFirstFile and friends which are already available in nxdk. Here, you will need to add a condition to not always #define LP_MULTIBYTE_AVAILABLE in https://github.com/openssl/openssl/blame/master/crypto/LPdir_win32.c (e.g. by making it a configure option).

You'd have better luck starting from the Windows route and adding the missing APIs there.

This might still require patches, though it's sometimes possible to upstream them. E.g. I was able to upstream this option to libfmt because Windows 9x also lacks the corresponding API: fmtlib/fmt#3636

I'm not opposed to a POSIX compatibility layer to make porting easier but only if it's actually working and not stubbed out. I'm not a maintainer of nxdk, just a user, but it'd be very frustrating to use an SDK that declares POSIX functions without actually implementing them.

@ReenigneArcher

Copy link
Copy Markdown
Contributor Author

NXDK implements many Windows APIs, it's basically a Windows platform with API level similar to Windows 9x.

Unfortunately, a very incomplete Windows API. First missing thing I found when going down that route was #453

This was the easier path to get my project working.

I can look into trying to complete some of the stubs in the next few weeks, but I don't want to waste time on it if a maintainer isn't going to review or consider this.

@antonic901

antonic901 commented Jul 30, 2026

Copy link
Copy Markdown

There is nxio from astarivi who is helping me with XBMC development. He wrote that because we were unable to compile curl in NXDK. I don't know how much it's completed, but it was enough to compile and get curl woking NXDK.

@dracc

dracc commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

There is nxio from astarivi who is helping me with XBMC development. He wrote that because we were unable to compile curl in NXDK. I don't know how much it's completed, but it was enough to compile and get curl woking NXDK.

Neat! Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants