Hacker News new | ask | show | jobs
by db48x 32 days ago
It’s a side issue, but I’ve long thought that the kernel should duplicate every existing syscall that takes a null–terminated string by pointer with an otherwise identical syscall that takes the string by pointer, capacity, and length instead. It would be a huge boon to programs written in modern languages. I keep meaning to search the kernel mailing lists to see if the idea has been proposed before, but I never quite find the time.
2 comments

Why also capacity?

What I think would make sense is a change to the C API where the error code is an out parameter and not that ugly thread local errno. But I guess that's not big enough of an issue for people/languages that use libc as system call interface.

You’re right; technically read–only access to a string only needs to know the pointer and length. I didn’t take the time to polish my message very much.

Errorno is stupid and annoying too, but I think that’s mostly a libc thing rather than a kernel thing. The syscalls themselves simply return error codes in a register as a return value. Worth fixing though.

Modern languages .. or more specifically .. modern compilers for those languages .. can surely sustain a pointer, capacity and length wrap to pointer until null ..
That’s not the point. The point is to avoid the work of repeatedly making sure that the null terminator exists, and of finding the lengths of strings by scanning them looking for that null character.