can4linux - the Linux CAN driver
 All Data Structures Files Functions Variables Pages
Macros | Functions
read.c File Reference

Macros

#define pr_fmt(fmt)   KBUILD_MODNAME ": " fmt
 

Functions

ssize_t can_read (struct file *file, char __user *buffer, size_t count, loff_t *loff)
 ssize_t read(int fd, void *buf, size_t count); the read system call More...
 

Detailed Description

Author
Heinz-Jürgen Oertel

Module Description see Doxygen Doc for all possibilities

Function Documentation

ssize_t can_read ( struct file *  file,
char __user *  buffer,
size_t  count,
loff_t *  loff 
)

ssize_t read(int fd, void *buf, size_t count); the read system call

Parameters
fdThe descriptor to read from.
bufThe destination data buffer (array of CAN canmsg_t).
countThe number of bytes to read.

read() attempts to read up to count CAN messages (not bytes! ) from file descriptor fd into the buffer starting at buf. buf must be large enough to hold count times the size of one CAN message structure canmsg_t.

int got;
canmsg_t rx[80]; // receive buffer for read()
got = read(can_fd, rx , 80 );
if( got > 0) {
...
} else {
// read returned with error
fprintf(stderr, "- Received got = %d\n", got);
fflush(stderr);
}
*
ERRORS

the following errors can occur

  • EINVAL buf points not to an large enough area,
Returns
On success, the number of CAN messages read is returned (zero indicates end of file). It is not an error if this number is smaller than the number of messages requested; this may happen for example because fewer messages are actually available right now, or because read() was interrupted by a signal. On error, -1 is returned, and errno is set appropriately.