utils.c
来自「采用UDP协议实现的UNIX/Linux环境下的聊天服务器和客户端程序」· C语言 代码 · 共 36 行
C
36 行
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <errno.h>//////////////////////////////////////////////////////////////////////// Utils functions//////////////////////////////////////////////////////////////////////char *safe_malloc(int size){ char *p = NULL; int retry = 5; while (retry > 0 && ((p = malloc(size)) == NULL)) { fprintf(stderr, "malloc() failed: %s\n", strerror(errno)); sleep(1); retry--; } return p;}void safe_free(void *p){ if (p) { fprintf(stdout, "DEBUG: try to free %p\n", p); free(p); p = NULL; } p = NULL;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?