[BACK]Return to log.c CVS log [TXT][DIR] Up to [local] / blind

Diff for /blind/log.c between version 1.3 and 1.8

version 1.3, 2022/03/17 10:20:47 version 1.8, 2022/03/29 20:24:55
Line 14 
Line 14 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   
 #include <stdio.h>  #include <errno.h>
 #include <stdarg.h>  #include <stdarg.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
 #include <syslog.h>  #include <syslog.h>
 #include <time.h>  #include <time.h>
   
 static int  log_background;  static int  log_bgnd;
 static int  log_verbose;  static int  log_verb;
 const char *log_procname;  const char *log_name;
   
 void log_init(int, int);  void    log_init(int, int);
 void log_setv(int);  void    log_set(int);
 int  log_getv(void);  int     log_get(void);
 void log_info(const char *, ...)  void    log_send(const char *, va_list)
           __attribute__((__format__ (printf, 1, 0)));
   void    log_info(const char *, ...)
         __attribute__((__format__ (printf, 1, 2)));          __attribute__((__format__ (printf, 1, 2)));
 void log_debug(const char *, ...)  void    log_debug(const char *, ...)
         __attribute__((__format__ (printf, 1, 2)));          __attribute__((__format__ (printf, 1, 2)));
   __dead void log_fatal(const char *, ...)
           __attribute__((__format__ (printf, 1, 2)));
   
   
 void  void
 log_init(int background, int facility)  log_init(int background, int facility)
 {  {
         extern char *__progname;          extern char *__progname;
   
         if (__progname != NULL)          if (__progname != NULL)
                 log_procname = __progname;                  log_name = __progname;
   
         log_background = background;          log_bgnd = background;
         if (log_background)          if (log_bgnd)
                 openlog(log_procname, LOG_PID | LOG_NDELAY, facility);                  openlog(log_name, LOG_PID | LOG_NDELAY, facility);
   
         tzset();          tzset();
 }  }
   
 void  void
 log_setv(int verb)  log_set(int verb)
 {  {
         log_verbose = verb;          log_verb = verb;
 }  }
   
 int  int
 log_getv(void)  log_get(void)
 {  {
         return (log_verbose);          return (log_verb);
 }  }
   
 void  void
   log_send(const char *info, va_list ap)
   {
           if (info != NULL) {
                   if (log_bgnd)
                           vsyslog(LOG_INFO, info, ap);
                   else {
                           vfprintf(stderr, info, ap);
                           fprintf(stderr, "\n");
                   }
           }
   }
   
   void
 log_info(const char *info, ...)  log_info(const char *info, ...)
 {  {
         va_list ap;          va_list ap;
   
         va_start(ap, info);          va_start(ap, info);
           log_send(info, ap);
         if (log_background)  
                 vsyslog(LOG_INFO, info, ap);  
         else {  
                 vfprintf(stderr, info, ap);  
                 fprintf(stderr, "\n");  
         }  
   
         va_end(ap);          va_end(ap);
 }  }
   
Line 81  log_debug(const char *info, ...)
Line 93  log_debug(const char *info, ...)
 {  {
         va_list ap;          va_list ap;
   
         if (log_verbose) {          if (log_verb) {
                 va_start(ap, info);                  va_start(ap, info);
                   log_send(info, ap);
                 if (log_background)  
                         vsyslog(LOG_INFO, info, ap);  
                 else {  
                         vfprintf(stderr, info, ap);  
                         fprintf(stderr, "\n");  
                 }  
   
                 va_end(ap);                  va_end(ap);
         }          }
   }
   
   void
   log_fatal(const char *info, ...)
   {
           va_list ap;
   
           va_start(ap, info);
           log_send(info, ap);
           va_end(ap);
           log_info("%s", strerror(errno));
           exit(1);
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

https://cvs.kroczynski.net