Skip to content

Commit

Permalink
Replace procfs linuxism with kinfo freebsdism
Browse files Browse the repository at this point in the history
  • Loading branch information
arrowd authored and pwithnall committed Nov 13, 2024
1 parent 6faed43 commit 6d67568
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion gio/tests/fake-desktop-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

/* A stub implementation of xdg-desktop-portal */

#ifdef __FreeBSD__
#include <fcntl.h>
#include <sys/types.h>
#include <sys/user.h>
#endif /* __FreeBSD__ */

#include <glib.h>
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
Expand Down Expand Up @@ -206,7 +212,7 @@ handle_to_uri (GVariant *handle,
{
int fd = -1;
int fd_id;
char *proc_path;
char *proc_path = NULL;
char *path;
char *uri;

Expand All @@ -216,8 +222,17 @@ handle_to_uri (GVariant *handle,
if (fd == -1)
return NULL;

#ifdef __FreeBSD__
struct kinfo_file kf;
kf.kf_structsize = sizeof (kf);
if (fcntl (fd, F_KINFO, &kf) == -1)
return NULL;
path = g_strdup (kf.kf_path);

#else
proc_path = g_strdup_printf ("/proc/self/fd/%d", fd);
path = g_file_read_link (proc_path, NULL);
#endif
g_assert_nonnull (path);

uri = g_filename_to_uri (path, NULL, NULL);
Expand Down

0 comments on commit 6d67568

Please sign in to comment.