home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / u_error.c < prev    next >
C/C++ Source or Header  |  2008-07-13  |  2KB  |  91 lines

  1. /* u_error.c
  2.  *
  3.  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #include "syshdrs.h"
  9. #ifdef PRAGMA_HDRSTOP
  10. #    pragma hdrstop
  11. #endif
  12.  
  13. #define _CRT_SECURE_NO_WARNINGS 1
  14.  
  15. /*VARARGS*/
  16. void
  17. FTPLogError(const FTPCIPtr cip, const int pError, const char *const fmt, ...)
  18. {
  19.     va_list ap;
  20.     int errnum;
  21.     size_t len;
  22.     char buf[256];
  23.     int endsinperiod;
  24.     int endsinnewline;
  25. #ifndef HAVE_STRERROR
  26.     char errnostr[16];
  27. #endif
  28.  
  29.     errnum = errno;
  30.     va_start(ap, fmt);
  31. #ifdef HAVE_VSNPRINTF
  32.     vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
  33.     buf[sizeof(buf) - 1] = '\0';
  34. #else
  35.     (void) vsprintf(buf, fmt, ap);
  36. #endif
  37.     va_end(ap);
  38.  
  39.     if (pError != 0) {
  40.         len = strlen(buf);
  41.         endsinperiod = 0;
  42.         endsinnewline = 0;
  43.         if (len > 2) {
  44.             if (buf[len - 1] == '\n') {
  45.                 endsinnewline = 1;
  46.                 buf[len - 1] = '\0';
  47.                 if (buf[len - 2] == '.') {
  48.                     endsinperiod = 1;
  49.                     buf[len - 2] = '\0';
  50.                 }
  51.             } else if (buf[len - 1] == '.') {
  52.                 endsinperiod = 1;
  53.                 buf[len - 1] = '\0';
  54.             }
  55.         }
  56. #ifdef HAVE_STRERROR
  57.         (void) STRNCAT(buf, ": ");
  58.         (void) STRNCAT(buf, strerror(errnum));
  59. #else
  60. #    ifdef HAVE_SNPRINTF
  61.         snprintf(errnostr, sizeof(errnostr) - 1, " (errno = %d)", errnum);
  62.         errnostr[sizeof(errnostr) - 1] = '\0';
  63. #    else
  64.         sprintf(errnostr, " (errno = %d)", errnum);
  65. #    endif
  66.         STRNCAT(buf, errnostr);
  67. #endif
  68.         if (endsinperiod != 0)
  69.             (void) STRNCAT(buf, ".");
  70.         if (endsinnewline != 0)
  71.             (void) STRNCAT(buf, "\n");
  72.     }
  73.  
  74.     if (cip->errLog != NULL) {
  75.         (void) fprintf(cip->errLog, "%s", buf);
  76.         (void) fflush(cip->errLog);
  77.     }
  78.     if ((cip->debugLog != NULL) && (cip->debugLog != cip->errLog)) {
  79.         if ((cip->errLog != stderr) || (cip->debugLog != stdout)) {
  80.             (void) fprintf(cip->debugLog, "%s", buf);
  81.             (void) fflush(cip->debugLog);
  82.         }
  83.     }
  84.     if (cip->errLogProc != NULL) {
  85.         (*cip->errLogProc)(cip, buf);
  86.     }
  87.     if ((cip->debugLogProc != NULL) && (cip->debugLogProc != cip->errLogProc)) {
  88.         (*cip->debugLogProc)(cip, buf);
  89.     }
  90. }    /* FTPLogError */
  91.