⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vsnprintf.c

📁 nasm早期的源代码,比较简单是学习汇编和编译原理的好例子
💻 C
字号:
/*
 * vsnprintf()
 *
 * Poor substitute for a real vsnprintf() function for systems
 * that don't have them...
 */

#include "compiler.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "nasmlib.h"

extern efunc nasm_malloc_error;

#define BUFFER_SIZE	65536	/* Bigger than any string we might print... */

static char snprintf_buffer[BUFFER_SIZE];

int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
    int rv, bytes;

    if (size > BUFFER_SIZE) {
	nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
			  "snprintf: size (%d) > BUFFER_SIZE (%d)",
			  size, BUFFER_SIZE);
	size = BUFFER_SIZE;
    }

    rv = vsprintf(snprintf_buffer, format, ap);
    if (rv >= BUFFER_SIZE) {
	nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
			  "snprintf buffer overflow");
    }

    if (size > 0) {
	if ((size_t)rv < size-1)
	    bytes = rv;
	else
	    bytes = size-1;

	memcpy(str, snprintf_buffer, bytes);
	str[bytes] = '\0';
    }

    return rv;
}

⌨️ 快捷键说明

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