2004-08-11 01:13:08 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2007-01-30 23:54:06 +03:00
|
|
|
* Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-08-11 01:13:08 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Buffer safe printf functions for portability to archaic platforms.
|
|
|
|
*/
|
|
|
|
|
2005-07-04 06:16:57 +04:00
|
|
|
#ifndef OPAL_PRINTF_H
|
|
|
|
#define OPAL_PRINTF_H
|
2004-08-11 01:13:08 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
BEGIN_C_DECLS
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes to a string under the control of a format string
|
|
|
|
* that specifies how subsequent arguments are converted for output.
|
|
|
|
*
|
|
|
|
* @param str Output string buffer
|
|
|
|
* @param size Size of string buffer
|
|
|
|
* @param fmt Output format
|
|
|
|
* @return Length of output string
|
|
|
|
*
|
|
|
|
* At most size-1 characters are printed into the output string (the
|
|
|
|
* size'th character then gets the terminating `\0'); if the return
|
|
|
|
* value is greater than or equal to the size argument, the string was
|
|
|
|
* too short and some of the printed characters were discarded. The
|
|
|
|
* output is always null-terminated.
|
|
|
|
*
|
|
|
|
* Returns the number of characters that would have been printed if
|
|
|
|
* the size were unlimited (again, not including the final `\0').
|
|
|
|
*
|
|
|
|
* THIS IS A PORTABILITY FEATURE: USE snprintf() in CODE.
|
|
|
|
*/
|
2007-01-30 23:54:06 +03:00
|
|
|
OPAL_DECLSPEC int opal_snprintf(char *str, size_t size, const char *fmt, ...) __opal_attribute_format__(__printf__, 3, 4);
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes to a string under the control of a format string that
|
|
|
|
* specifies how arguments accessed via the variable-length argument
|
|
|
|
* facilities of stdarg(3) are converted for output.
|
|
|
|
*
|
|
|
|
* @param str Output string buffer
|
|
|
|
* @param size Size of string buffer
|
|
|
|
* @param fmt Output format
|
|
|
|
* @param ap Variable argument list pointer
|
|
|
|
* @return Length of output string
|
|
|
|
*
|
|
|
|
* At most size-1 characters are printed into the output string (the
|
|
|
|
* size'th character then gets the terminating `\0'); if the return
|
|
|
|
* value is greater than or equal to the size argument, the string was
|
|
|
|
* too short and some of the printed characters were discarded. The
|
|
|
|
* output is always null-terminated.
|
|
|
|
*
|
|
|
|
* Returns the number of characters that would have been printed if
|
|
|
|
* the size were unlimited (again, not including the final `\0').
|
|
|
|
*
|
|
|
|
* THIS IS A PORTABILITY FEATURE: USE vsnprintf() in CODE.
|
|
|
|
*/
|
2007-01-30 23:54:06 +03:00
|
|
|
OPAL_DECLSPEC int opal_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 3, 0);
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and writes to a string under the control of a format
|
|
|
|
* string that specifies how subsequent arguments are converted for
|
|
|
|
* output.
|
|
|
|
*
|
2009-03-03 15:50:46 +03:00
|
|
|
* @param *ptr Pointer to output string buffer
|
2004-08-11 01:13:08 +04:00
|
|
|
* @param fmt Output format
|
|
|
|
* @return Length of output string
|
|
|
|
*
|
|
|
|
* Sets *ptr to be a pointer to a buffer sufficiently large to hold
|
|
|
|
* the formatted 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, asprintf() and vasprintf()
|
|
|
|
* will return -1 and set ret to be a NULL pointer.
|
|
|
|
*
|
|
|
|
* Returns the number of characters printed.
|
|
|
|
*
|
|
|
|
* THIS IS A PORTABILITY FEATURE: USE asprintf() in CODE.
|
|
|
|
*/
|
2007-01-30 23:54:06 +03:00
|
|
|
OPAL_DECLSPEC int opal_asprintf(char **ptr, const char *fmt, ...) __opal_attribute_format__(__printf__, 2, 3);
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and writes to a string under the control of a format
|
|
|
|
* string that specifies how arguments accessed via the
|
|
|
|
* variable-length argument facilities of stdarg(3) are converted for
|
|
|
|
* output.
|
|
|
|
*
|
2009-03-03 15:50:46 +03:00
|
|
|
* @param *ptr Pointer to output string buffer
|
2004-08-11 01:13:08 +04:00
|
|
|
* @param fmt Output format
|
|
|
|
* @param ap Variable argument list pointer
|
|
|
|
* @return Length of output string
|
|
|
|
*
|
|
|
|
* Sets *ptr to be a pointer to a buffer sufficiently large to hold
|
|
|
|
* the formatted 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, asprintf() and vasprintf()
|
|
|
|
* will return -1 and set ret to be a NULL pointer.
|
|
|
|
*
|
|
|
|
* Returns the number of characters printed.
|
|
|
|
*
|
|
|
|
* THIS IS A PORTABILITY FEATURE: USE vasprintf() in CODE.
|
|
|
|
*/
|
2007-01-30 23:54:06 +03:00
|
|
|
OPAL_DECLSPEC int opal_vasprintf(char **ptr, const char *fmt, va_list ap) __opal_attribute_format__(__printf__, 2, 0);
|
2004-08-11 01:13:08 +04:00
|
|
|
|
|
|
|
|
2008-02-28 04:57:57 +03:00
|
|
|
END_C_DECLS
|
2004-08-11 01:13:08 +04:00
|
|
|
|
2005-07-04 06:16:57 +04:00
|
|
|
#endif /* OPAL_PRINTF_H */
|
2004-08-11 01:13:08 +04:00
|
|
|
|