Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_filesystem_append ( CameraFilesystem fs,
const char *  folder,
const char *  filename,
GPContext context 
)

gp_filesystem_append: : a CameraFilesystem : the folder where to put the file in : filename of the file : a GPContext

Tells the that there is a file called in folder called . Usually, camera drivers will call this function after capturing an image in order to tell the about the new file. A front-end should not use this function.

Return value: a gphoto2 error code.

Definition at line 601 of file gphoto2-filesys.c.

References _CameraFilesystem::folder.

Referenced by gp_filesystem_list_files().

{
      CameraFilesystemFile *new;
        int x, y;

      CHECK_NULL (fs && folder);
      CC (context);
      CA (folder, context);

      /* Check for existence */
      x = gp_filesystem_folder_number (fs, folder, context);
      switch (x) {
      case GP_ERROR_DIRECTORY_NOT_FOUND:
            CR (append_folder (fs, folder, context));
            break;
      default:
            CR (x);
      }
      CR (x = gp_filesystem_folder_number (fs, folder, context));

      if (!filename)
            return (GP_OK);

      /* If file exists, return error */
      for (y = 0; y < fs->folder[x].count; y++)
            if (!strncmp (fs->folder[x].file[y].name, filename,
                       strlen (filename)) && (
                (strlen (filename) == strlen (fs->folder[x].file[y].name))))
                  break;
      if (y < fs->folder[x].count) {
            gp_context_error (context, 
                  _("Could not append '%s' to folder '%s' because "
                    "this file already exists."), filename, folder);
            return (GP_ERROR_FILE_EXISTS);
      }

      /* Allocate a new file in that folder and append the file */
      if (!fs->folder[x].count)
            CHECK_MEM (new = malloc (sizeof (CameraFilesystemFile)))
      else
            CHECK_MEM (new = realloc (fs->folder[x].file,
                              sizeof (CameraFilesystemFile) *
                              (fs->folder[x].count + 1)));
      fs->folder[x].file = new;
      fs->folder[x].count++;
      memset (&(fs->folder[x].file[fs->folder[x].count - 1]), 0,
            sizeof (CameraFilesystemFile));
      strcpy (fs->folder[x].file[fs->folder[x].count - 1].name, filename);
      fs->folder[x].file[fs->folder[x].count - 1].info_dirty = 1;

      /*
       * If people manually add files, they probably know the contents of
       * this folder.
       */
      fs->folder[x].files_dirty = 0;

        return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index