Logo Search packages:      
Sourcecode: samba-doc-ja version File versions

ssize_t smbc_read ( int  fd,
void *  buf,
size_t  bufsize 
)

Read from a file using an opened file handle.

Parameters:
fd Open file handle from smbc_open() or smbc_creat()
buf Pointer to buffer to recieve read data
bufsize Size of buf in bytes
Returns:
Number of bytes read, < 0 on error with errno set:
  • EISDIR fd refers to a directory
  • EBADF fd is not a valid file descriptor or is not open for reading.
  • EINVAL fd is attached to an object which is unsuitable for reading, or no buffer passed or smbc_init not called.
See also:
smbc_open(), smbc_write()

Definition at line 733 of file libsmbclient.c.

Referenced by smbc_print_file().

{
      struct smbc_file *fe;
      ssize_t ret;

      if (!smbc_initialized) {

            errno = EINVAL;
            return -1;

      }

      DEBUG(4, ("smbc_read(%d, %d)\n", fd, (int)count));

      if (fd < smbc_start_fd || fd >= (smbc_start_fd + SMBC_MAX_FD)) {

            errno = EBADF;
            return -1;

      }

      /* Check that the buffer exists ... */

      if (buf == NULL) {

            errno = EINVAL;
            return -1;

      }

      fe = smbc_file_table[fd - smbc_start_fd];

      if (!fe || !fe->file) {

            errno = EBADF;
            return -1;

      }

      ret = cli_read(&fe->srv->cli, fe->cli_fd, buf, fe->offset, count);

      if (ret < 0) {

            errno = smbc_errno(&fe->srv->cli);
            return -1;

      }

      fe->offset += ret;

      DEBUG(4, ("  --> %d\n", ret));

      return ret;  /* Success, ret bytes of data ... */

}


Generated by  Doxygen 1.6.0   Back to index