Files
libguestfs/examples/hello.c
Jim Meyering c372c7c23a maint: use EXIT_SUCCESS and EXIT_FAILURE, not 0 and 1 to exit
Convert all uses automatically, via these two commands:
git grep -l '\<exit *(1)' \
  | grep -vEf .x-sc_prohibit_magic_number_exit \
  | xargs --no-run-if-empty \
    perl -pi -e 's/\b(exit ?)\(1\)/$1(EXIT_FAILURE)/'
git grep -l '\<exit *(0)' \
  | grep -vEf .x-sc_prohibit_magic_number_exit \
  | xargs --no-run-if-empty \
  perl -pi -e 's/\b(exit ?)\(0\)/$1(EXIT_SUCCESS)/'
* .x-sc_prohibit_magic_number_exit: New file.

Edit (RWMJ): Don't change Java code.
2009-11-20 12:14:14 +00:00

39 lines
816 B
C

/* Create a "/hello" file on chosen partition.
* eg:
* hello guest.img /dev/sda1
* hello guest.img /dev/VolGroup00/LogVol00
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <guestfs.h>
int
main (int argc, char *argv[])
{
guestfs_h *g;
if (argc != 3 || access (argv[1], F_OK) != 0) {
fprintf (stderr, "Usage: hello disk-image partition\n");
exit (EXIT_FAILURE);
}
if (!(g = guestfs_create ())) exit (EXIT_FAILURE);
if (guestfs_add_drive (g, argv[1]) == -1) exit (EXIT_FAILURE);
if (guestfs_launch (g) == -1) exit (EXIT_FAILURE);
if (guestfs_mount (g, argv[2], "/") == -1) exit (EXIT_FAILURE);
if (guestfs_touch (g, "/hello") == -1) exit (EXIT_FAILURE);
guestfs_sync (g);
guestfs_close (g);
return 0;
}