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 >
Wrap
C/C++ Source or Header
|
2008-07-13
|
2KB
|
91 lines
/* u_error.c
*
* Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
* All rights reserved.
*
*/
#include "syshdrs.h"
#ifdef PRAGMA_HDRSTOP
# pragma hdrstop
#endif
#define _CRT_SECURE_NO_WARNINGS 1
/*VARARGS*/
void
FTPLogError(const FTPCIPtr cip, const int pError, const char *const fmt, ...)
{
va_list ap;
int errnum;
size_t len;
char buf[256];
int endsinperiod;
int endsinnewline;
#ifndef HAVE_STRERROR
char errnostr[16];
#endif
errnum = errno;
va_start(ap, fmt);
#ifdef HAVE_VSNPRINTF
vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
buf[sizeof(buf) - 1] = '\0';
#else
(void) vsprintf(buf, fmt, ap);
#endif
va_end(ap);
if (pError != 0) {
len = strlen(buf);
endsinperiod = 0;
endsinnewline = 0;
if (len > 2) {
if (buf[len - 1] == '\n') {
endsinnewline = 1;
buf[len - 1] = '\0';
if (buf[len - 2] == '.') {
endsinperiod = 1;
buf[len - 2] = '\0';
}
} else if (buf[len - 1] == '.') {
endsinperiod = 1;
buf[len - 1] = '\0';
}
}
#ifdef HAVE_STRERROR
(void) STRNCAT(buf, ": ");
(void) STRNCAT(buf, strerror(errnum));
#else
# ifdef HAVE_SNPRINTF
snprintf(errnostr, sizeof(errnostr) - 1, " (errno = %d)", errnum);
errnostr[sizeof(errnostr) - 1] = '\0';
# else
sprintf(errnostr, " (errno = %d)", errnum);
# endif
STRNCAT(buf, errnostr);
#endif
if (endsinperiod != 0)
(void) STRNCAT(buf, ".");
if (endsinnewline != 0)
(void) STRNCAT(buf, "\n");
}
if (cip->errLog != NULL) {
(void) fprintf(cip->errLog, "%s", buf);
(void) fflush(cip->errLog);
}
if ((cip->debugLog != NULL) && (cip->debugLog != cip->errLog)) {
if ((cip->errLog != stderr) || (cip->debugLog != stdout)) {
(void) fprintf(cip->debugLog, "%s", buf);
(void) fflush(cip->debugLog);
}
}
if (cip->errLogProc != NULL) {
(*cip->errLogProc)(cip, buf);
}
if ((cip->debugLogProc != NULL) && (cip->debugLogProc != cip->errLogProc)) {
(*cip->debugLogProc)(cip, buf);
}
} /* FTPLogError */