4 ms·
AFAIK Linux doesn't use zero-terminated strings anywhere in its syscalls, or at least not in those like write, where you pass a size alongside the buffer.
by eddyb 11y ago
AFAIK Linux doesn't use zero-terminated strings anywhere in its syscalls, or at least not in those like write, where you pass a size alongside the buffer.
- reipahb 11y agoHowever (almost?) all syscalls dealing with filesystem paths take null-terminated strings. See for example the implementation of the open() syscall: https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a49513911d0281577bfd/fs/open.c#L999 https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a... (Hence the need for the strncpy_from_user()-function: https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a49513911d0281577bfd/lib/strncpy_from_user.c#L99 https://github.com/torvalds/linux/blob/fb65d872d7a8dc629837a...)
- eddyb 11y agoAhh, I totally missed the path arguments, my bad.
- ranit 11y agowrite() syscall writes a sequence of bytes (not string) therefore cannot use zero-terminated convention.
- JoshTriplett 11y agoopen takes a NUL-terminated filename.