diff options
| author | 2008-12-12 22:05:44 +0100 | |
|---|---|---|
| committer | 2008-12-12 22:05:44 +0100 | |
| commit | 9ca887308d59e6cb5bf684f9f3bd968118e8014f (patch) | |
| tree | 14dd1cffa8e082ea71fcc8e7fdf878655cd98a3e /dev | |
| parent | 31379321cec6bf6c6d670e0738d1b1e23dc92ac1 (diff) | |
| download | libplist-9ca887308d59e6cb5bf684f9f3bd968118e8014f.tar.gz libplist-9ca887308d59e6cb5bf684f9f3bd968118e8014f.tar.bz2 | |
Fix some bugs in binary plist generation.
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/plutil.c | 37 | 
1 files changed, 24 insertions, 13 deletions
| diff --git a/dev/plutil.c b/dev/plutil.c index e76506e..3d93797 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -14,9 +14,7 @@  int main(int argc, char *argv[])  {  	struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); -	uint32_t position = 0;  	Options *options = parse_arguments(argc, argv); -	int argh = 0;  	if (!options) {  		print_usage(); @@ -25,29 +23,42 @@ int main(int argc, char *argv[])  	iphone_set_debug(options->debug); -	FILE *bplist = fopen(options->in_file, "r"); - +	//read input file +	FILE *iplist = fopen(options->in_file, "r"); +	if (!iplist) +		return 1;  	stat(options->in_file, filestats); +	char *plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); +	fread(plist_entire, sizeof(char), filestats->st_size, iplist); +	fclose(iplist); -	char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); -	argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); -	fclose(bplist); -	// bplist_entire contains our stuff +	//convert one format to another  	plist_t root_node = NULL;  	char *plist_out = NULL;  	int size = 0; -	if (memcmp(bplist_entire, "bplist00", 8) == 0) { -		bin_to_plist(bplist_entire, filestats->st_size, &root_node); +	if (memcmp(plist_entire, "bplist00", 8) == 0) { +		bin_to_plist(plist_entire, filestats->st_size, &root_node);  		plist_to_xml(root_node, &plist_out, &size);  	} else { -		xml_to_plist(bplist_entire, filestats->st_size, &root_node); +		xml_to_plist(plist_entire, filestats->st_size, &root_node);  		plist_to_bin(root_node, &plist_out, &size);  	} - -	printf("%s\n", plist_out); +	if (plist_out) { +		if (options->out_file != NULL) { +			FILE *oplist = fopen(options->out_file, "wb"); +			if (!oplist) +				return 1; +			fwrite(plist_out, size, sizeof(char), oplist); +			fclose(oplist); +		} +		//if no output file specified, write to stdout +		else +			fwrite(plist_out, size, sizeof(char), stdout); +	} else +		printf("ERROR\n");  	return 0;  } | 
