dmon
1.0.0
@septag
Dmonは、ディレクトリ内の変更を監視する小さなCライブラリです。各OSに存在する複数のシステムAPIに対して統一されたソリューションを提供します。また、ディレクトリを再帰的に監視することもできます。
ReadDirectoryChangesWバックエンド。 Windows10 SDK + Visual Studio 2019でテストしましたinotify BackEnd。 GCC-7.4/Clang-6、Ubuntu 18.04 LTSでテストFSEvents backend。 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バックエンドのdmon.hの後にオプションを含めることができます。そのヘッダー、 dmon_watch_addとdmon_watch_rmに導入された2つのAPIがあり、現在視聴されているディレクトリにサブディレクトリを追加/削除できます。これは、Linuxバックエンドで大きな変更が発生し、 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.