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 CoreServices
還有其他文件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.