Crypt-MatrixSSL

 view release on metacpan or  search on metacpan

matrixssl-1-8-6-open/src/os/win/win.c  view on Meta::CPAN

	CryptReleaseContext(hProv, 0);
	psCloseMalloc();
	return 0;
}

int32 sslGetEntropy(unsigned char *bytes, int32 size)
{
	if (CryptGenRandom(hProv, size, bytes)) {
		return size;
	}
	return -1;
}

#ifdef DEBUG
void psBreak()
{
	int32	i = 0; i++;	/* Prevent the compiler optimizing this function away */

	DebugBreak();
}
#endif

int32 sslInitMsecs(sslTime_t *t)
{
	__int64		diff;
	int32			d;

	QueryPerformanceCounter(t);
	diff = t->QuadPart - hiresStart.QuadPart;
	d = (int32)((diff * 1000) / hiresFreq.QuadPart);
	return d;
}

int32 sslDiffSecs(sslTime_t then, sslTime_t now)
{
	__int64	diff;

	diff = now.QuadPart - then.QuadPart;
	return (int32)(diff / hiresFreq.QuadPart);
}

/*
	Time comparison.  1 if 'a' is less than or equal.  0 if 'a' is greater
*/
int32 sslCompareTime(sslTime_t a, sslTime_t b)
{
	if (a.QuadPart <= b.QuadPart) {
		return 1;
	}
	return 0;
}

#ifdef WINCE
/******************************************************************************/
/*
 	Our implementation of wide character stat: get file information.
 
 	NOTES:
 		only gets the file size currently
 */
int32 stat(char *filename, struct stat *sbuf)
{
	DWORD	dwAttributes;
	HANDLE	hFile;
	int32		rc, size;

	unsigned short uniFile[512];

	rc = 0;
	memset(sbuf, 0, sizeof(struct stat));

	MultiByteToWideChar(CP_ACP, 0, filename, -1, uniFile, 256);
	dwAttributes = GetFileAttributes(uniFile);
	if (dwAttributes != 0xFFFFFFFF && dwAttributes & FILE_ATTRIBUTE_DIRECTORY) {
		sbuf->st_mode = S_IFDIR;
		return 0;
	}
	sbuf->st_mode = S_IFREG;

	if ((hFile = CreateFile(uniFile, GENERIC_READ, FILE_SHARE_READ && FILE_SHARE_WRITE, NULL,
		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
		return -1;
	}
	
/*
 *	 Get the file size.
 */
	size = GetFileSize(hFile, NULL);
	sbuf->st_size = size;
	
	CloseHandle(hFile);
	return rc;
}

/******************************************************************************/
/*
 	The following functions implement a unixlike time() function.
 */

static FILETIME YearToFileTime(WORD wYear)
{	
	SYSTEMTIME sbase;
	FILETIME fbase;

	sbase.wYear         = wYear;
	sbase.wMonth        = 1;
	sbase.wDayOfWeek    = 1; //assumed
	sbase.wDay          = 1;
	sbase.wHour         = 0;
	sbase.wMinute       = 0;
	sbase.wSecond       = 0;
	sbase.wMilliseconds = 0;

	SystemTimeToFileTime( &sbase, &fbase );

	return fbase;
}

time_t time() {

	__int64 time1, time2, iTimeDiff;



( run in 0.757 second using v1.01-cache-2.11-cpan-39bf76dae61 )