我正在尝试对目录进行文件监视,从苹果文档中获取代码。它在 fseventstreamcreate 函数调用上崩溃并出现此错误:
异常类型:EXC_BAD_ACCESS (SIGSEGV)
异常代码:KERN_INVALID_ADDRESS at 0x0000000000000008
我对目标 C 相当陌生(尽管我知道这是 C 代码,它是 obj-c 应用程序的一部分)并且真的不知道为什么会崩溃,这里可能是一个菜鸟错误。我很感激这方面的任何帮助。
void monitorCallback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
int i;
char **paths = (char**)eventPaths;
// printf("Callback called\n");
for (i=0; i<numEvents; i++)
{
/* flags are unsigned long, IDs are uint64_t */
printf("Change %llu in %s, flags %u\n", eventIds[i], paths[i], eventFlags[i]);
}
}
- (void) monitorFolder
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * monitorFolder = [[NSUserDefaults standardUserDefaults] objectForKey:@"monitorFolder"];
//Create stream to monitor for changes.
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&monitorFolder, 1, NULL);
FSEventStreamRef stream;
CFAbsoluteTime latency = 3.0; /* Latency in seconds */
/* Create the stream, passing in a callback */
stream = FSEventStreamCreate(
NULL,
(FSEventStreamCallback)&monitorCallback,
NULL,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNone );
...
}