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

off_t smbc_lseek ( int  fd,
off_t  offset,
int  whence 
)

Seek to a specific location in a file.

Parameters:
fd Open file handle from smbc_open() or smbc_creat()
offset Offset in bytes from whence
whence A location in the file:
  • SEEK_SET The offset is set to offset bytes from the beginning of the file
  • SEEK_CUR The offset is set to current location plus offset bytes.
  • SEEK_END The offset is set to the size of the file plus offset bytes.
Returns:
Upon successful completion, lseek returns the resulting offset location as measured in bytes from the beginning of the file. Otherwise, a value of (off_t)-1 is returned and errno is set to indicate the error:
  • EBADF Fildes is not an open file descriptor.
  • EINVAL Whence is not a proper value or smbc_init not called.
Todo:
Are all the whence values really supported?
Todo:
Are errno values complete and correct?

Definition at line 1070 of file libsmbclient.c.

{
      struct smbc_file *fe;
      SMB_BIG_UINT size;

      if (!smbc_initialized) {

            errno = EINVAL;
            return -1;
            
      }

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

            errno = EBADF;
            return -1;

      }

      fe = smbc_file_table[fd - smbc_start_fd];

      if (!fe) {

            errno = EBADF;
            return -1;

      }

      if (!fe->file) {

            errno = EINVAL;
            return -1;      /* Can't lseek a dir ... */

      }

      switch (whence) {
      case SEEK_SET:
            fe->offset = offset;
            break;

      case SEEK_CUR:
            fe->offset += offset;
            break;

      case SEEK_END:
            if (!cli_qfileinfo(&fe->srv->cli, fe->cli_fd, NULL, &size, NULL, NULL,
                           NULL, NULL, NULL) &&
                !cli_getattrE(&fe->srv->cli, fe->cli_fd, NULL, &size, NULL, NULL,
                          NULL)) {

                  errno = EINVAL;
                  return -1;
            }
            fe->offset = size + offset;
            break;

      default:
            errno = EINVAL;
            break;

      }

      return fe->offset;

}


Generated by  Doxygen 1.6.0   Back to index