Unison Help
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
2.19.read() #
NAME
read – read from file
SYNOPSIS
#include <unistd.h>
- ssize_t read( int fildes , void *buf , size_t nbyte );
DESCRIPTION
read() attempts to read nbyte bytes from the file associated with fildes into the buffer pointed to by buf. If nbyte is zero, read() returns zero and has no other results. fildes is an open file descriptor.
On devices capable of seeking, the read() starts at a position in the file given by the file pointer associated with fildes. On return from read() , , the file pointer is incremented by the number of bytes actually read.
Devices that are incapable of seeking always read from the current position. The value of a file pointer associated with such a file is undefined.
On success, read() returns the number of bytes actually read and placed in the buffer; this number may be less than nbyte if the file is associated with a communication line or if the number of bytes left in the file is less than nbyte, or if the file is a pipe or a special file. A value of 0 is returned when an end-of-file has been reached.
read() reads data previously written to a file. If any portion of an ordinary file prior to the end of file has not been written, read() returns the number of bytes read as 0. For example, the lseek() routine allows the file pointer to be set beyond the end of existing data in the file. If additional data is written at this point, subsequent reads in the gap between the previous end of data and newly written data return bytes with a value of 0 until data is written into the gap.
When attempting to read from a regular file with mandatory file/record locking set and there is a write lock owned by another thread on the segment of the file to be read: If O_NDELAY or O_NONBLOCK is set, read() returns -1 and sets errno to EAGAIN. If O_NDELAY and O_NONBLOCK are clear, read() sleeps until the blocking record lock is removed.
When attempting to read from an empty pipe or FIFO: If no thread has the pipe open for writing, read() returns 0 to indicate end-of-file. If some thread has the pipe open for writing and O_NDELAY is set, read() returns 0. If some thread has the pipe open for writing and O_NONBLOCK is set, read() returns -1 and sets errno to EAGAIN. If O_NDELAY and O_NONBLOCK are clear, read() blocks until data is written to the pipe or the pipe is closed by all processes that had opened the pipe for writing.
When attempting to read a file associated with a terminal that has no data currently available: If O_NDELAY is set, read() returns 0. If O_NONBLOCK is set, read() returns -1 and sets errno to EAGAIN. If O_NDELAY and O_NONBLOCK are clear, read() blocks until data become available.
RETURN VALUES
On success a non-negative integer is returned indicating the number of bytes actually read. Otherwise, a -1 is returned and errnorminal that has no data is set to indicate the error.
ERRORS
This function is a member of Unison’s IOLIB family of functions. IOLIB is implemented as a message passing and generalized interface layer. Each Unison I/O server is responsible for its own error reporting.
For an exact list of error codes returned by a particular server, refer to that server’s documentation in the Unison Programmer’s Guide for each specific platform.
Servers may implement these errors codes in response to this function.
read() fails if one or more of the following are true:
- EAGAIN
- Mandatory file/record locking was set, O_NDELAY or O_NONBLOCK was set, and there was a blocking record lock.
- EAGAIN
- Total amount of system memory available when reading using raw I/O is temporarily insufficient.
- EAGAIN or EWOULDBLOCK
- No data is waiting to be read on a file associated with a socket or tty device and O_NONBLOCK was set.
- EBADF
- fildes is not a valid file descriptor open for reading.
- EFAULT
- buf points to an illegal address.