Skip to content

Instantly share code, notes, and snippets.

@mwleeds
Created March 25, 2022 01:51
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 mwleeds/466a3da3e04d0913d5e7fac2e07c9c4d to your computer and use it in GitHub Desktop.
Save mwleeds/466a3da3e04d0913d5e7fac2e07c9c4d to your computer and use it in GitHub Desktop.
#include <glib.h>
#include <gio/gio.h>
#include <stdio.h>
static void
changed_cb (GFileMonitor *m,
GFile *f,
GFile *f2,
GFileMonitorEvent event_type,
gpointer user_data)
{
g_printerr ("an event!\n");
}
int main (int argc, char **argv) {
const char *path = "/home/mwleeds/adirectorythatdoesnotexist";
g_autoptr(GFile) f = g_file_new_for_path (path);
g_autoptr(GError) error = NULL;
GMainContext *c;
c = g_main_context_new ();
g_autoptr(GFileMonitor) m = g_file_monitor_directory (f, G_FILE_MONITOR_WATCH_MOVES, NULL, &error);
if (!m) {
printf ("%s", error->message);
return 1;
}
g_signal_connect (m, "changed", G_CALLBACK (changed_cb), NULL);
while (1)
{
g_main_context_iteration (c, TRUE);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment