Enable dynamic loading of setxattr(2) in Darwin/Mac OS X if compiled with dl interface, TODO old dyld interface.

This commit is contained in:
2021-05-20 16:31:27 +01:00
parent e20566d3ad
commit 142ef1d3ef
2 changed files with 18 additions and 1 deletions

View File

@@ -26,8 +26,15 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
return()
endif()
include(CheckSymbolExists)
find_library(CARBON_LIBRARY NAMES Carbon)
CHECK_SYMBOL_EXISTS(dlsym dlfcn.h HAVE_DLSYM)
if(HAVE_DLSYM)
add_sub_definitions(HAVE_DLSYM)
endif()
add_sources(os.c darwin.h volume.c volume.h attr.c attr.h rsrcfork.c rsrcfork.h sparse.c xattr.c xattr.h)
if(CARBON_LIBRARY)

View File

@@ -22,7 +22,11 @@ Aaru Data Preservation Suite
Copyright (C) 2011-2021 Natalia Portillo
*****************************************************************************/
// TODO: old dyld interface
#if HAVE_DLSYM
#include <dlfcn.h>
#endif // HAVE_DLSYM
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
@@ -33,13 +37,15 @@ Copyright (C) 2011-2021 Natalia Portillo
void DarwinExtendedAttributes(const char* path)
{
// TODO: old dyld interface
#if HAVE_DLSYM
int ret;
FILE* file;
int rc;
int cRc;
_darwin_setxattr darwin_setxattr;
darwin_setxattr = (_darwin_setxattr)dlsym(RTLD_DEFAULT, "setxattr");
darwin_setxattr = (_darwin_setxattr)dlsym(RTLD_DEFAULT, "setxattr");
if(!darwin_setxattr)
{
@@ -100,4 +106,8 @@ void DarwinExtendedAttributes(const char* path)
if(ret) cRc = errno;
}
log_write("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc);
#else // HAVE_DLSYM
printf("This version is not compiled to try extended attributes. This version MUST NOT be used in Mac OS X 10.4 "
"(Darwin 8.0) or higher\n");
#endif // HAVE_DLSYM
}