Well, if you want to be pedantic, I’ll entertain you a bit more.
You see, C and Unix were “born” together. So sometimes, POSIX intertwines them in weird ways. In this case, getlogin is declared in unistd.h because it’s part of the Unix standard API, however the POSIX standard states that it must be implemented in libc. So the POSIX compliant way to getlogin is to call into libc, which doesn’t need to be glibc, you could use musl and avoid the GNU dependencies.
If rust’s stdlib were to offer a getlogin function, the proper approach would be to still call libc.
It’s like if on windows you were to call into Win32 to getuser, except on *nix it’s the same file as libc.
If you want to replace the getlogin implementation, the POSIX compliant place to do it is not in coreutils but in libc, like the aforementioned musl library does.
So the key here is that getlogin is not art of the c system API. It is actually part of the POSIX APIs, it is just “located” inside of libc, which by the way, does not need to be GNU if you are concerned with uutils’ philosophy.
I don’t think I do want to be pedantic but, to be explicitly clear, the philosphy I’m associating with uutils is capured by the “rewritie it in rust” mantra, so whether or not their posix compliant interface uses GNU code is beside the point.
More importantly, if their goal was a posix compliant api, then I’d have assumed they would have included that in their repo description, or even called the project posix.rs; but they didn’t.
What’s more is that the rust standard library isn’t equivalent to that of C, so it would still make sense that for a project whose goal was, or has simply become, to replace a C codebase would offer a safe C alternative to its dependencies.
But maybe that’s their next step; an internal library offering enough of a posix api to avoid surprises like these.
Not at all. I would not expect any riir project to reimplement the entire stack in rust.
This is not calling a random C dependency. This is literally calling the OS’s API. Literally there’s just this and the kernel.
As you said its goal is to rewrite a C codebase. The C codebase is coreutils. The correct way to getuser is to use the OS’s API, which happens to be inside libc.so, which has nothing to do with coreutils, it’s an entirely different codebase. End of the story.
The OS’s API needs to be exposed as a c library, because c is the only language that can be imported from any other language. If you were to rewrite it in rust, it would use extern'C' and it could not be any other way. And uutils would still import it from libc.
Maybe one day we’ll see a rust rewrite of libc (tho it doesn’t make much sense), but this has nothing to do with uutils.
If you are asking for a rust wrapper around the correct way to getuser, you have literally posted it. You can find it in uutils.
Also, being compliant is just being compliant. I wouldn’t expect it to be called something like POSIX.rs unless it were implementing every part of POSIX. Which is clearly not what we have here. Or are you suggesting that bash should be called POSIX.c, because it’s in c and it’s POSIX compliant?
Well, if you want to be pedantic, I’ll entertain you a bit more.
You see, C and Unix were “born” together. So sometimes, POSIX intertwines them in weird ways. In this case, getlogin is declared in unistd.h because it’s part of the Unix standard API, however the POSIX standard states that it must be implemented in libc. So the POSIX compliant way to getlogin is to call into libc, which doesn’t need to be glibc, you could use musl and avoid the GNU dependencies. If rust’s stdlib were to offer a getlogin function, the proper approach would be to still call libc. It’s like if on windows you were to call into Win32 to getuser, except on *nix it’s the same file as libc.
If you want to replace the getlogin implementation, the POSIX compliant place to do it is not in coreutils but in libc, like the aforementioned musl library does.
So the key here is that getlogin is not art of the c system API. It is actually part of the POSIX APIs, it is just “located” inside of libc, which by the way, does not need to be GNU if you are concerned with uutils’ philosophy.
I don’t think I do want to be pedantic but, to be explicitly clear, the philosphy I’m associating with uutils is capured by the “rewritie it in rust” mantra, so whether or not their posix compliant interface uses GNU code is beside the point.
More importantly, if their goal was a posix compliant api, then I’d have assumed they would have included that in their repo description, or even called the project posix.rs; but they didn’t. What’s more is that the rust standard library isn’t equivalent to that of C, so it would still make sense that for a project whose goal was, or has simply become, to replace a C codebase would offer a safe C alternative to its dependencies. But maybe that’s their next step; an internal library offering enough of a posix api to avoid surprises like these.
Not at all. I would not expect any riir project to reimplement the entire stack in rust. This is not calling a random C dependency. This is literally calling the OS’s API. Literally there’s just this and the kernel.
As you said its goal is to rewrite a C codebase. The C codebase is coreutils. The correct way to getuser is to use the OS’s API, which happens to be inside libc.so, which has nothing to do with coreutils, it’s an entirely different codebase. End of the story. The OS’s API needs to be exposed as a c library, because c is the only language that can be imported from any other language. If you were to rewrite it in rust, it would use
extern 'C'and it could not be any other way. And uutils would still import it from libc.Maybe one day we’ll see a rust rewrite of libc (tho it doesn’t make much sense), but this has nothing to do with uutils.
If you are asking for a rust wrapper around the correct way to getuser, you have literally posted it. You can find it in uutils.
Also, being compliant is just being compliant. I wouldn’t expect it to be called something like POSIX.rs unless it were implementing every part of POSIX. Which is clearly not what we have here. Or are you suggesting that bash should be called POSIX.c, because it’s in c and it’s POSIX compliant?