mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Add support for logging to the QNX slog via NSLog().
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35450 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d86ea96c56
commit
1e852b259e
5 changed files with 191 additions and 7 deletions
|
@ -39,6 +39,16 @@
|
|||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#elif HAVE_SYS_SLOG_H
|
||||
// we are on a QNX-ish system, which has a syslog symbol somewhere, but it isn't
|
||||
// our syslog function (we use slogf().)
|
||||
# ifdef HAVE_SYSLOG
|
||||
# undef HAVE_SYSLOG
|
||||
# endif
|
||||
# include <sys/slog.h>
|
||||
# ifdef HAVE_SYS_SLOGCODES_H
|
||||
# include <sys/slogcodes.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define UNISTR(X) \
|
||||
|
@ -106,8 +116,8 @@ _NSLog_standard_printf_handler (NSString* message)
|
|||
#if defined(__MINGW__)
|
||||
LPCWSTR null_terminated_buf;
|
||||
#else
|
||||
#if defined(HAVE_SYSLOG)
|
||||
char *null_terminated_buf;
|
||||
#if defined(HAVE_SYSLOG) || defined(HAVE_SLOGF)
|
||||
char *null_terminated_buf = NULL;
|
||||
#endif
|
||||
#endif
|
||||
static NSStringEncoding enc = 0;
|
||||
|
@ -162,8 +172,8 @@ _NSLog_standard_printf_handler (NSString* message)
|
|||
NULL); // pointer to data
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#else
|
||||
|
||||
#if defined(HAVE_SYSLOG)
|
||||
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES
|
||||
|| write(_NSLogDescriptor, buf, len) != (int)len)
|
||||
|
@ -176,6 +186,36 @@ _NSLog_standard_printf_handler (NSString* message)
|
|||
|
||||
free(null_terminated_buf);
|
||||
}
|
||||
#elif defined(HAVE_SLOGF)
|
||||
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES
|
||||
|| write(_NSLogDescriptor, buf, len) != (int)len)
|
||||
{
|
||||
// QNX's slog has a size limit per entry. We might need to iterate over
|
||||
// _SLOG_MAXSIZEd chunks of the buffer
|
||||
const char *newBuf = buf;
|
||||
unsigned newLen = len;
|
||||
|
||||
// Allocate at most _SLOG_MAXSIZE bytes
|
||||
null_terminated_buf = malloc(sizeof(char) * MIN(newLen, _SLOG_MAXSIZE));
|
||||
// If it's shorter than that, we never even enter the loop
|
||||
while (newLen >= _SLOG_MAXSIZE)
|
||||
{
|
||||
strncpy (null_terminated_buf, newBuf, (_SLOG_MAXSIZE - 1));
|
||||
null_terminated_buf[_SLOG_MAXSIZE] = '\0';
|
||||
slogf(_SLOG_SETCODE(_SLOG_SYSLOG, 0), _SLOG_ERROR, "%s", null_terminated_buf);
|
||||
newBuf+= (_SLOG_MAXSIZE - 1);
|
||||
newLen-= (_SLOG_MAXSIZE - 1 );
|
||||
}
|
||||
// Write out the rest (which will be at most (_SLOG_MAXSIZE - 1) chars, so
|
||||
// the terminator still fits.
|
||||
if (0 != newLen)
|
||||
{
|
||||
strncpy(null_terminated_buf, newBuf, newLen);
|
||||
null_terminated_buf[newLen] = '\0';
|
||||
slogf(_SLOG_SETCODE(_SLOG_SYSLOG, 0), _SLOG_ERROR, "%s", null_terminated_buf);
|
||||
}
|
||||
free(null_terminated_buf);
|
||||
}
|
||||
#else
|
||||
write(_NSLogDescriptor, buf, len);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue