Created
April 5, 2015 16:33
-
-
Save mike-burns/6ae3fd0670ed53d4575b to your computer and use it in GitHub Desktop.
How does GTK+3 want to open your file?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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