Example #1
0
char * om_string_copy(const char *str) {
	char *ret = om_malloc(sizeof(char)*strlen(str)+1);
	if( ret==NULL ) {
		om_error_set(OM_ERR_MALLOC,"Could not allocate to copy string in om_string_copy()");
		return OM_NULL;
	}
	strcpy(ret,str);
	return ret;
}
Example #2
0
char * om_substring_copy(om_substring_ptr ptr) {
	char * ret = om_malloc((ptr->len+1)*sizeof(char));
	if( ret==NULL ) {
		om_error_set(OM_ERR_MALLOC,"could not allocate to copy string in om_substring_copy()");
		return OM_NULL;
	}
	memcpy(ret,ptr->str,ptr->len*sizeof(char));
	return ret;
}
Example #3
0
void om_error_set_format(om_error_code code, const char *format, ...) {
	char *str = om_malloc(OM_STRING_FORMAT_LIMIT+1);
	va_list ap;
	va_start(ap,format);
	vsnprintf(str, OM_STRING_FORMAT_LIMIT, format, ap);
	va_end(ap);
	om_error_set(code,str);
	om_free(str);
}
Example #4
0
om_dict_entry_ptr __om_dict_new_entry(void * key, void * val) {
	om_dict_entry_ptr ret = om_malloc(sizeof(om_dict_entry));
	if( ret==NULL ) {
		om_error_set(OM_ERR_MALLOC,"Couldn't allocate a new dict entry");
		return OM_NULL;
	}
	ret->key=key;
	ret->value=val;
	return ret;
}
Example #5
0
om_substring_ptr om_substring_new(const char *str, int len) {
	om_substring_ptr ret = om_malloc(sizeof(om_substring));
	if( ret==NULL ) {
		om_error_set(OM_ERR_MALLOC,"Could not malloc() a new substring");
		return OM_NULL;
	}
	ret->str = str;
	ret->len = len;
	return ret;
}
Example #6
0
/**
 * @return om_dict_ptr where the hash_func is the default om_dict_hash_string function
 */
om_dict_ptr om_dict_new(int size) {
	om_dict_ptr ret = om_malloc(sizeof(om_dict));
	if( ret==OM_NULL ) {
		om_error_set( OM_ERR_MALLOC, "Could not allocate a new dict" );
		return OM_NULL;
	}
	ret->hash_func = om_dict_hash_string;
	ret->bucket_count = size;
	ret->buckets = om_malloc(sizeof(om_list_ptr)*size);
	return ret;
}
Example #7
0
char * om_mock_prefs_get(const om_prefs_ptr prefs, const char *key) {
	char *val = (char*)om_dict_get((om_dict_ptr)prefs->device_data,key);
	if( val==OM_NULL )
		return OM_NULL;
	char *ret = om_string_copy(val);
	if( ret==OM_NULL ) {
		om_error_set(OM_ERR_MALLOC,"Could not malloc() for string in om_prefs_get()");
		return OM_NULL;
	}
	return ret;
}
Example #8
0
om_unzip_archive_ptr om_unzip_open_archive(const char *file_path) {
	
	int err;
	
	unz_global_info * gip = om_malloc(sizeof(unz_global_info));
	if( gip==OM_NULL ) {
		return OM_NULL;
	}
	
	unzFile uf = unzOpen(file_path);
	err = unzGetGlobalInfo(uf,gip);
	if( err!=UNZ_OK ) {
		om_free(gip);
		om_error_set(OM_ERR_ZIP_GLOBALINFO,"Error getting global info for the zip archive.");
		return OM_NULL;
	}
	
	om_list_ptr error_log = om_list_new();
	if( error_log==OM_NULL ) {
		om_free(gip);
		return OM_NULL;
	}
	
	om_unzip_archive_ptr arch = om_malloc(sizeof(om_unzip_archive));
	if( arch==OM_NULL ) {
		om_list_release(error_log);
		om_free(gip);
		return OM_NULL;
	}
	
	arch->error_log = error_log;
	arch->file = uf;
	arch->global_info_ptr = gip;
	
	return arch;
}