HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnprintf.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_ARCH_VSNPRINTF_H
25 #define PXR_BASE_ARCH_VSNPRINTF_H
26 
27 /// \file arch/vsnprintf.h
28 /// \ingroup group_arch_Strings
29 /// Architecture dependent memory-safe sprintf capability
30 
31 #include "pxr/pxr.h"
32 #include "pxr/base/arch/api.h"
34 
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <string>
38 
40 
41 /// \addtogroup group_arch_Strings
42 ///@{
43 
44 /// Return the number of characters (not including the null character)
45 /// necessary for a particular sprintf into a string.
46 ///
47 /// \c ArchVsnprintf guarantees the C99 behavior of vsnprintf on all systems:
48 /// it returns the number of bytes (not including the terminating null
49 /// character) needed to actually print the requested string. If \c size
50 /// indicates that \c str has enough capacity to hold the result, then the
51 /// function actually prints into \c str.
52 ///
53 /// You probably want to use the functionality of this call via
54 /// \c TfStringPrintf().
55 ///
57 int ArchVsnprintf(char *str, size_t size, const char *format, va_list ap)
58 #ifndef doxygen
59  ARCH_PRINTF_FUNCTION(3, 0)
60 #endif /* doxygen */
61  ;
62 
63 /// Returns a string formed by a printf()-like specification.
64 ///
65 /// \c ArchStringPrintf() is a memory-safe architecture-independent way of
66 /// forming a string using printf()-like formatting. For example,
67 /// \code
68 /// string formatMsg(const string& caller, int i, double val[])
69 /// {
70 /// return ArchStringPrintf("%s: val[%d] = %g\n", caller.c_str(), i, val[i]);
71 /// }
72 /// \endcode
73 ///
74 /// The function is safe only to the extent that the arguments match the
75 /// formatting string. In particular, be careful to pass strings themselve
76 /// into \c ArchStringPrintf() as in the above example (i.e. \c caller.c_str()
77 /// as opposed to just passing \c caller).
78 ///
80 std::string ArchStringPrintf(const char *fmt, ...)
81 #ifndef doxygen
82  ARCH_PRINTF_FUNCTION(1, 2)
83 #endif /* doxygen */
84  ;
85 
86 /// Returns a string formed by a printf()-like specification.
87 ///
88 /// \c ArchVStringPrintf() is equivalent to \c ArchStringPrintf() except that
89 /// it is called with a \c va_list instead of a variable number of arguments.
90 /// \c ArchVStringPrintf() does not call the \c va_end macro. Consequently,
91 /// the value of \c ap is undefined after the call. A functions that calls \c
92 /// ArchVStringPrintf() should call \c va_end(ap) itself afterwards.
93 ///
95 std::string ArchVStringPrintf(const char *fmt, va_list ap)
96 #ifndef doxygen
97  ARCH_PRINTF_FUNCTION(1, 0)
98  ;
99 #endif
100 
101 /// @}
102 
104 
105 #endif // PXR_BASE_ARCH_VSNPRINTF_H
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
ARCH_API std::string ArchVStringPrintf(const char *fmt, va_list ap)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
ARCH_API int ArchVsnprintf(char *str, size_t size, const char *format, va_list ap)
ARCH_API std::string ArchStringPrintf(const char *fmt,...)
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
#define ARCH_API
Definition: api.h:40