1#ifndef MYSQL_SERVICE_MY_SNPRINTF_INCLUDED
2/* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/**
18 @file
19 my_snprintf service
20
21 Portable and limited vsnprintf() implementation.
22
23 This is a portable, limited vsnprintf() implementation, with some
24 extra features. "Portable" means that it'll produce identical result
25 on all platforms (for example, on Windows and Linux system printf %e
26 formats the exponent differently, on different systems %p either
27 prints leading 0x or not, %s may accept null pointer or crash on
28 it). "Limited" means that it does not support all the C89 features.
29 But it supports few extensions, not in any standard.
30
31 my_vsnprintf(to, n, fmt, ap)
32
33 @param[out] to A buffer to store the result in
34 @param[in] n Store up to n-1 characters, followed by an end 0
35 @param[in] fmt printf-like format string
36 @param[in] ap Arguments
37
38 @return a number of bytes written to a buffer *excluding* terminating '\0'
39
40 @post
41 The syntax of a format string is generally the same:
42 % <flag> <width> <precision> <length modifier> <format>
43 where everithing but the format is optional.
44
45 Three one-character flags are recognized:
46 '0' has the standard zero-padding semantics;
47 '-' is parsed, but silently ignored;
48 '`' (backtick) is only supported for strings (%s) and means that the
49 string will be quoted according to MySQL identifier quoting rules.
50
51 Both <width> and <precision> can be specified as numbers or '*'.
52 If an asterisk is used, an argument of type int is consumed.
53
54 <length modifier> can be 'l', 'll', or 'z'.
55
56 Supported formats are 's' (null pointer is accepted, printed as
57 "(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o',
58 'X', 'p' (works as 0x%x), 'f', 'g', 'M' (extension, see below).
59
60 Standard syntax for positional arguments $n is supported.
61
62 Extensions:
63
64 Flag '`' (backtick): see above.
65
66 Format 'b': binary buffer, prints exactly <precision> bytes from the
67 argument, without stopping at '\0'.
68
69 Format 'M': takes one integer, prints this integer, space, double quote
70 error message, double quote. In other words
71 printf("%M", n) === printf("%d \"%s\"", n, strerror(n))
72*/
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78#ifndef MYSQL_ABI_CHECK
79#include <stdarg.h>
80#include <stdlib.h>
81#endif
82
83extern struct my_snprintf_service_st {
84 size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
85 size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);
86} *my_snprintf_service;
87
88#ifdef MYSQL_DYNAMIC_PLUGIN
89
90#define my_vsnprintf my_snprintf_service->my_vsnprintf_type
91#define my_snprintf my_snprintf_service->my_snprintf_type
92
93#else
94
95size_t my_snprintf(char* to, size_t n, const char* fmt, ...);
96size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap);
97
98#endif
99
100#ifdef __cplusplus
101}
102#endif
103
104#define MYSQL_SERVICE_MY_SNPRINTF_INCLUDED
105#endif
106
107