检查Objective C中的资源分叉

问题描述 投票:2回答:3

如何检查文件是否存在资源分叉?

注意:不使用CarbonCore-> Resources.h的API,因为它们已被弃用。

我将能够打开存在资源分叉的文件。但我需要检查资源分支是否存在。这正是我正在寻找的。

objective-c macos cocoa xcode6
3个回答
4
投票

使用getattrlist或fgetattrlist在attrList参数中传递ATTR_FILE_RSRCLENGTH。看到man page for getattrlist


1
投票

另外

BOOL hasResourceFork = getxattr("/path/To/file", "com.apple.ResourceFork", NULL, 0, 0, 0) != -1;

这需要

#include <sys/xattr.h>

0
投票

对于那些想要获得实际资源分叉长度的人,这里是代码:

#include <sys/attr.h>

struct attrlist attrlist = {0};
attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;
attrlist.fileattr    = ATTR_FILE_RSRCLENGTH;
typedef struct __attribute__((__packed__)) {
    uint32_t size;
    off_t forkSize;
} result_t;
result_t result = {0};
if (getattrlist (filepath, &attrlist, &result, sizeof(result), 0) == 0) {
    assert(sizeof(result)==result.size); // makes sure we got the struct right
    // now we find the rsrc fork size in result.forkSize
}
© www.soinside.com 2019 - 2024. All rights reserved.