mallocs.c
来自「在网络中,有时候会想检查自己电脑的端口的状态,这是端口扫描器的C语言源代码,」· C语言 代码 · 共 45 行
C
45 行
/* * mymalloc, myrealloc, dupstr - memory allocation with error handling * * Environment: POSIX, ANSI * * Author: Wietse Venema. */#include <stdlib.h>#include <unistd.h>#include <string.h>#include "lib.h"/* mymalloc - allocate memory or bust */char *mymalloc(len)int len;{ char *ptr; if ((ptr = malloc(len)) == 0) error("Insufficient memory: %m"); return (ptr);}/* myrealloc - reallocate memory or bust */char *myrealloc(ptr, len)char *ptr;int len;{ if ((ptr = realloc(ptr, len)) == 0) error("Insufficient memory: %m"); return (ptr);}/* dupstr - save string to heap */char *dupstr(str)char *str;{ return (strcpy(mymalloc(strlen(str) + 1), str));}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?