#Libc and std.os.system

1 messages · Page 1 of 1 (latest)

lime sequoia
#

I have a project (https://github.com/natecraddock/zf) that uses std.os.system in a few places. A recent change requires me to use exe.linkLibC(). Now I'm running into issues with missing constants in std.os.system on Linux. For example, std.os.system.ICRNL isn't found on Linux now.

I looked into this and found the switch in os.zig that sets system. The issue is std.c is missing some constants that were previously found in std.os.linux. I tried overriding std.os.system in my root source file as the comment suggests and ran into some more missing fields. So now I'm just manually using std.os.linux or std.c depending on my target. It feels a bit messy though.

I'm sure these issues are just due to the stdlib being a work in progress. Is there is a better or recommended way to approach fixing this?

eager moss
#

My understanding is that std will get reworked before 1.0, but my impression as to how it's meant to work now is that you're not generally expected to be reaching for platform-specific constants if you're using the std.os APIs, as they are supposed to be the cross-platform layer.
Alongside that, it may be of the opinion that if you link with libc, you want to use libc as the OS interface. BSDs force you to do this of course.
As a result, if you link libc, you do indeed have to reach into the OS-specific stuff in order to use stuff that is platform-specific.

As to how good of an idea this is, is a different question though 😄

#

But all of that is basically just me spitballing, ultimately.
Might be worth inquiring in #stdlib-devel about whether your usecase should be better supported.
My impression is that it amounts to "I want to use libc, but I also want to do platform-specific stuff" - which seems reasonable enough.
Possible that it should be redesigned a touch to better enable it.

lime sequoia
#

Thanks for replying! I figured it was probably just me misunderstanding the std.os layer, and that stdlib is still unfinished. I found a good enough solution for now, and in the future I probably won't need to link libc on linux after I redesign some things. If I can think of a good enough way to describe the issue though, I may ask in the #stdlib-devel channel