admin管理员组

文章数量:1415460

Every language I've done some form of file handling in has some form of read/write specification when interacting with a file, something like

open_file(file_name, read=true) 

Is this typically implemented in the library? Or is there some simple operating system support that library devs can leverage?

I looked around the python file handling docs but I didn't see any clear specification of how read/write worked.

Every language I've done some form of file handling in has some form of read/write specification when interacting with a file, something like

open_file(file_name, read=true) 

Is this typically implemented in the library? Or is there some simple operating system support that library devs can leverage?

I looked around the python file handling docs but I didn't see any clear specification of how read/write worked.

Share Improve this question asked Feb 21 at 2:57 user29573453user29573453 1 1
  • You should looking into read, write, and open syscalls. For instance, in Linux. – wxz Commented Feb 22 at 3:15
Add a comment  | 

1 Answer 1

Reset to default 0

In order to be portable, languages would usually not specify how things are implemented.

However, almost always file permissions they are implemented by the operating system. For example, most operating systems implement some subset of POSIX. A POSIX operating system allows you to open a file as follows:

int open(const char *path, int oflag, ... );

And the documentation of oflag includes:

Applications shall specify exactly one of the first three values (file access modes) below in the value of oflag:
O_RDONLY
    Open for reading only.
O_WRONLY
    Open for writing only.
O_RDWR
    Open for reading and writing. The result is undefined if this flag is applied to a FIFO. 

Language implementations simply translate calls such as open_file(file_name, read=true) to the operating system's equivalent of open().

本文标签: operating systemtypical implementation of readwrite permissions in file reading codeStack Overflow