Skip to content

Instantly share code, notes, and snippets.

@mike-burns
Created April 5, 2015 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-burns/6ae3fd0670ed53d4575b to your computer and use it in GitHub Desktop.
Save mike-burns/6ae3fd0670ed53d4575b to your computer and use it in GitHub Desktop.
How does GTK+3 want to open your file?
/*
* gcc -g `pkg-config gtk+-3.0 --libs --cflags` main.c -o main
*/
#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include <gtk/gtk.h>
extern int errno;
__dead static void usage();
int
main(int argc, char *argv[])
{
GAppInfo *app_info;
GFile *file;
GError *error;
if (argc < 2)
usage();
file = g_file_new_for_uri(argv[1]);
error = NULL;
app_info = g_file_query_default_handler(file, NULL, &error);
g_object_unref(file);
if (app_info == NULL)
errx(1, "could not get app info from URI scheme: %s",
error->message);
printf("exec: '%s'\n", g_app_info_get_commandline(app_info));
g_object_unref(app_info);
return 0;
}
static void
usage()
{
fprintf(stderr, "usage: ./main file-uri\n");
exit(64);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment