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

📄 log.c

📁 实战的linux socket编程--示例源码
💻 C
字号:
/* log.c * * Logging Functions: */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <errno.h>static FILE *logf = NULL;      /* Log File *//* * Open log file for append: * * RETURNS: *  0   Success *  -1  Failed. */intlog_open(const char *pathname) {        logf = fopen(pathname,"a");    return logf ? 0 : -1;}/* * Log information to a file: */voidlog(const char *format,...) {    va_list ap;    if ( !logf )        return;        /* No log file open */    fprintf(logf,"[PID %ld] ",(long)getpid());    va_start(ap,format);    vfprintf(logf,format,ap);    va_end(ap);    fflush(logf);}/* * Close the log file : */voidlog_close(void) {    if ( logf )        fclose(logf);    logf = NULL;}/* * This function reports the error to * the log file and calls exit(1). */voidbail(const char *on_what) {    if ( logf ) {          /* Is log open? */        if ( errno )             /* Error? */            log("%s: ",strerror(errno));        log("%s\n",on_what);    /* Log msg */        log_close();    }    exit(1);}

⌨️ 快捷键说明

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