From aa4008c978265b0818958c7bc78f42d91ef8655c Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 3 Apr 2004 17:16:49 +0000 Subject: [PATCH] r3400: Try to load xattr functions dynamically (somewhat untested since I don't have xattr filesystem support). Hopefully, this will lead to better binary compatibility. --- ROX-Filer/src/main.c | 2 ++ ROX-Filer/src/xtypes.c | 53 +++++++++++++++++++++++++++++++++++++------------- ROX-Filer/src/xtypes.h | 5 +++-- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index 593a2c28..f52b96a7 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -71,6 +71,7 @@ #include "panel.h" #include "session.h" #include "minibuffer.h" +#include "xtypes.h" int number_of_windows = 0; /* Quit when this reaches 0 again... */ int to_wakeup_pipe = -1; /* Write here to get noticed */ @@ -211,6 +212,7 @@ int main(int argc, char **argv) /* Get internationalisation up and running. This requires the * choices system, to discover the user's preferred language. */ + xtype_init(); choices_init(); options_init(); i18n_init(); diff --git a/ROX-Filer/src/xtypes.c b/ROX-Filer/src/xtypes.c index 842d77f1..b1d3612d 100644 --- a/ROX-Filer/src/xtypes.c +++ b/ROX-Filer/src/xtypes.c @@ -36,16 +36,6 @@ #include -#ifdef HAVE_GETXATTR -#if defined(HAVE_ATTR_XATTR_H) -#include -#elif defined(HAVE_SYS_XATTR_H) -#include -#else -#error "Where is getxattr defined?" -#endif -#endif - #include "global.h" #include "type.h" #include "xtypes.h" @@ -55,19 +45,41 @@ #if defined(HAVE_GETXATTR) /* Linux implementation */ +#include + +static int (*dyn_setxattr)(const char *path, const char *name, + const void *value, size_t size, int flags) = NULL; +static ssize_t (*dyn_getxattr)(const char *path, const char *name, + void *value, size_t size) = NULL; + +void xtype_init(void) +{ + void *libc; + + libc = dlopen("libc.so.6", RTLD_LAZY | RTLD_NOLOAD); + if (!libc) + return; /* Give up on xattr support */ + + (void *) dyn_setxattr = dlsym(libc, "setxattr"); + (void *) dyn_getxattr = dlsym(libc, "setxattr"); +} + MIME_type *xtype_get(const char *path) { ssize_t size; gchar *buf; MIME_type *type = NULL; - size = getxattr(path, XTYPE_ATTR, "", 0); + if (!dyn_getxattr) + return type_from_path(path); /* Old libc */ + + size = dyn_getxattr(path, XTYPE_ATTR, "", 0); if (size > 0) { int new_size; buf = g_new(gchar, size + 1); - new_size = getxattr(path, XTYPE_ATTR, buf, size); + new_size = dyn_getxattr(path, XTYPE_ATTR, buf, size); if (size == new_size) { @@ -90,14 +102,25 @@ int xtype_set(const char *path, const MIME_type *type) int res; gchar *ttext; + if (!dyn_setxattr) + { + errno = ENOSYS; + return 1; /* Set type failed */ + } + ttext = g_strdup_printf("%s/%s", type->media_type, type->subtype); - res = setxattr(path, XTYPE_ATTR, ttext, strlen(ttext), 0); + res = dyn_setxattr(path, XTYPE_ATTR, ttext, strlen(ttext), 0); g_free(ttext); return res; } #elif defined(HAVE_ATTROPEN) + +void xtype_init(void) +{ +} + /* Solaris 9 implementation */ MIME_type *xtype_get(const char *path) @@ -154,6 +177,10 @@ int xtype_set(const char *path, const MIME_type *type) #else /* No extended attricutes available */ +void xtype_init(void) +{ +} + MIME_type *xtype_get(const char *path) { /* Fall back to non-extended */ diff --git a/ROX-Filer/src/xtypes.h b/ROX-Filer/src/xtypes.h index 46cc4f44..32945c75 100644 --- a/ROX-Filer/src/xtypes.h +++ b/ROX-Filer/src/xtypes.h @@ -17,7 +17,8 @@ #endif /* Prototypes */ -extern MIME_type *xtype_get(const char *path); -extern int xtype_set(const char *path, const MIME_type *type); +MIME_type *xtype_get(const char *path); +int xtype_set(const char *path, const MIME_type *type); +void xtype_init(void); #endif -- 2.11.4.GIT