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

📄 d_printf.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
字号:
/* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. * * d_printf.c: debugging messages. Can be easily compiled out by *   setting the -DNDEBUG flag. Verbosity level controlled by setting *   the environment variable DEBUG_LEVEL. If DEBUG_LEVEL = -1, then *   _all_ debugging messages will be printed. Otherwise, only those *   messages with a debug level less than DEBUG_LEVEL will be printed *   (so DEBUG_LEVEL = 0 produces no messages). * * $Id: d_printf.c,v 1.2 2003/09/17 11:26:10 tmoerlan Exp $ */#ifdef __KERNEL__#include <linux/kernel.h>#else#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <sys/time.h>#include "d_printf.h"#endif /* __KERNEL__ */int debug_level = 0;int debug_level_setp = 0;void set_debug_level_int(int newdebuglvl){#ifdef __KERNEL__  debug_level = -1;#else  char *env_val;  sysctl_snap_debug_level = newdebuglvl;  env_val = getenv("DEBUG_LEVEL");  if (env_val != NULL) {    sysctl_snap_debug_level = atoi(env_val);  }#endif /* __KERNEL__ */  debug_level_setp = 1;}void set_debug_level(void) {	set_debug_level_int(5);}void d_printf(int lvl, char* fmt, ...){  va_list ap;  if (!debug_level_setp) {    set_debug_level();  }  if (sysctl_snap_debug_level == -1 || lvl <= sysctl_snap_debug_level) {    va_start(ap,fmt);#ifdef __KERNEL__	/* TODO : add kernel version of gettimeofday */	printk(fmt,ap);#else#ifdef DEBUG_TIMED_ALL	{	struct timeval tNow;	/* get the time */	gettimeofday(&tNow,NULL);	fprintf(stderr,"%lu | ",(unsigned long) ((tNow.tv_sec * 1000000) + tNow.tv_usec));	}#endif	vfprintf(stderr,fmt,ap);#endif /* __KERNEL__ */	va_end(ap);  }}void d_printf_timed(int lvl, char* fmt, ...){  va_list ap;  if (!debug_level_setp) {    set_debug_level();  }  if (sysctl_snap_debug_level == -1 || lvl <= sysctl_snap_debug_level) {    va_start(ap,fmt);#ifdef __KERNEL__	/* TODO : add kernel version of gettimeofday */	printk(fmt,ap);#else	{	struct timeval tNow;	/* get the time */	gettimeofday(&tNow,NULL);	fprintf(stderr,"%lu | ",(unsigned long) ((tNow.tv_sec * 1000000) + tNow.tv_usec));	vfprintf(stderr,fmt,ap);	}#endif /* __KERNEL__ */	va_end(ap);  }}

⌨️ 快捷键说明

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