oaa-windows.c

来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 75 行

C
75
字号
#ifdef _WINDOWS
#include <windows.h>
#include <stdio.h>
#include "oaa-windows.h"

enum { SNPRINTF_BUFFER_SIZE=300 };

/**
 * Implementation of snprintf on Windows. On Unix, it is ok
 * to pass a NULL buffer to the snprintf function. However, Windows
 * throws an error. For this reason, on Windows the snprintf function
 * is defined as win_oaa_snprintf. The win_oaa_snprintf function
 * checks if the buffer is null. If the buffer is null, a scratch
 * buffer is supplied. Note that this solution only works for
 * a single-threaded application. The scratch buffer is static and
 * should not be used in a multithreaded app.
 */
int win_oaa_snprintf(char *buffer, size_t count, const char *format, ...) {
	int ret = 0;
	static char scratch_buffer[SNPRINTF_BUFFER_SIZE];
	va_list args;
	va_start(args, format);
	if (buffer != NULL) {
		ret = _vsnprintf(buffer, count, format, args);
	} else {
		ret = _vsnprintf(scratch_buffer, SNPRINTF_BUFFER_SIZE, format, args);
	}
	va_end(args);
	return ret;
}

/**
 * Implementation of strtoll on Windows. This implementation uses
 * the _atoi64 method for base 10. This method only supports
 * base 10.
 */
__int64 strtoll(const char *nptr, char **endptr, int base) {
	// Only base 10 is supported by this function!
	if (base == 10) {
		char *itr = (char*)nptr;
		while ((*itr) != '\0') {
			itr++;
		}
		*endptr = itr;
		return _atoi64(nptr);
	} else {
		fprintf(stderr, "Error: strtoll only implemented for base 10");
		return 0;
	}
}
#endif

/**
 * @defgroup Windows Windows
 *
 * Implementation of some Unix-style functions to support
 * the Windows version of OAA.
 *
 * @{
 */

/**
 * @file oaa-windows.h
 * Contains windows-specific typedefs for compiling
 * oaa on windows.
 */

/**
 * @file oaa-windows.c
 * Implementation of some Unix-style functions to support
 * the Windows version of OAA.
 */

/** @} */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?