Index: src/OFFileManager.h ================================================================== --- src/OFFileManager.h +++ src/OFFileManager.h @@ -180,15 +180,26 @@ - (void)changePermissionsOfItemAtPath: (OFString *)path permissions: (uint16_t)permissions; #endif #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER +/*! + * @brief Get the UID and GID of the specified item. + * + * @param UID A pointer to an uint16_t to store the UID, or NULL + * @param GID A pointer to an uint16_t to store the GID, or NULL + * @param path The path to the item whose UID and GID should be retrieved + */ +- (void)getUID: (nullable uint16_t *)UID + GID: (nullable uint16_t *)GID + ofItemAtPath: (OFString *)path; + /*! * @brief Get the owner and group of the specified item. * - * @param owner A pointer to an `OFString *` to store the owner, or nil - * @param group A pointer to an `OFString *` to store the group, or nil + * @param owner A pointer to an `OFString *` to store the owner, or NULL + * @param group A pointer to an `OFString *` to store the group, or NULL * @param path The path to the item whose owner and group should be retrieved */ - (void)getOwner: (OFString *__autoreleasing _Nonnull *_Nullable)owner group: (OFString *__autoreleasing _Nonnull *_Nullable)group ofItemAtPath: (OFString *)path; Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -755,13 +755,13 @@ errNo: errno]; } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER -- (void)getOwner: (OFString **)owner - group: (OFString **)group - ofItemAtPath: (OFString *)path +- (void)getUID: (uint16_t *)UID + GID: (uint16_t *)GID + ofItemAtPath: (OFString *)path { of_stat_t s; if (path == nil) @throw [OFInvalidArgumentException exception]; @@ -768,25 +768,41 @@ if (of_stat(path, &s) != 0) @throw [OFStatItemFailedException exceptionWithPath: path errNo: errno]; + if (UID != NULL) + *UID = s.st_uid; + if (GID != NULL) + *GID = s.st_gid; +} + +- (void)getOwner: (OFString **)owner + group: (OFString **)group + ofItemAtPath: (OFString *)path +{ + uint16_t UID, GID; + + [self getUID: &UID + GID: &GID + ofItemAtPath: path]; + # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif of_string_encoding_t encoding = [OFLocalization encoding]; if (owner != NULL) { - struct passwd *passwd = getpwuid(s.st_uid); + struct passwd *passwd = getpwuid(UID); *owner = [OFString stringWithCString: passwd->pw_name encoding: encoding]; } if (group != NULL) { - struct group *group_ = getgrgid(s.st_gid); + struct group *group_ = getgrgid(GID); *group = [OFString stringWithCString: group_->gr_name encoding: encoding]; } # ifdef OF_HAVE_THREADS