Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_file_slurp ( CameraFile file,
char *  data,
size_t  size,
size_t *  readlen 
)

Parameters:
file a CameraFile
data 
size 
Returns:
a gphoto2 error code.
Internal.

Definition at line 240 of file gphoto2-file.c.

References CHECK_NULL, GP_ERROR, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, gp_log(), GP_LOG_ERROR, and GP_OK.

  {
      CHECK_NULL (file);

      switch (file->accesstype) {
      case GP_FILE_ACCESSTYPE_MEMORY:
            if (size > file->size-file->offset)
                  size = file->size - file->offset;
            memcpy (data, &file->data[file->offset], size);
            file->offset += size;
            if (readlen) *readlen = size;
            break;
      case GP_FILE_ACCESSTYPE_FD: {
            unsigned long int curread = 0; 
            while (curread < size) {
                  size_t      res = read (file->fd, data+curread, size-curread);
                  if (res == -1) {
                        gp_log (GP_LOG_ERROR, "gphoto2-file", "Encountered error %d reading from fd.", errno);
                        return GP_ERROR_IO_READ;
                  }
                  if (!res) { /* no progress is bad too */
                        gp_log (GP_LOG_ERROR, "gphoto2-file", "Encountered 0 bytes reading from fd.");
                        return GP_ERROR_IO_READ;
                  }
                  curread += res;
                  if (readlen)
                        *readlen = curread;
            }
            break;
      }
      default:
            gp_log (GP_LOG_ERROR, "gphoto2-file", "Unknown file access type %d", file->accesstype);
            return GP_ERROR;
      }
        return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index