Source

mtdupefind / Win32Questions / HeapAllocAlignmentQ / FindDupes.h

Full commit
#pragma once

#include <stdlib.h>

extern "C" {

#ifdef WIN32
typedef wchar_t FC_CHAR;
typedef wchar_t * const FD_PATH_IN;
typedef wchar_t * FD_PATH_OUT;
#define TWO_BYTE_CHAR
typedef DWORD FD_OS_ERRORCODE;
#else

typedef char FC_CHAR;
typedef char * const FD_PATH_IN;
typedef char * FD_PATH_OUT;
typedef int FD_OS_ERRORCODE;
#endif

typedef int FD_ERROR;
typedef void * FD_BATON;
typedef int FD_PATH_COUNT;
typedef void const*const FD_PATH_ID;
typedef int FD_GROUP_COUNT;
typedef int FD_GROUP_ID;
typedef long long FD_BYTE_COUNT;
typedef struct _FD_INSTANCE FD_INSTANCE; /* Opaque to allow implementation changes */

#define FD_SUCCESS 0
#define FD_ENOMEM 1
#define FD_EBUFFSMALL 2
#define FD_CALLAGAIN 3
#define FD_NOTADIR 4
#define FD_RESTART_FORBIDDEN 5
#define FD_NOT_IMPLEMENTED 6

typedef int (*FD_COMPLETION_CB)(FD_BATON);
typedef int (*FD_ERROR_CB)(FD_PATH_ID dirId, FD_OS_ERRORCODE, FD_BATON);
typedef int (*FD_FILEIO_ERROR_CB)(FD_PATH_ID fileId, FD_OS_ERRORCODE, FD_BYTE_COUNT loc, FD_BATON);
typedef int (*FD_SEARCHPROGRESS_CB)(FD_PATH_COUNT dirFound, FD_PATH_COUNT dirScanned, FD_PATH_COUNT files, FD_BYTE_COUNT bytes, FD_BATON);
typedef int (*FD_BYTEPROGRESS_CB)(FD_BYTE_COUNT found, FD_BYTE_COUNT compared, FD_BYTE_COUNT duplicated, FD_BATON);
typedef int (*FD_NEW_GROUP_CB)(FD_GROUP_ID groupId, FD_BATON);
typedef int (*FD_NEW_FILE_IN_GROUP_CB)(FD_GROUP_ID groupId, FD_PATH_ID fileId, FD_BATON);
typedef bool (*FD_INCLUDE_FILE)(FC_CHAR const*const path, FD_BATON);

/* setup, start, stop, cleanup. */
FD_INSTANCE* fd_init();
FD_ERROR fd_addpath(FD_INSTANCE*,FD_PATH_IN);
FD_ERROR fd_start(FD_INSTANCE*);
FD_ERROR fd_cancel(FD_INSTANCE*, FD_COMPLETION_CB, FD_BATON);
FD_ERROR fd_halt(FD_INSTANCE*); /* Equivelent to calling fd_cancel and waiting until the completion callback */
FD_ERROR fd_free(FD_INSTANCE*);

/* Reporting handler registration.
   Only one function can be registered at a time.
   Register a null func ptr to unregister. */
/* Error reporting will callback once for each error encountered. */
FD_ERROR fd_error(FD_INSTANCE*, FD_ERROR_CB, FD_BATON); /* non filesystem/io errors */
FD_ERROR fd_dirread_error(FD_INSTANCE*, FD_ERROR_CB, FD_BATON);
FD_ERROR fd_fileread_error(FD_INSTANCE*, FD_FILEIO_ERROR_CB, FD_BATON);
/* Completion reporting:  Will callback once, when that stage is complete. */
FD_ERROR fd_filesearch_complete(FD_INSTANCE*, FD_COMPLETION_CB, FD_BATON);
FD_ERROR fd_compare_complete(FD_INSTANCE*, FD_COMPLETION_CB, FD_BATON);
/* Progress reporting:  Called periodically to report progress. */
/* (Use the granularity parameter controll how often the callback fires) */
FD_ERROR fd_pathsearch_progress(FD_INSTANCE*, FD_PATH_COUNT granularity, FD_SEARCHPROGRESS_CB, FD_BATON);
FD_ERROR fd_bytescompared_progress(FD_INSTANCE*, FD_PATH_COUNT granularity, FD_BYTEPROGRESS_CB, FD_BATON);
/* Progress reporting:  Called as files are compared. */
FD_ERROR fd_new_group(FD_INSTANCE*, FD_NEW_GROUP_CB, FD_BATON);
FD_ERROR fd_new_file_in_group(FD_INSTANCE*, FD_GROUP_ID, FD_NEW_FILE_IN_GROUP_CB, FD_BATON);

/* Callback to ask your code to include or exclude a file */
FD_ERROR fd_include_file(FD_INSTANCE*, FD_INCLUDE_FILE, FD_BATON);

/* Use these to traverse groups */
FD_ERROR fd_get_first_group(FD_GROUP_ID*);
FD_ERROR fd_get_next_group(FD_GROUP_ID, FD_GROUP_ID*);
FD_ERROR fd_get_first_file_in_group(FD_GROUP_ID, FD_PATH_ID*);
FD_ERROR fd_get_next_file_in_group(FD_GROUP_ID, FD_PATH_ID, FD_PATH_ID*);

/*  Turn a file or directory id into a file or directory path.
	Writes a null terminated path string into your buffer, which you allocated
	to be buffsize bytes.
	if *buffsize<=0 or buff is null  
		*buffsize will set to the required size (including the null terminator)
		and FD_CALLAGAIN will be returned.
	if *buffsize>0 and buff is not null and the buffer is not sufficent to 
		hold the null terminated path string  *buffsize will be set to the
		required size.  (A number of bytes, less than or equal to pre-call
		value of *buffsize, _may_ be written to the memory pointed to by buff)
		and FD_EBUFFSMALL will be returned.
	if *buffsize>0 and buff is not null and the buffer is large enough
		The path (including null terminator) will be written to the memory
		pointer to by buff and FD_SUCCESS will be returned.
	* remember:  On widows and other platforms using wchar_t for path strings
	  buffsize is twice the number of wchar_t characters and the null
	  terminator will be 2 bytes */
FD_ERROR fd_getpath(FD_INSTANCE, FD_PATH_ID, int* buffsize, FD_PATH_OUT buff);
};