c-ipfs/unixfs/format.c.old
jmjatlanta 914d3caaed Intermidiate commit with big changes to storage formats
I am attempting to match the storage format of the reference
implementation, so as to generate the same hashes.
2016-12-23 09:37:43 -05:00

42 lines
1.1 KiB
C

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "ipfs/unixfs/format.h"
/**
* Copy data into a new struct
* @param type the type of data
* @param data the acutal data
* @param data_length the length of the data array
* @param result where the struct will be stored
* @returns true(1) on success
*/
int ipfs_unixfs_format_new(enum UnixFSFormatType type, const unsigned char* data,
size_t data_length, struct UnixFSData** result) {
struct UnixFSData* new_struct = (struct UnixFSData*)malloc(sizeof(struct UnixFSData));
if (new_struct == NULL)
return 0;
new_struct->data = (unsigned char*) malloc(sizeof(unsigned char) * data_length);
if (new_struct->data == NULL) {
free (new_struct);
return 0;
}
memcpy(new_struct->data, data, data_length);
new_struct->type = type;
new_struct->data_length = data_length;
return 1;
}
/**
* Free memory allocated by _new
* @param data the struct
* @returns true(1) on success
*/
int ipfs_unixfs_format_free(struct UnixFSData* unixfs_data) {
free(unixfs_data->data);
free(unixfs_data);
return 0;
}