Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_list_append ( CameraList *  list,
const char *  name,
const char *  value 
)

Appends name and value to the list.

Parameters:
list a CameraList
name the name of the entry to append
value the value of the entry to append
Returns:
a gphoto2 error code

Definition at line 203 of file gphoto2-list.c.

References CHECK_LIST, and MAX_ENTRIES.

Referenced by gp_abilities_list_detect(), gp_filesystem_list_files(), gp_filesystem_list_folders(), and gp_list_populate().

{
      CHECK_LIST (list);

      if (list->count == MAX_ENTRIES) {
            gp_log (GP_LOG_ERROR, "gphoto2-list", "gp_list_append: "
            "Tried to add more than %d entries to the list, reporting error.",
            MAX_ENTRIES);
            return (GP_ERROR_FIXED_LIMIT_EXCEEDED);
      }

      if (name) {
            /* check that the 'name' value fits */
            const size_t buf_len = sizeof (list->entry[list->count].name);
            const size_t str_len = strlen (name);
            if (str_len >= buf_len) {
                  gp_log (GP_LOG_ERROR, "gphoto2-list", 
                        "gp_list_append: "
                        "'name' value too long (%d >= %d)",
                        str_len, buf_len);
                  return (GP_ERROR_FIXED_LIMIT_EXCEEDED);
            }
            /* set the value */
            strncpy (list->entry[list->count].name, name, buf_len);
            list->entry[list->count].name[buf_len-1] = '\0';
      }
      if (value) {
            /* check that the 'value' value fits */
            const size_t buf_len = sizeof (list->entry[list->count].value);
            const size_t str_len = strlen (value);
            if (str_len >= buf_len) {
                  gp_log (GP_LOG_ERROR, "gphoto2-list", 
                        "gp_list_append: "
                        "'value' value too long (%d >= %d)",
                        str_len, buf_len);
                  return (GP_ERROR_FIXED_LIMIT_EXCEEDED);
            }
            /* set the value */
            strncpy (list->entry[list->count].value, value, buf_len);
            list->entry[list->count].value[buf_len-1] = '\0';
      }

        list->count++;

        return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index