-1

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.

1
  • You should looking into read, write, and open syscalls. For instance, in Linux. Commented Feb 22 at 3:15

1 Answer 1

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().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.