millisecond counts should round down (0-999).

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36751 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-06-24 16:48:22 +00:00
parent e8c56a5d9d
commit 4ab22b8130
2 changed files with 31 additions and 27 deletions

View file

@ -277,7 +277,7 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
m = m * 60; m = m * 60;
c = a - h - m; c = a - h - m;
*second = (NSInteger)c; *second = (NSInteger)c;
*mil = (NSInteger)((a - h - m - c) * 1000.0 + 0.5); *mil = (NSInteger)((a - h - m - c) * 1000.0);
} }
/** /**

View file

@ -108,7 +108,7 @@ GSLogLock()
} }
static void static void
_NSLog_standard_printf_handler (NSString* message) _NSLog_standard_printf_handler(NSString* message)
{ {
NSData *d; NSData *d;
const char *buf; const char *buf;
@ -190,30 +190,34 @@ _NSLog_standard_printf_handler (NSString* message)
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES if (GSPrivateDefaultsFlag(GSLogSyslog) == YES
|| write(_NSLogDescriptor, buf, len) != (int)len) || write(_NSLogDescriptor, buf, len) != (int)len)
{ {
// QNX's slog has a size limit per entry. We might need to iterate over /* QNX's slog has a size limit per entry. We might need to iterate over
// _SLOG_MAXSIZEd chunks of the buffer * _SLOG_MAXSIZEd chunks of the buffer
*/
const char *newBuf = buf; const char *newBuf = buf;
unsigned newLen = len; unsigned newLen = len;
// Allocate at most _SLOG_MAXSIZE bytes // Allocate at most _SLOG_MAXSIZE bytes
null_terminated_buf = malloc(sizeof(char) * MIN(newLen, _SLOG_MAXSIZE)); null_terminated_buf = malloc(sizeof(char) * MIN(newLen, _SLOG_MAXSIZE));
// If it's shorter than that, we never even enter the loop // If it's shorter than that, we never even enter the loop
while (newLen >= _SLOG_MAXSIZE) while (newLen >= _SLOG_MAXSIZE)
{ {
strncpy (null_terminated_buf, newBuf, (_SLOG_MAXSIZE - 1)); strncpy(null_terminated_buf, newBuf, (_SLOG_MAXSIZE - 1));
null_terminated_buf[_SLOG_MAXSIZE] = '\0'; null_terminated_buf[_SLOG_MAXSIZE] = '\0';
slogf(_SLOG_SETCODE(_SLOG_SYSLOG, 0), _SLOG_ERROR, "%s", null_terminated_buf); slogf(_SLOG_SETCODE(_SLOG_SYSLOG, 0), _SLOG_ERROR, "%s",
newBuf+= (_SLOG_MAXSIZE - 1); null_terminated_buf);
newLen-= (_SLOG_MAXSIZE - 1 ); 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. /* Write out the rest (which will be at most (_SLOG_MAXSIZE - 1) chars,
if (0 != newLen) * so the terminator still fits.
{ */
strncpy(null_terminated_buf, newBuf, newLen); if (0 != newLen)
null_terminated_buf[newLen] = '\0'; {
slogf(_SLOG_SETCODE(_SLOG_SYSLOG, 0), _SLOG_ERROR, "%s", null_terminated_buf); 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); free(null_terminated_buf);
} }
#else #else
@ -279,13 +283,13 @@ NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
* </p> * </p>
*/ */
void void
NSLog (NSString* format, ...) NSLog(NSString* format, ...)
{ {
va_list ap; va_list ap;
va_start (ap, format); va_start(ap, format);
NSLogv (format, ap); NSLogv(format, ap);
va_end (ap); va_end(ap);
} }
/** /**
@ -315,7 +319,7 @@ NSLog (NSString* format, ...)
* </p> * </p>
*/ */
void void
NSLogv (NSString* format, va_list args) NSLogv(NSString* format, va_list args)
{ {
NSString *prefix; NSString *prefix;
NSString *message; NSString *message;