Index: src/OFFileIRIHandler.m ================================================================== --- src/OFFileIRIHandler.m +++ src/OFFileIRIHandler.m @@ -761,10 +761,66 @@ [OFString stringWithCString: dirent->d_name encoding: encoding]]; } @finally { fs_close_attr_dir(dir); } +# elif defined(OF_SOLARIS) + int fd; + DIR *dir; + + if ((fd = attropen(cPath, ".", O_RDONLY)) == -1) + return; + + if ((dir = fdopendir(fd)) == NULL) { + close(fd); + return; + } + +# ifdef OF_HAVE_THREADS + @try { + [readdirMutex lock]; + } @catch (id e) { + closedir(dir); + close(fd); + @throw e; + } +# endif + + @try { + names = [OFMutableArray array]; + + for (;;) { + struct dirent *dirent; + OFString *name; + + errno = 0; + if ((dirent = readdir(dir)) == NULL) { + if (errno == 0) + break; + else + return; + } + + if (strcmp(dirent->d_name, ".") == 0 || + strcmp(dirent->d_name, "..") == 0) + continue; + + name = [[OFString alloc] initWithCString: dirent->d_name + encoding: encoding]; + @try { + [names addObject: name]; + } @finally { + [name release]; + } + } + } @finally { +# ifdef OF_HAVE_THREADS + [readdirMutex unlock]; +# endif + closedir(dir); + close(fd); + } # endif [names makeImmutable]; [attributes setObject: names forKey: OFFileExtendedAttributesNames]; } @@ -1708,13 +1764,13 @@ { void *pool = objc_autoreleasePoolPush(); OFString *path = IRI.fileSystemRepresentation; OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; - void *value = NULL; # if defined(OF_LINUX) || defined(OF_MACOS) const char *cName = [name cStringWithEncoding: encoding]; + void *value = NULL; # if defined(OF_LINUX) ssize_t size = lgetxattr(cPath, cName, NULL, 0); # elif defined(OF_MACOS) ssize_t size = getxattr(cPath, cName, NULL, 0, 0, XATTR_NOFOLLOW); # endif @@ -1748,10 +1804,11 @@ *type = nil; # elif defined(OF_FREEBSD) || defined(OF_NETBSD) int namespace; const char *cName; ssize_t size; + void *value = NULL; parseAttributeName(&name, &namespace); cName = [name cStringWithEncoding: encoding]; if ((size = extattr_get_link(cPath, namespace, cName, NULL, 0)) < 0) @@ -1779,10 +1836,11 @@ *type = nil; # elif defined(OF_HAIKU) const char *cName = [name cStringWithEncoding: encoding]; int fd = open(cPath, O_RDONLY); struct attr_info info; + void *value = NULL; if (fd == -1) @throw [OFGetItemAttributesFailedException exceptionWithIRI: IRI errNo: errno]; @@ -1814,10 +1872,40 @@ *type = [OFNumber numberWithUnsignedLong: info.type]; } @finally { OFFreeMemory(value); close(fd); } +# elif defined(OF_SOLARIS) + const char *cName = [name cStringWithEncoding: encoding]; + int fd; + + if ((fd = attropen(cPath, cName, O_RDONLY)) == -1) + @throw [OFGetItemAttributesFailedException + exceptionWithIRI: IRI + errNo: errno]; + + @try { + OFMutableData *mutableData = [OFMutableData data]; + char buffer[512]; + ssize_t length; + + while ((length = read(fd, buffer, 512)) > 0) + [mutableData addItems: buffer count: length]; + + if (length < 0) + @throw [OFGetItemAttributesFailedException + exceptionWithIRI: IRI + errNo: errno]; + + [mutableData makeImmutable]; + *data = mutableData; + } @finally { + close(fd); + } + + if (type != NULL) + *type = nil; # endif [*data retain]; if (type != NULL) [*type retain]; @@ -1839,16 +1927,17 @@ OFStringEncoding encoding = [OFLocale encoding]; const char *cPath = [path cStringWithEncoding: encoding]; size_t size = data.count * data.itemSize; # if defined(OF_LINUX) || defined(OF_MACOS) - const char *cName = [name cStringWithEncoding: encoding]; + const char *cName; if (type != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; + cName = [name cStringWithEncoding: encoding]; # if defined(OF_LINUX) if (lsetxattr(cPath, cName, data.items, size, 0) != 0) { # elif defined(OF_MACOS) if (setxattr(cPath, cName, data.items, size, 0, XATTR_NOFOLLOW) != 0) { # endif @@ -1928,10 +2017,43 @@ errNo: errNo]; } } @finally { close(fd); } +# elif defined(OF_SOLARIS) + const char *cName; + int fd; + + if (type != nil) + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; + + cName = [name cStringWithEncoding: encoding]; + fd = attropen(cPath, cName, O_WRONLY | O_CREAT | O_TRUNC, 0666); + + if (fd == -1) + /* TODO: Add an attribute (prefix?) for extended attributes? */ + @throw [OFSetItemAttributesFailedException + exceptionWithIRI: IRI + attributes: [OFDictionary dictionary] + failedAttribute: @"" + errNo: errno]; + + @try { + if (write(fd, data.items, size) != (ssize_t)size) + /* + * TODO: Add an attribute (prefix?) for extended + * attributes? + */ + @throw [OFSetItemAttributesFailedException + exceptionWithIRI: IRI + attributes: [OFDictionary dictionary] + failedAttribute: @"" + errNo: errno]; + } @finally { + close(fd); + } # endif objc_autoreleasePoolPop(pool); } @@ -2005,12 +2127,38 @@ failedAttribute: @"" errNo: errNo]; } } @finally { close(fd); + } +# elif defined(OF_SOLARIS) + const char *cName = [name cStringWithEncoding: encoding]; + int fd; + + if ((fd = attropen(cPath, ".", O_RDONLY)) < 0) + /* TODO: Add an attribute (prefix?) for extended attributes? */ + @throw [OFSetItemAttributesFailedException + exceptionWithIRI: IRI + attributes: [OFDictionary dictionary] + failedAttribute: @"" + errNo: errno]; + + @try { + if (unlinkat(fd, cName, 0) != 0) + /* + * TODO: Add an attribute (prefix?) for extended + * attributes? + */ + @throw [OFSetItemAttributesFailedException + exceptionWithIRI: IRI + attributes: [OFDictionary dictionary] + failedAttribute: @"" + errNo: errno]; + } @finally { + close(fd); } # endif objc_autoreleasePoolPop(pool); } #endif @end Index: src/OFFileManager.h ================================================================== --- src/OFFileManager.h +++ src/OFFileManager.h @@ -38,11 +38,12 @@ # if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \ defined(OF_WINDOWS) || defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_SYMLINKS # endif # if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_FREEBSD) || \ - defined(OF_NETBSD) || defined(OF_HAIKU) || defined(DOXYGEN) + defined(OF_NETBSD) || defined(OF_HAIKU) || defined(OF_SOLARIS) || \ + defined(DOXYGEN) # define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES # endif #endif @class OFArray OF_GENERIC(ObjectType);