@@ -37,11 +37,11 @@ #endif #include #if defined(OF_LINUX) || defined(OF_MACOS) # include #endif -#ifdef OF_NETBSD +#if defined(OF_FREEBSD) || defined(OF_NETBSD) # include #endif #ifdef OF_HAIKU # include # include @@ -155,10 +155,15 @@ static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *); static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD); static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); #endif + +#if defined(OF_FREEBSD) || defined(OF_NETBSD) +static const char *namespaces[] = EXTATTR_NAMESPACE_NAMES; +static int numNamespaces = sizeof(namespaces) / sizeof(*namespaces); +#endif #ifdef OF_WINDOWS static OFTimeInterval filetimeToTimeInterval(const FILETIME *filetime) { @@ -383,28 +388,34 @@ #else return statWrapper(path, buffer); #endif } -#ifdef OF_NETBSD +#if defined(OF_FREEBSD) || defined(OF_NETBSD) static void parseAttributeName(OFString **name, int *namespace) { size_t pos = [*name rangeOfString: @"."].location; OFString *namespaceName; + const char *cNamespace; if (pos == OFNotFound) @throw [OFInvalidArgumentException exception]; namespaceName = [*name substringToIndex: pos]; - - if (extattr_string_to_namespace( - [namespaceName cStringWithEncoding: [OFLocale encoding]], - namespace) == -1) - @throw [OFInvalidArgumentException exception]; + cNamespace = [namespaceName cStringWithEncoding: [OFLocale encoding]]; *name = [*name substringFromIndex: pos + 1]; + + for (int i = 0; i < numNamespaces; i++) { + if (strcmp(namespaces[i], cNamespace) == 0) { + *namespace = i; + return; + } + } + + @throw [OFInvalidArgumentException exception]; } #endif static void setTypeAttribute(OFMutableFileAttributes attributes, Stat *s) @@ -656,35 +667,29 @@ size -= length + 1; } } @finally { OFFreeMemory(list); } -# elif defined(OF_NETBSD) +# elif defined(OF_FREEBSD) || defined(OF_NETBSD) names = [OFMutableArray array]; - for (size_t i = 0; extattr_namespaces[i] != 0; i++) { + for (int i = 0; i < numNamespaces; i++) { ssize_t size; char *list; - if ((size = extattr_list_link(cPath, extattr_namespaces[i], - NULL, 0)) < 0) + if ((size = extattr_list_link(cPath, i, NULL, 0)) < 0) continue; list = OFAllocMemory(1, size); @try { - OFString *namespace; - char *cNamespace, *iter; - - if (extattr_namespace_to_string( - extattr_namespaces[i], &cNamespace) == -1) - continue; - - namespace = [OFString stringWithCString: cNamespace - encoding: encoding]; - - if ((size = extattr_list_link(cPath, - extattr_namespaces[i], list, size)) < 0) + OFString *namespace = [OFString + stringWithCString: namespaces[i] + encoding: encoding]; + char *iter; + + if ((size = extattr_list_link(cPath, i, + list, size)) < 0) continue; iter = list; while (size > 0) { @@ -1742,11 +1747,11 @@ OFFreeMemory(value); } if (type != NULL) *type = nil; -# elif defined(OF_NETBSD) +# elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; ssize_t size; parseAttributeName(&name, &namespace); @@ -1857,11 +1862,11 @@ exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } -# elif defined(OF_NETBSD) +# elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; if (size > SSIZE_MAX) @throw [OFOutOfRangeException exception]; @@ -1955,11 +1960,11 @@ exceptionWithIRI: IRI attributes: [OFDictionary dictionary] failedAttribute: @"" errNo: errNo]; } -# elif defined(OF_NETBSD) +# elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; parseAttributeName(&name, &namespace); cName = [name cStringWithEncoding: encoding];