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

📄 lud_utils.c

📁 一个快速
💻 C
字号:
#include "LUD_Utils.h"

/***********************************************************************/
/*  FUNCTION:  void Assert(int assertion, char* error)  */
/**/
/*  INPUTS: assertion should be a predicated that the programmer */
/*  assumes to be true.  If this assumption is not true the message */
/*  error is printed and the program exits. */
/**/
/*  OUTPUT: None. */
/**/
/*  Modifies input:  none */
/**/
/*  Note:  If DEBUG_ASSERT is not defined then assertions should not */
/*         be in use as they will slow down the code.  Therefore the */
/*         compiler will complain if an assertion is used when */
/*         DEBUG_ASSERT is undefined. */
/***********************************************************************/


void Assert(int assertion, char* error) {
	if(!assertion) {
		printf("Assertion Failed: %s\n",error);
		exit(-1);
	}
}



/***********************************************************************/
/*  FUNCTION:  SafeMalloc */
/**/
/*    INPUTS:  size is the size to malloc */
/**/
/*    OUTPUT:  returns pointer to allocated memory if succesful */
/**/
/*    EFFECT:  mallocs new memory.  If malloc fails, prints error message */
/*             and terminates program. */
/**/
/*    Modifies Input: none */
/**/
/***********************************************************************/

void * SafeMalloc(size_t size) {
	void * result;

	if ( (result = malloc(size)) ) { /* assignment intentional */
		return(result);
	} else {
		printf("memory overflow: malloc failed in SafeMalloc.");
		printf("  Exiting Program.\n");
		exit(-1);
		return(0);
	}
}
/*  NullFunction does nothing it is included so that it can be passed */
/*  as a function to RBTreeCreate when no other suitable function has */
/*  been defined */

void NullFunction(void * junk) { ; }

int GetLineFromAFile(FILE* fp, wchar_t* buf){
	wchar_t tmp = 0;
	int i = 0;
	if(feof(fp) != 0)
		return EOF;
	for(i = 0; (tmp = fgetwc(fp)) != L'\n'; i++){
		if(tmp == 0xffff)
			return EOF;
		buf[i] = tmp;
	}

	buf[i] = L'\0';
	if(i == 0)
		return 1;
	return 0;
}

⌨️ 快捷键说明

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