OpenMPI  0.1.1
printf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  * University Research and Technology
4  * Corporation. All rights reserved.
5  * Copyright (c) 2004-2005 The University of Tennessee and The University
6  * of Tennessee Research Foundation. All rights
7  * reserved.
8  * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
9  * University of Stuttgart. All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  * All rights reserved.
12  * $COPYRIGHT$
13  *
14  * Additional copyrights may follow
15  *
16  * $HEADER$
17  */
18 
19 /** @file
20  *
21  * Buffer safe printf functions for portability to archaic platforms.
22  */
23 
24 #ifndef OPAL_PRINTF_H
25 #define OPAL_PRINTF_H
26 
27 #include "opal_config.h"
28 
29 #include <stdarg.h>
30 #include <stdlib.h>
31 
32 BEGIN_C_DECLS
33 
34 /**
35  * Writes to a string under the control of a format string
36  * that specifies how subsequent arguments are converted for output.
37  *
38  * @param str Output string buffer
39  * @param size Size of string buffer
40  * @param fmt Output format
41  * @return Length of output string
42  *
43  * At most size-1 characters are printed into the output string (the
44  * size'th character then gets the terminating `\0'); if the return
45  * value is greater than or equal to the size argument, the string was
46  * too short and some of the printed characters were discarded. The
47  * output is always null-terminated.
48  *
49  * Returns the number of characters that would have been printed if
50  * the size were unlimited (again, not including the final `\0').
51  *
52  * THIS IS A PORTABILITY FEATURE: USE snprintf() in CODE.
53  */
54 OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt, ...) __opal_attribute_format__(__printf__, 3, 4);
55 
56 
57 /**
58  * Writes to a string under the control of a format string that
59  * specifies how arguments accessed via the variable-length argument
60  * facilities of stdarg(3) are converted for output.
61  *
62  * @param str Output string buffer
63  * @param size Size of string buffer
64  * @param fmt Output format
65  * @param ap Variable argument list pointer
66  * @return Length of output string
67  *
68  * At most size-1 characters are printed into the output string (the
69  * size'th character then gets the terminating `\0'); if the return
70  * value is greater than or equal to the size argument, the string was
71  * too short and some of the printed characters were discarded. The
72  * output is always null-terminated.
73  *
74  * Returns the number of characters that would have been printed if
75  * the size were unlimited (again, not including the final `\0').
76  *
77  * THIS IS A PORTABILITY FEATURE: USE vsnprintf() in CODE.
78  */
79 OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 3, 0);
80 
81 /**
82  * Allocates and writes to a string under the control of a format
83  * string that specifies how subsequent arguments are converted for
84  * output.
85  *
86  * @param *ptr Pointer to output string buffer
87  * @param fmt Output format
88  * @return Length of output string
89  *
90  * Sets *ptr to be a pointer to a buffer sufficiently large to hold
91  * the formatted string. This pointer should be passed to free(3) to
92  * release the allocated storage when it is no longer needed. If
93  * sufficient space cannot be allocated, asprintf() and vasprintf()
94  * will return -1 and set ret to be a NULL pointer.
95  *
96  * Returns the number of characters printed.
97  *
98  * THIS IS A PORTABILITY FEATURE: USE asprintf() in CODE.
99  */
100 OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt, ...) __opal_attribute_format__(__printf__, 2, 3);
101 
102 
103 /**
104  * Allocates and writes to a string under the control of a format
105  * string that specifies how arguments accessed via the
106  * variable-length argument facilities of stdarg(3) are converted for
107  * output.
108  *
109  * @param *ptr Pointer to output string buffer
110  * @param fmt Output format
111  * @param ap Variable argument list pointer
112  * @return Length of output string
113  *
114  * Sets *ptr to be a pointer to a buffer sufficiently large to hold
115  * the formatted string. This pointer should be passed to free(3) to
116  * release the allocated storage when it is no longer needed. If
117  * sufficient space cannot be allocated, asprintf() and vasprintf()
118  * will return -1 and set ret to be a NULL pointer.
119  *
120  * Returns the number of characters printed.
121  *
122  * THIS IS A PORTABILITY FEATURE: USE vasprintf() in CODE.
123  */
124 OPAL_DECLSPEC int opal_vasprintf(char **ptr, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 2, 0);
125 
126 
127 END_C_DECLS
128 
129 #endif /* OPAL_PRINTF_H */
130 
BEGIN_C_DECLS OPAL_DECLSPEC int OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __opal_attribute_format__(__printf__
Writes to a string under the control of a format string that specifies how arguments accessed via the...
BEGIN_C_DECLS OPAL_DECLSPEC int OPAL_DECLSPEC int OPAL_DECLSPEC int OPAL_DECLSPEC int opal_vasprintf(char **ptr, const char *fmt, va_list ap) __opal_attribute_format__(__printf__
Allocates and writes to a string under the control of a format string that specifies how arguments ac...
BEGIN_C_DECLS OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt,...) __opal_attribute_format__(__printf__
Writes to a string under the control of a format string that specifies how subsequent arguments are c...
BEGIN_C_DECLS OPAL_DECLSPEC int OPAL_DECLSPEC int OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt,...) __opal_attribute_format__(__printf__
Allocates and writes to a string under the control of a format string that specifies how subsequent a...