dmon
1.0.0
@Septag
DMON是一个很小的C库,可监视目录中的变化。它为每个OS存在的多个系统API提供了统一的解决方案。它还可以递归监视目录。
ReadDirectoryChangesW后端。使用Windows10 SDK + Visual Studio 2019测试inotify后端。用GCC-7.4/clang-6,Ubuntu 18.04 LTS测试FSEvents后端。用MacOS-10.14 clang测试10您只需要包含文件并使用其功能即可。它也与C ++代码兼容。 Windows路径中的后斜线也被转换为“/”以供便携性。
#define DMON_IMPL
#include "dmon.h"
static void watch_callback ( dmon_watch_id watch_id , dmon_action action , const char * rootdir ,
const char * filepath , const char * oldfilepath , void * user )
{
// receive change events. type of event is stored in 'action' variable
}
int main ()
{
dmon_init ();
dmon_watch ( "/path/to/directory" , watch_callback , DMON_WATCHFLAGS_RECURSIVE , NULL );
// wait ...
dmon_deinit ();
return 0 ;
}有关更多信息以及如何自定义功能,请参见DMON.H
要在Linux上构建,请与pthread链接: gcc test.c -lpthread -o test
要建立MacOS,请与CoreServices和CoreFoundation链接: clang test.c -framework CoreFoundation -framework CoreServices -lpthread -o test
还有其他文件dmon_extra.h ,您可以在Linux Backend之后(可选dmon.h包含它。该标题, dmon_watch_add和dmon_watch_rm中有两个API,您可以将/删除子目录添加到当前观看的目录中。在Linux Backend上发生了大量更改,并且由于inotify后端的某些缺点,这可能很有用。因此,通过禁用DMON_WATCHFLAGS_RECURSIVE并使用这些功能手动处理目录递归,您可以解决这些问题。
Copyright 2019 Sepehr Taghdisian. All rights reserved.
https://github.com/septag/dmon
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.