Search code examples
pythonlinuxpython-2.7system-callsfuse

How to call the 'read' system call with python


I need to run the linux 'read' system call with my arguments. Any ideas?

read(const char *path, char *buf, size_t size, off_t offset,struct fuse_file_info *fi)

I need to call the above function with my arguments.


Solution

  • Python exposes the C stdlib read() function as the os.read() function:

    os.read(fd, n)
    Read at most n bytes from file descriptor fd. Return a string containing the bytes read. If the end of the file referred to by fd has been reached, an empty string is returned.

    Errors are raised as OSError exceptions, with the errno attribute set to an integer as documented in the C read() documentation. You could use the errno module if you wanted constants to test against.