/*
* snprintf.c - a portable implementation of snprintf
*
* AUTHOR
* Mark Martinec <mark.martinec@ijs.si>, April 1999.
*
* Copyright 1999, Mark Martinec. All rights reserved.
*
* TERMS AND CONDITIONS
* This program is free software; you can redistribute it and/or modify
* it under the terms of the "Frontier Artistic License" which comes
* with this Kit.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Frontier Artistic License for more details.
*
* You should have received a copy of the Frontier Artistic License
* with this Kit in the file named LICENSE.txt .
* If not, I'll be glad to provide one.
*
* FEATURES
* - careful adherence to specs regarding flags, field width and precision;
* - good performance for large string handling (large format, large
* argument or large paddings). Performance is similar to system's sprintf
* and in several cases significantly better (make sure you compile with
* optimizations turned on, tell the compiler the code is strict ANSI
* if necessary to give it more freedom for optimizations);
* - return value semantics per ISO/IEC 9899:1999 ("ISO C99");
* - written in standard ISO/ANSI C - requires an ANSI C compiler.
*
* SUPPORTED CONVERSION SPECIFIERS AND DATA TYPES
*
* This snprintf only supports the following conversion specifiers:
* s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below)
* with flags: '-', '+', ' ', '0' and '#'.
* An asterisk is supported for field width as well as precision.
*
* Length modifiers 'h' (short int), 'l' (long int),
* and 'll' (long long int) are supported.
* NOTE:
* If macro SNPRINTF_LONGLONG_SUPPORT is not defined (default) the
* length modifier 'll' is recognized but treated the same as 'l',
* which may cause argument value truncation! Defining
* SNPRINTF_LONGLONG_SUPPORT requires that your system's sprintf also
* handles length modifier 'll'. long long int is a language extension
* which may not be portable.
*
* Conversion of numeric data (conversion specifiers d, u, o, x, X, p)
* with length modifiers (none or h, l, ll) is left to the system routine
* sprintf, but all handling of flags, field width and precision as well as
* c and s conversions is done very carefully by this portable routine.
* If a string precision (truncation) is specified (e.g. %.8s) it is
* guaranteed the string beyond the specified precision will not be referenced.
*
* Length modifiers h, l and ll are ignored for c and s conversions (data
* types wint_t and wchar_t are not supported).
*
* The following common synonyms for conversion characters are supported:
* - i is a synonym for d
* - D is a synonym for ld, explicit length modifiers are ignored
* - U is a synonym for lu, explicit length modifiers are ignored
* - O is a synonym for lo, explicit length modifiers are ignored
* The D, O and U conversion characters are nonstandard, they are supported
* for backward compatibility only, and should not be used for new code.
*
* The following is specifically NOT supported:
* - flag ' (thousands' grouping character) is recognized but ignored
* - numeric conversion specifiers: f, e, E, g, G and synonym F,
* as well as the new a and A conversion specifiers
* - length modifier 'L' (long double) and 'q' (quad - use 'll' instead)
* - wide character/string conversions: lc, ls, and nonstandard
* synonyms C and S
* - writeback of converted string length: conversion character n
* - the n$ specification for direct reference to n-th argument
* - locales
*
* It is permitted for str_m to be zero, and it is permitted to specify NULL
* pointer for resulting string argument if str_m is zero (as per ISO C99).
*
* The return value is the number of characters which would be generated
* for the given input, excluding the trailing null. If this value
* is greater or equal to str_m, not all characters from the result
* have been stored in str, output bytes beyond the (str_m-1) -th character
* are discarded. If str_m is greater than zero it is guaranteed
* the resulting string will be null-terminated.
*
* NOTE that this matches the ISO C99, OpenBSD, and GNU C library 2.1,
* but is different from some older and vendor implementations,
* and is also different from XPG, XSH5, SUSv2 specifications.
* For historical discussion on changes in the semantics and standards
* of snprintf see printf(3) man page in the Linux programmers manual.
*
* Routines asprintf and vasprintf return a pointer (in the ptr argument)
* to a buffer sufficiently large to hold the resulting string. This pointer
* should be passed to free(3) to release the allocated storage when it is
* no longer needed. If sufficient space cannot be allocated, these functions
* will return -1 and set ptr to be a NULL pointer. These two routines are a
* GNU C library extensions (glibc).
*
* Routines asnprintf and vasnprintf are similar to asprintf and vasprintf,
* yet, like snprintf and vsnprintf counterparts, will write at most str_m-1
* characters into the allocated output string, the last character in the
* allocated buffer then gets the terminating null. If the formatted string
* length (the return value) is greater than or equal to the str_m argument,
* the resulting string was truncated and some of the formatted characters
* were discarded. These routines present a handy way to limit the amount
* of allocated memory to some sane value.
*
* AVAILABILITY
* http://www.ijs.si/software/snprintf/
*
* REVISION HISTORY
* 1999-04 V0.9 Mark Martinec
* - initial version, some modifications after comparing printf
* man pages for Digital Unix 4.0, Solaris 2.6 and HPUX 10,
* and checking how Perl handles sprintf (differently!);
* 1999-04-09 V1.0 Mark Martinec <mark.martinec@ijs.si>
* - added main test program, fixed remaining inconsistencies,
* added optional (long long int) support;
* 1999-04-12 V1.1 Mark Martinec <mark.martinec@ijs.si>
* - support the 'p' conversion (pointer to void);
* - if a string precision is specified
* make sure the string beyond the specified precision
* will not be referenced (e.g. by strlen);
* 1999-04-13 V1.2 Mark Martinec <mark.martinec@ijs.si>
* - support synonyms %D=%ld, %U=%lu, %O=%lo;
* - speed up the case of long format string with few conversions;
* 1999-06-30 V1.3 Mark Martinec <mark.martinec@ijs.si>
* - fixed runaway loop (eventually crashing when str_l wraps
* beyond 2^31) while copying format string without
* conversion specifiers to a buffer that is too short
* (thanks to Edwin Young <edwiny@autonomy.com> for
* spotting the problem);
* - added macros PORTABLE_SNPRINTF_VERSION_(MAJOR|MINOR)
* to snprintf.h
* 2000-02-14 V2.0 (never released) Mark Martinec <mark.martinec@ijs.si>
* - relaxed license terms: The Artistic License now applies.
* You may still apply the GNU GENERAL PUBLIC LICENSE
* as was distributed with previous versions, if you prefer;
* - changed REVISION HISTORY dates to use ISO 8601 date format;
* - added vsnprintf (patch also independently proposed by
* Caolan McNamara 2000-05-04, and Keith M Willenson 2000-06-01)
* 2000-06-27 V2.1 Mark Martinec <mark.martinec@ijs.si>
* - removed POSIX check for str_m<1; value 0 for str_m is
* allowed by ISO C99 (and GNU C library 2.1) - (pointed out
* on 2000-05-04 by Caolan McNamara, caolan@ csn dot ul dot ie).
* Besides relaxed license this change in standards adherence
* is the main reason to bump up the major version number;
* - added nonstandard routines asnprintf, vasnprintf, asprintf,
* vasprintf that dynamically allocate storage for the
* resulting string; these routines are not compiled by default,
* see comments where NEED_V?ASN?PRINTF macros a
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
log4cpp 日志 源码 (114个子文件)
Makefile.am 1KB
Makefile.am 187B
snprintf.c 41KB
PatternLayout.cpp 14KB
PropertyConfiguratorImpl.cpp 13KB
Category.cpp 13KB
SimpleConfigurator.cpp 9KB
RemoteSyslogAppender.cpp 6KB
NTEventLogAppender.cpp 5KB
Properties.cpp 5KB
HierarchyMaintainer.cpp 4KB
RollingFileAppender.cpp 4KB
FileAppender.cpp 3KB
AppendersFactory.cpp 3KB
FixedContextCategory.cpp 3KB
Appender.cpp 3KB
NDC.cpp 2KB
SyslogAppender.cpp 2KB
IdsaAppender.cpp 2KB
StringUtil.cpp 2KB
AlurFrameWoks.Log.cpp 2KB
LayoutsFactory.cpp 2KB
Win32DebugAppender.cpp 2KB
TriggeringEventEvaluatorFactory.cpp 2KB
CategoryStream.cpp 1KB
Priority.cpp 1KB
AppenderSkeleton.cpp 1KB
Filter.cpp 1KB
StringQueueAppender.cpp 1KB
BufferingAppender.cpp 1KB
AbortAppender.cpp 1KB
TimeStamp.cpp 1KB
BasicLayout.cpp 1KB
SimpleLayout.cpp 1KB
OstreamAppender.cpp 990B
LayoutAppender.cpp 921B
DllMain.cpp 764B
LoggingEvent.cpp 755B
BasicConfigurator.cpp 698B
Localtime.cpp 611B
PortabilityImpl.cpp 585B
PropertyConfigurator.cpp 498B
FactoryParams.cpp 459B
MSThreads.cpp 413B
LevelEvaluator.cpp 405B
OmniThreads.cpp 404B
PThreads.cpp 393B
Configurator.cpp 346B
DummyThreads.cpp 301B
PassThroughLayout.cpp 251B
stdafx.cpp 222B
config-win32.h 3KB
convenience.h 3KB
config-openvms.h 2KB
stdafx.h 276B
Category.hh 22KB
NDC.hh 6KB
FixedContextCategory.hh 5KB
MSThreads.hh 5KB
FactoryParams.hh 5KB
OmniThreads.hh 5KB
RemoteSyslogAppender.hh 4KB
Appender.hh 4KB
CategoryStream.hh 4KB
Filter.hh 4KB
PatternLayout.hh 4KB
AppenderSkeleton.hh 3KB
PropertyConfiguratorImpl.hh 3KB
Priority.hh 3KB
StringUtil.hh 3KB
NTEventLogAppender.hh 3KB
PThreads.hh 3KB
FileAppender.hh 3KB
LoggingEvent.hh 2KB
SyslogAppender.hh 2KB
StringQueueAppender.hh 2KB
TimeStamp.hh 2KB
HierarchyMaintainer.hh 2KB
IdsaAppender.hh 2KB
SimpleConfigurator.hh 2KB
DummyThreads.hh 2KB
PropertyConfigurator.hh 2KB
Win32DebugAppender.hh 1KB
BoostThreads.hh 1KB
PortabilityImpl.hh 1KB
LayoutAppender.hh 1KB
RollingFileAppender.hh 1KB
Portability.hh 1KB
TriggeringEventEvaluatorFactory.hh 1KB
BufferingAppender.hh 1KB
AbortAppender.hh 1KB
AppendersFactory.hh 1012B
LayoutsFactory.hh 999B
Properties.hh 966B
Layout.hh 962B
OstreamAppender.hh 919B
BasicLayout.hh 836B
SimpleLayout.hh 826B
Threading.hh 779B
Configurator.hh 693B
共 114 条
- 1
- 2
资源评论
HeroAlur
- 粉丝: 16
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功