问题
Why does the open
system call not need a buffer size parameter like the write
system call does?
How do these two system calls treat their string parameters differently?
Does the open
system call assume a zero-terminated string for the path parameter while the write
system call does not? If so why the inconsistency?
Why not make all (or none) of the system calls that use strings / arrays require a size parameter?
回答1:
UNIX was developed as an operating system for programs written in assembly, later for programs written in C. In the assembly convention the UNIX team uses and later in C, strings are terminated with NUL bytes. Thus it is only natural to use the same convention when talking to the operating system. Linus copied the UNIX API when designing Linux, so that's why it has the same design. No functionality is lost by terminating strings with NUL as NUL bytes are not allowed to appear in paths or other identifiers.
A write
call writes arbitrary binary data to a file. This data is not necessarily text thus using the string convention doesn't make much sense.
来源:https://stackoverflow.com/questions/55262374/why-does-the-linux-open-system-call-not-need-a-buffer-size-parameter-for-the-pat