2 ms·
> Why is there a need for 76 lines of unsafe code? I took a quick look, and all of them seem to be for calling functions from the C library. Moreover, nearly a
by cesarb 7y ago
> Why is there a need for 76 lines of unsafe code?
I took a quick look, and all of them seem to be for calling functions from the C library. Moreover, nearly all of these seem to be system calls (open, close, select, ioctl...). Since the Rust compiler can't verify that these calls are safe (for an obvious example: the "read" call can write to arbitrary memory), it requires an "unsafe" block for them - signalling that it's the programmer's responsibility to make sure it's safe (in the "read" example, receiving a "&mut [u8]" from outside the "unsafe" block, and passing that slice's pointer and length as the parameters to the "read" call, would be safe).