`errno` is another relic that needs to die yesterday.
`errno` is another relic that needs to die yesterday.
https://utcc.utoronto.ca/~cks/space/blog/programming/Go116Op...
In this particular case, the Windows APIs have neither getaddrinfo() nor getenv(); and the closest equivalent GetEnvironmentVariableW is perfectly thread-safe. Microsoft additionally has a C runtime (msvcrt) providing functions like getenv(), but this is much less fundamental than it is on other system. Every program is supposed to ship its own copy of the C runtime, it's not officially part of Windows! And it's perfectly possible for multiple different copies of the C runtime to be loaded into the same Windows process. And since *environ is a variable defined by the C runtime, there's a different copy for each C runtime...
https://learn.microsoft.com/en-us/cpp/windows/universal-crt-...
Doing raw syscalls without ntdll is also possible, but windows syscall numbers change on essentially every release, so you’d end up with something that only works on your windows version.
[1] golang official image 1.20.4 to 1.20.5 went from Debian 11 to 12 base. Always use the -(debian version) tags.
Re-implementing system capabilities is fine and all as long as you support common use cases properly, which Golang does not.
I mostly like C as a language, but between the security concerns and the tooling concerns (and the community's zealous devotion to ignoring these very real problems) I'm really excited for its increasing marginalization. Unfortunately, it's not being marginalized in favor of "a better C", but rather every ecosystem is rewriting the same stuff from scratch which seems like a bit of a bummer (but still better than depending on C).
You should see other libraries. At least glibc does not require meson, cmake and ninja.
ok, i will bite: what is the problem with it ?
Linus Torvalds on errno: https://yarchive.net/comp/linux/errno.html
yes, he argues against its usage in the KERNEL.
As for why shared global mutable state is (generally) bad, see: https://softwareengineering.stackexchange.com/questions/1481...
`man 3 errno` on my Linux system even has a note calling out a common failure pattern. Can you spot the problem?
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ... }
}Returning a"Result" struct doubles the size. This is one less register to use.
Exception handling is even more invasive.
They are great for high(-er) level language, but less prefect on lower level where performance is critical.
EDIT: Linux kernel use negative return value for error. It's good and efficient when it work. But it is not always an option when you need the full register width
Linux even shows you a path, yet you reject it for reasons that don't seem compelling to me.
One less register right before and after returns doesn't sound like a big problem, especially with 16+ registers.
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ... }
}
sure, the issue is that `somecall(...)` might have altered `errno` through 'acts-of-omission-or-comission' :o)fwiw, posix has updated its definition to pretty much say that 'value of errno in one thread is not affected by assignments to it by another'. this has been the case since at least a decade-and-a-half (iirc), which in internet years would positively be in the pleistocenic era :o)
so, i am not sure i really appreciate 'the shared-global-mutable-state' argument above. thanks !
my typical usage for such scenarios i.e. when i know that callee might alter errno etc. is to
int save_errno = errno;
do_foo(...);
if (errno == ...) {
...
}
wrapping libc into something that (maybe) does better seems like such a sisyphean task to me.Notice how this entire thread was started by someone asking why errno was problematic. This is just about understanding.
yes, you are absolutely right. this is just about understanding and how easy it is to miss what is hidden just one-level away.
Environment variables like LD_PRELOAD should never ever be available in production.
I totally understand why the muslc developers kinda freaked out and started their own standard library.
For example I have vision issue and without reshade filter I would be unable to play a great deal of games.
Now that is also an attack vector, that's for sure, but you cannot go ax features willy nilly just because you don't see value in them.
The Unix kernel (both Linux, BSD, and Solaris) already had much of what's needed, say, 30 years ago, but nobody saw it as such a burning necessity (likely except Solaris which eventually developed Zones).
But today every god damn UI program needs an internet connection to phone home and execute remote code. This is the actual problem which must be fixed.
> Err no
Not sure if you are trolling