util.c
来自「一个FREE编译器原码」· C语言 代码 · 共 30 行
C
30 行
/*
* util.c - commonly used utility functions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
void *checked_malloc(int len)
{void *p = malloc(len);
if (!p) {
fprintf(stderr,"\nRan out of memory!\n");
exit(1);
}
return p;
}
string String(char *s)
{string p = checked_malloc(strlen(s)+1);
strcpy(p,s);
return p;
}
U_boolList U_BoolList(bool head, U_boolList tail)
{ U_boolList list = checked_malloc(sizeof(*list));
list->head = head;
list->tail = tail;
return list;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?