/* FILE : c-test-0011.c
 *
 * SYNOPSIS : Test ped_disk_commit_to_os() reporting errors.
 *            https://bugzilla.gnome.org/show_bug.cgi?id=790418
 * BUILD    : gcc -o c-test-0011 c-test-0011.c -lparted
 */

#include <stdio.h>
#include <stdlib.h>
#include <parted/parted.h>

int main(int argc, const char *argv[])
{
	PedDevice* lp_device;
	PedDisk* lp_disk;
	int success;

	if ( argc != 2 )
	{
		fprintf(stderr, "Usage: c-test-0011 DISK\n");
		exit(1);
	}

	lp_device = ped_device_get(argv[1]);
	if (lp_device == NULL)
	{
		fprintf(stderr, "ped_device_get(\"%s\") failed\n", argv[1]);
		exit(1);
	}

	lp_disk = ped_disk_new(lp_device);
	if (lp_disk == NULL)
	{
		fprintf(stderr, "ped_disk_new(lp_device) failed\n");
		exit(1);
	}

	fprintf(stderr, "calling ped_disk_commit_to_os(lp_disk) ...\n");
	success = ped_disk_commit_to_os(lp_disk);
	if (! success)
	{
		fprintf(stderr, "ped_disk_commit_to_os(lp_disk) failed\n");
		exit(1);
	}
	fprintf(stderr, "ped_disk_commit_to_os(lp_disk) succeeded\n");

	return 0;
}
