"Fossies" - the Fresh Open Source Software Archive

Member "apg-2.2.3/errors.c" (7 Aug 2003, 3363 Bytes) of package /linux/privat/old/apg-2.2.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2 ** Copyright (c) 1999, 2000, 2001, 2002, 2003
    3 ** Adel I. Mirzazhanov. All rights reserved
    4 **
    5 ** Redistribution and use in source and binary forms, with or without
    6 ** modification, are permitted provided that the following conditions
    7 ** are met:
    8 ** 
    9 **     1.Redistributions of source code must retain the above copyright notice,
   10 **       this list of conditions and the following disclaimer. 
   11 **     2.Redistributions in binary form must reproduce the above copyright
   12 **       notice, this list of conditions and the following disclaimer in the
   13 **       documentation and/or other materials provided with the distribution. 
   14 **     3.The name of the author may not be used to endorse or promote products
   15 **       derived from this software without specific prior written permission. 
   16 **        
   17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND ANY EXPRESS
   18 ** OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO, THE IMPLIED
   19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20 ** ARE DISCLAIMED.  IN  NO  EVENT  SHALL THE AUTHOR BE LIABLE FOR ANY
   21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE
   23 ** GOODS OR SERVICES;  LOSS OF USE,  DATA,  OR  PROFITS;  OR BUSINESS
   24 ** INTERRUPTION)  HOWEVER  CAUSED  AND  ON  ANY  THEORY OF LIABILITY,
   25 ** WHETHER  IN  CONTRACT,   STRICT   LIABILITY,  OR  TORT  (INCLUDING
   26 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   27 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   28 */
   29 
   30 #include <stdio.h>
   31 #include <string.h>
   32 #include <unistd.h>
   33 #include <stdlib.h>
   34 #include "errs.h"
   35 
   36 #ifdef CLISERV
   37 #  include <syslog.h>
   38 #endif
   39 
   40 /*
   41 ** err_sys() - routine that handles non-fatal system errors
   42 ** like calloc, open, etc.
   43 ** INPUT:
   44 **   const char * - error name.
   45 ** OUTPUT:
   46 **   prints error to stderr.
   47 ** NOTES:
   48 **   none.
   49 */
   50 void
   51 err_sys(const char *string)
   52 {
   53 
   54 #ifndef CLISERV
   55  perror(string);
   56 #else
   57  syslog (LOG_DEBUG, "%s: %s",string, (char *)strerror(errno));
   58 #endif
   59 }
   60 
   61 /*
   62 ** err_sus_fatal() - routine that handles fatal system errors
   63 ** like calloc, open, etc.
   64 ** INPUT:
   65 **   const char * - error name.
   66 ** OUTPUT:
   67 **   prints error to stderr and then exit.
   68 ** NOTES:
   69 **   none.
   70 */
   71 void
   72 err_sys_fatal(const char *string)
   73 {
   74 
   75 #ifndef CLISERV
   76  perror(string);
   77 #else
   78  syslog (LOG_DEBUG, "%s: %s", string, (char *)strerror(errno));
   79  closelog();
   80  close(0);
   81 #endif
   82  exit (-1);
   83 }
   84 
   85 /*
   86 ** err_app() - routine that handles non-fatal application errors.
   87 ** INPUT:
   88 **   const char * - error name.
   89 **   const char * - error description.
   90 ** OUTPUT:
   91 **   prints error to stderr.
   92 ** NOTES:
   93 **   none.
   94 */
   95 void
   96 err_app(const char *string, const char * err)
   97 {
   98 #ifndef CLISERV
   99  fprintf (stderr, "%s: ", string);
  100  fprintf (stderr, "%s\n", err);
  101  fflush (stderr);
  102 #else
  103  syslog (LOG_DEBUG, "%s: %s",string, err);
  104 #endif
  105 }
  106 
  107 /*
  108 ** err_app_fatal() - routine that handles fatal application errors.
  109 ** INPUT:
  110 **   const char * - error name.
  111 **   const char * - error description.
  112 ** OUTPUT:
  113 **   prints error to stderr and then exit.
  114 ** NOTES:
  115 **   none.
  116 */
  117 void
  118 err_app_fatal(const char *string, const char *err)
  119 {
  120 
  121 #ifndef CLISERV
  122  fprintf (stderr, "%s: ", string);
  123  fprintf (stderr, "%s\n", err);
  124  fflush (stderr);
  125 #else
  126  syslog (LOG_DEBUG, "%s: %s",string, err);
  127  closelog();
  128  close(0);
  129 #endif
  130  exit (-1);
  131 }