Returns number of bytes read returns 0 bytes at end

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: system call interface –  Applica)ons request I/O opera)ons through syscalls –  Set up syscall arguments and trap to kernel –  Kernel performs opera)on and returns results •  Higher- level func)ons built on syscall interface –  printf, scanf, gets, all user- level code File Descriptors •  Most I/O in Unix done through file descriptors –  Integer handles to per- process table in kernel •  int open(char *path, int flags, ...);! •  Returns file descriptor, used for all I/O to file hbp://en.wikipedia.org/wiki/File_descriptor Error Returns •  What if open fails? Returns - 1 (invalid fd) •  Most system calls return - 1 on failure –  Specific type of error in global int errno! •  #include <sys/errno.h> for possible values –  2 = ENOENT “No such file or directory” –  13 = EACCES “Permission denied” Some opera)ons on File Descriptors •  ssize_t read (int fd, void *buf, int nbytes);! –  Returns number of bytes read –  Returns 0 bytes at end of file, or - 1 on error •  ssize_t write (int fd, void* buf, int nbytes);! –  Returns number of bytes wriben, - 1 on error •  off_t lseek (int fd, off_t offset, int whence);! –  whence: SEEK_SET, SEEK_CUR, SEEK_END! –  returns new offset, or - 1 on error •  int close (int fd);! Sockets: Communica)on Between Machines •  Network sockets are file descriptors too •  Datagram sockets: unreliable message delivery –  With IP, gives you UDP –  Send atomic messages, which may be reordered or lost –  Special system calls to re...
View Full Document

This note was uploaded on 01/27/2014 for the course COSC 4377 taught by Professor Staff during the Spring '08 term at University of Houston.

Ask a homework question - tutors are online