MOBI_RET mobi_ncx_add_to_rawml(const char *ncx_xml, MOBIRawml *rawml) {
    MOBIPart *ncx_part;
    size_t uid = 0;
    if (rawml->resources) {
        MOBIPart *part = rawml->resources;
        while (part->next) {
            part = part->next;
        }
        uid = part->uid + 1;
        part->next = calloc(1, sizeof(MOBIPart));
        ncx_part = part->next;
    }
    else {
        rawml->resources = calloc(1, sizeof(MOBIPart));
        ncx_part = rawml->resources;
    }
    if (ncx_part == NULL) {
        return MOBI_MALLOC_FAILED;
    }
    ncx_part->uid = uid;
    ncx_part->next = NULL;
    ncx_part->data = (unsigned char *) strdup(ncx_xml);
    if (ncx_part->data == NULL) {
        free(ncx_part);
        ncx_part = NULL;
        return MOBI_MALLOC_FAILED;
    }
    ncx_part->size = strlen(ncx_xml);
    ncx_part->type = T_NCX;
    return MOBI_SUCCESS;
}
MOBI_RET mobi_ncx_add_to_rawml(const char *ncx_xml, MOBIRawml *rawml) {
    MOBIPart *ncx_part;
    size_t uid = 0;
    if (rawml->resources) {
        MOBIPart *part = rawml->resources;
        while (part->next) {
            part = part->next;
        }
        uid = part->uid + 1;
        part->next = calloc(1, sizeof(MOBIPart));
        ncx_part = part->next;
    }
    else {
        rawml->resources = calloc(1, sizeof(MOBIPart));
        ncx_part = rawml->resources;
    }
    if (ncx_part == NULL) {
        return MOBI_MALLOC_FAILED;
    }
    ncx_part->uid = uid;
    ncx_part->next = NULL;
    ncx_part->data = (unsigned char *) strdup(ncx_xml);
    if (ncx_part->data == NULL) {
        free(ncx_part);
        ncx_part = NULL;
        return MOBI_MALLOC_FAILED;
    }
    ncx_part->size = strlen(ncx_xml);
    ncx_part->type = T_NCX;
    return MOBI_SUCCESS;
}