[prev] 13 [next]

Devices on Unix/Linux (cont)

Devices can be manipulated by open(), read(), write() ...

int open(char *PathName, int Flags)

  • attempts to open device PathName in mode Flags
  • Flags can specify caching, async i/o, close on exec(), etc.
  • returns file descriptor if ok, -1 (plus errno) if error
ssize_t read(int FDesc, void *Buf, size_t Nbytes)
  • attempts to read Nbytes of data into Buf from FDesc
  • returns # bytes actually read, 0 at EOF, -1 (plus errno) if error
ssize_t write(int FDesc, void *Buf, size_t Nbytes)
  • attempts to write Nbytes of data from Buf to FDesc
  • returns # bytes actually written, -1 (plus errno) if error