Logo Search packages:      
Sourcecode: libgphoto2 version File versions  Download package

int gp_file_append ( CameraFile file,
const char *  data,
unsigned long int  size 
)

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

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

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

{
        char *t;

      CHECK_NULL (file);

      switch (file->accesstype) {
      case GP_FILE_ACCESSTYPE_MEMORY:
            if (!file->data)
                  file->data = malloc (sizeof(char) * (size));
            else {
                  t = realloc (file->data, sizeof (char) * (file->size + size));
                  if (!t)
                        return GP_ERROR_NO_MEMORY;
                  file->data = t;
            }
            memcpy (&file->data[file->size], data, size);
            file->size += size;
            break;
      case GP_FILE_ACCESSTYPE_FD: {
            unsigned long int curwritten = 0; 
            while (curwritten < size) {
                  size_t      res = write (file->fd, data+curwritten, size-curwritten);
                  if (res == -1) {
                        gp_log (GP_LOG_ERROR, "gphoto2-file", "Encountered error %d writing to fd.", errno);
                        return GP_ERROR_IO_WRITE;
                  }
                  if (!res) { /* no progress is bad too */
                        gp_log (GP_LOG_ERROR, "gphoto2-file", "Encountered 0 bytes written to fd.");
                        return GP_ERROR_IO_WRITE;
                  }
                  curwritten += res;
            }
            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