delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/27/00:34:25

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: file system change notification
Date: 26 Aug 2001 22:01:11 GMT
Organization: Cornell University
Lines: 60
Sender: asu1 AT cornell DOT invalid (on slip-32-102-40-95.ny.us.prserv.net)
Message-ID: <Xns9109B74F0D8A6ASINANUNUR@132.236.56.8>
NNTP-Posting-Host: slip-32-102-40-95.ny.us.prserv.net
X-Trace: news01.cit.cornell.edu 998863271 25908 32.102.40.95 (26 Aug 2001 22:01:11 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 26 Aug 2001 22:01:11 GMT
User-Agent: Xnews/4.06.22
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

hello,

i would like to write a program that will watch a given directory (possibly 
one that it was started in) for any file creation/deletion operations.

I can do this in Windows using  the code snippet included at the bottom of 
this post. However, I would like to use djgpp. I am assuming there is no 
similar API in the libraries, and hence I should chain some DOS interrupts. 
(I could sit in a tight loop reading directory contents but I could miss 
some creations/deletions if they happen rapidly).

Anyway, I do not know where to begin so I would appreciate any pointers. 
Which DOS interrupt/API should I look for? Any hints?

Thanks

Sinan.

==== Win32 example ====
#include <stdio.h>
#include <stdlib.h>

#include <windows.h>

int main(void)
{
	DWORD wait_ret_code = 0;
	HANDLE h = INVALID_HANDLE_VALUE;
	
	h = FindFirstChangeNotification(".", 
			FALSE, 
			FILE_NOTIFY_CHANGE_SIZE | 
FILE_NOTIFY_CHANGE_LAST_WRITE);

	if( h == INVALID_HANDLE_VALUE )
	{
		fprintf(stderr, "Invalid handle registering for 
notification\n");
		exit(EXIT_FAILURE);
	}

	wait_ret_code = WaitForSingleObject(h, INFINITE);

	if( wait_ret_code == WAIT_FAILED )
	{
		fprintf(stderr, "Wait failed\n");
		exit(EXIT_FAILURE);
	}

	if( wait_ret_code == WAIT_OBJECT_0 )
	{
		fprintf(stderr, "Change notification received ...\n");
	}

	return 0;
}
-- 
--------------------------------
A. Sinan Unur
http://www.unur.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019