📄 exit.c
字号:
/******************************************************************************* ** Copyright (C) 1992-1996 Tony Robinson and SoftSound Limited ** ** See the file LICENSE for conditions on distribution and usage ** *******************************************************************************/# include <stdio.h># include <stdlib.h># include <string.h>#ifndef MSDOS# include <unistd.h># include <errno.h>extern char *sys_errlist[];#endif# include <setjmp.h># ifdef HAVE_STDARG_H# include <stdarg.h># else# include <varargs.h># endif# include "shorten.h"extern char *argv0;extern char *filenameo;extern FILE *fileo;#ifdef _WINDOWS/* mrhmod - warn about attempt to use stderr (use perror_exit()/error_exit() instead) */char *stderrWarningMsg = "caught attempt to use stderr";#endifjmp_buf exitenv;char *exitmessage;/***************************************************************************/void basic_exit(exitcode) int exitcode; { /* try to delete the output file on all abnormal exit conditions */ if(exitcode != 0 && fileo != NULL && fileo != stdout) { fclose(fileo); unlink(filenameo); } if(exitmessage == NULL) exit(exitcode < 0 ? 0 : exitcode); else longjmp(exitenv, exitcode);}/****************************************************************************** error_exit() - standard error handler with printf() syntax*/# ifdef HAVE_STDARG_Hvoid error_exit(char* fmt, ...) { va_list args; va_start(args, fmt);# elsevoid error_exit(va_alist) va_dcl { va_list args; char *fmt; va_start(args); fmt = va_arg(args, char*);# endif if(exitmessage == NULL) {#if defined(_WINDOWS) && defined(_DEBUG) _asm { int 3 } /* mrhmod - catch if debugging */#endif #ifndef _WINDOWS /* mrhmod - must use exitmessage 'cos stderr not available */ fprintf(stderr, "%s: ", argv0); (void) vfprintf(stderr, fmt, args);#endif /* _WINDOWS */ } else { (void) vsprintf(exitmessage, fmt, args); strcat(exitmessage, "\n"); } va_end(args); basic_exit(errno);}/****************************************************************************** perror_exit() - system error handler with printf() syntax**** Appends system error message based on errno*/# ifdef HAVE_STDARG_Hvoid perror_exit(char* fmt, ...) { va_list args; va_start(args, fmt);# elsevoid perror_exit(va_alist) va_dcl { va_list args; char *fmt; va_start(args); fmt = va_arg(args, char*);# endif if(exitmessage == NULL) {#if defined(_WINDOWS) && defined(_DEBUG) _asm { int 3 } /* mrhmod - catch if debugging */#endif #ifndef _WINDOWS /* mrhmod - must use exitmessage 'cos stderr not available */ fprintf(stderr, "%s: ", argv0); (void) vfprintf(stderr, fmt, args); (void) fprintf(stderr, ": ");#ifndef MSDOS perror("\0");#endif #endif /* _WINDOWS */ } else { (void) vsprintf(exitmessage, fmt, args); strcat(exitmessage, ": "); strcat(exitmessage, sys_errlist[errno]); strcat(exitmessage, "\n"); } va_end(args); basic_exit(errno);}# ifdef HAVE_STDARG_Hvoid usage_exit(int exitcode, char* fmt, ...) { va_list args; va_start(args, fmt);# elsevoid usage_exit(va_alist) va_dcl { va_list args; int exitcode; char *fmt; va_start(args); exitcode = va_arg(args, int); fmt = va_arg(args, char*);# endif if(exitmessage == NULL) {#if defined(_WINDOWS) && defined(_DEBUG) _asm { int 3 } /* mrhmod - catch if debugging */#endif #ifndef _WINDOWS /* mrhmod - must use exitmessage 'cos stderr not available */ if(fmt != NULL) { fprintf(stderr, "%s: ", argv0); (void) vfprintf(stderr, fmt, args); } fprintf(stderr, "%s: for more information use: %s -h\n", argv0, argv0);#endif /* _WINDOWS */ } va_end(args); basic_exit(exitcode);}# ifdef HAVE_STDARG_Hvoid update_exit(int exitcode, char* fmt, ...) { va_list args; va_start(args, fmt);# elsevoid update_exit(va_alist) va_dcl { va_list args; int exitcode; char *fmt; va_start(args); exitcode = va_arg(args, int); fmt = va_arg(args, char*);# endif if(exitmessage == NULL) {#if defined(_WINDOWS) && defined(_DEBUG) _asm { int 3 } /* mrhmod - catch if debugging */#endif#ifndef _WINDOWS /* mrhmod - must use exitmessage 'cos stderr not available */ if(fmt != NULL) { fprintf(stderr, "%s: ", argv0); (void) vfprintf(stderr, fmt, args); } fprintf(stderr, "%s: version %d.%s\n",argv0,FORMAT_VERSION,BUGFIX_RELEASE); fprintf(stderr, "%s: please report this problem to ajr@softsound.com\n", argv0);#endif /* _WINDOWS */ }#ifdef _WINDOWS /* mrhmod - output something */ error_exit( exitcode, fmt, args );#endif va_end(args); basic_exit(exitcode);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -