为什么 Linux Open 系统调用不需要路径的缓冲区大小参数? [英] Why does the Linux Open system call not need a buffer size parameter for the path?

查看:23
本文介绍了为什么 Linux Open 系统调用不需要路径的缓冲区大小参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 open 系统调用不需要像 write 系统调用那样的缓冲区大小参数?

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?

open 系统调用是否假定 path 参数以零结尾的字符串而 write 系统调用没有?如果是这样,为什么不一致?

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?

推荐答案

UNIX 被开发为一种操作系统,用于用汇编编写的程序,后来用于用 C 编写的程序.在 UNIX 团队使用的汇编约定中,后来在 C 中,字符串以 NUL 字节结尾.因此,在与操作系统交谈时使用相同的约定是很自然的.Linus 在设计 Linux 时复制了 UNIX API,因此它具有相同的设计.使用 NUL 终止字符串不会丢失任何功能,因为 NUL 字节不允许出现在路径或其他标识符中.

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.

write 调用将任意二进制数据写入文件.此数据不一定是文本,因此使用字符串约定没有多大意义.

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.

这篇关于为什么 Linux Open 系统调用不需要路径的缓冲区大小参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆