#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <windows.h>

#if _MSC_VER
	#define PFS_U64 "%I64u"
	typedef unsigned __int64 U64;
#else
	#define PFS_U64 "%llu"
	typedef unsigned long long U64;
#endif

int main(int argc, const char* argv[])
{
	if (argc < 2)
	{
		printf("Error: insufficient args.\n");
		exit(1);
	}

#if 0
	// Call Win32 GetFileAttributes.()
	printf("Checking file \"%s\"...\n", argv[1]);
	DWORD uAttr = GetFileAttributes(argv[1]);
	if (uAttr == (unsigned int)-1)
	{
		printf("GetFileAttributes() failed; error is 0x%08x.\n", GetLastError());
	}
	else
	{
		printf("GetFileAttributes(): 0x%08x\n", uAttr);
	}
#endif

#if 1
	// Call Win32 GetFileAttributesEx.()
	printf("Checking file \"%s\"...\n", argv[1]);
	WIN32_FILE_ATTRIBUTE_DATA myInfo;
	BOOL bOk = GetFileAttributesEx(argv[1], GetFileExInfoStandard, &myInfo);
	if (!bOk)
	{
		printf("GetFileAttributesEx() failed; error is 0x%08x.\n", GetLastError());
	}
	else
	{
		U64 uFileSize = ((U64)myInfo.nFileSizeHigh << 32) | (U64)myInfo.nFileSizeLow;
		printf("GetFileAttributesEx(): attr=0x%08x, size=" PFS_U64 "\n", myInfo.dwFileAttributes, uFileSize);
	}
#endif

	// Call stat().
	struct stat myStat;
	stat(argv[1], &myStat);
	printf(
		"stat(): mode=0x%04x, size=%lu\n", 
		myStat.st_mode, myStat.st_size
	);

	// Exit.
	return(0);
}

