Exemplo n.º 1
0
void AllocationFailureSimulator::checkOperation(int32_t targetType, size_t size) {
	(void) size;

	if (enabled_ && targetType == targetType_) {
		const uint64_t count = lastOperationCount_;
		lastOperationCount_++;

		if (startCount_ <= count && count < endCount_) {
			switch (targetType) {
			case TARGET_NEW:
				
				UTIL_THROW_UTIL_ERROR(CODE_NO_MEMORY,
						"Allocation failed");
			case TARGET_STACK_ALLOCATION:
				try {
					UTIL_THROW_UTIL_ERROR(CODE_NO_MEMORY,
							"Allocation failed");
				}
				catch (util::Exception &e) {
					StackAllocator::handleAllocationError(e);
				}
			}
		}
	}
}
Exemplo n.º 2
0
FILETIME FileLib::getFileTime(int64_t unixTime) {
	if (unixTime < 0) {
		UTIL_THROW_UTIL_ERROR(CODE_INVALID_PARAMETER,
				"Negative unix time");
	}
	const int64_t value = (unixTime * 10000 + UNIXTIME_FILETIME_EPOC_DIFF);
	FILETIME fileTime;
	fileTime.dwLowDateTime = static_cast<DWORD>(value);
	fileTime.dwHighDateTime = static_cast<DWORD>(value >> 32);
	return fileTime;
}
Exemplo n.º 3
0
int64_t FileLib::getUnixTime(
		tm &time, int32_t milliSecond, bool asLocalTimeZone) {
	if (milliSecond < 0 || milliSecond >= 1000) {
		UTIL_THROW_UTIL_ERROR(CODE_INVALID_PARAMETER,
				"Millisecond field out of range");
	}

	time_t unixTimeSec;
	if (asLocalTimeZone) {
		unixTimeSec = mktime(&time);
	}
	else {
		unixTimeSec = timegm(&time);
	}

	if (unixTimeSec == static_cast<time_t>(-1)) {
		UTIL_THROW_UTIL_ERROR(CODE_INVALID_PARAMETER,
				"Illegal time");
	}
	else {
		return static_cast<int64_t>(unixTimeSec) * 1000 +
				static_cast<int32_t>(milliSecond);
	}
}
Exemplo n.º 4
0
tm FileLib::getTM(int64_t unixTime, bool asLocalTimeZone) {
	if (unixTime < 0) {
		UTIL_THROW_UTIL_ERROR(CODE_INVALID_PARAMETER,
				"Negative unix time");
	}
	time_t unixTimeSec = static_cast<time_t>(unixTime / 1000);
	tm time;
	if (asLocalTimeZone) {
		if (localtime_r(&unixTimeSec, &time) == NULL) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
	}
	else {
		if (gmtime_r(&unixTimeSec, &time) == NULL) {
			UTIL_THROW_PLATFORM_ERROR(NULL);
		}
	}
	return time;
}