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

📄 snprintf.c

📁 UNIX网络编程 第2卷 进程间通信 代码
💻 C
字号:
/* * Throughout the book I use snprintf() because it's safer than sprintf(). * But as of the time of this writing, not all systems provide this * function.  The function below should only be built on those systems * that do not provide a real snprintf(). * The function below just acts like sprintf(); it is not safe, but it * tries to detect overflow. */#include	"unpipc.h"#include	<stdarg.h>		/* ANSI C header file */intsnprintf(char *buf, size_t size, const char *fmt, ...){	int			n;	va_list		ap;	va_start(ap, fmt);	vsprintf(buf, fmt, ap);	/* Sigh, some vsprintf's return ptr, not length */	n = strlen(buf);	va_end(ap);	if (n >= size)		err_quit("snprintf: '%s' overflowed array", fmt);	return(n);}

⌨️ 快捷键说明

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