Why does the Linux Open system call not need a buffer size parameter for the path?

柔情痞子 提交于 2021-02-17 06:25:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!