📄 error.c
字号:
/* ---------------------------------------------------------------------------- CFL - A C Foundation Library Copyright (C) 1994-2003 Mark A Lindner This file is part of CFL. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ---------------------------------------------------------------------------- $Log: error.c,v $ Revision 1.2 2003/03/14 09:02:30 markl Code cleanup & bug fixes. Revision 1.1 2003/03/03 08:20:07 markl Initial checkin (clean compile on Solaris & OS X) ----------------------------------------------------------------------------*//* Feature test switches */#include "config.h"/* System headers */#include <errno.h>#include <stdio.h>#include <stdarg.h>#include <string.h>#ifdef THREADED_LIBRARY#include <pthread.h>#endif /* THREADED_LIBRARY *//* Local headers */#include "cfl/defs.h"#include "cfl/system.h"#include "cfl/cerrno.h"/* File scope variables */static char *__C_error_progname = "<program>";#ifdef THREADED_LIBRARYstatic pthread_once_t __C_error_once = PTHREAD_ONCE_INIT;static pthread_key_t __C_error_key;#else /* THREADED_LIBRARY */static int __c_errno = 0; /* global CFL error number */#endif /* THREADED_LIBRARY *//* Functions */void C_error_init(const char *progname) { if(progname) __C_error_progname = (char *)progname; }/* */void C_error_printf(const char *fmt, ...) { va_list vp;#ifdef THREADED_LIBRARY#ifdef HAVE_FLOCKFILE flockfile(stderr);#endif /* HAVE_FLOCKFILE */#endif /* THREADED_LIBRARY */ fprintf(stderr, "%s: ", __C_error_progname); va_start(vp, fmt); vfprintf(stderr, fmt, vp); va_end(vp); fflush(stderr);#ifdef THREADED_LIBRARY#ifdef HAVE_FLOCKFILE funlockfile(stderr);#endif /* HAVE_FLOCKFILE */#endif /* THREADED_LIBRARY */ }/* */void C_error_usage(const char *usage) { fprintf(stderr, "%s: Usage: %s %s\n", __C_error_progname, __C_error_progname, usage); fflush(stderr); }/* */void C_error_syserr(void) {#ifdef THREADED_LIBRARY#ifdef HAVE_FLOCKFILE flockfile(stderr);#endif /* HAVE_FLOCKFILE */#endif /* THREADED_LIBRARY */ fprintf(stderr, "%s: %s\n", __C_error_progname, strerror(errno)); fflush(stderr);#ifdef THREADED_LIBRARY#ifdef HAVE_FLOCKFILE funlockfile(stderr);#endif /* HAVE_FLOCKFILE */#endif /* THREADED_LIBRARY */ }/* */#ifdef THREADED_LIBRARYstatic void __C_error_destructor(void *datum) { C_free(datum); }/* */static void __C_error_init_once(void) { pthread_key_create(&__C_error_key, __C_error_destructor); }#endif /* THREADED_LIBRARY *//* */int C_error_get_errno(void) {#ifdef THREADED_LIBRARY int *e; pthread_once(&__C_error_once, __C_error_init_once); e = (int *)pthread_getspecific(__C_error_key); if(!e) { /* didn't exist, so create it */ e = C_new(int); *e = C_EOK; pthread_setspecific(__C_error_key, (void *)e); } return(*e);#else return(__c_errno);#endif /* THREADED_LIBRARY */ }/* */void C_error_set_errno(int err) {#ifdef THREADED_LIBRARY int *e; pthread_once(&__C_error_once, __C_error_init_once); e = (int *)pthread_getspecific(__C_error_key); if(!e) { /* didn't exist, so create it */ e = C_new(int); pthread_setspecific(__C_error_key, (void *)e); } *e = err;#else /* THREADED_LIBRARY */ __c_errno = err;#endif /* THREADED_LIBRARY */ }/* end of source file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -