nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GLIB - Library of useful routines for C programming |
2 | * Copyright (C) 2003 Matthias Clasen |
||
3 | * |
||
4 | * This library is free software; you can redistribute it and/or |
||
5 | * modify it under the terms of the GNU Lesser General Public |
||
6 | * License as published by the Free Software Foundation; either |
||
7 | * version 2 of the License, or (at your option) any later version. |
||
8 | * |
||
9 | * This library is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
12 | * Lesser General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public |
||
15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Modified by the GLib Team and others 2003. See the AUTHORS |
||
20 | * file for a list of people on the GLib Team. See the ChangeLog |
||
21 | * files for a list of changes. These files are distributed with |
||
22 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
||
23 | */ |
||
24 | |||
25 | #ifdef HAVE_CONFIG_H |
||
26 | # include <config.h> |
||
27 | #endif |
||
28 | #include <string.h> |
||
29 | #include <stdlib.h> |
||
30 | #include <stdio.h> |
||
31 | #include "g-gnulib.h" |
||
32 | #include "vasnprintf.h" |
||
33 | #include "printf.h" |
||
34 | |||
35 | int _g_gnulib_printf (char const *format, ...) |
||
36 | { |
||
37 | va_list args; |
||
38 | int retval; |
||
39 | |||
40 | va_start (args, format); |
||
41 | retval = _g_gnulib_vprintf (format, args); |
||
42 | va_end (args); |
||
43 | |||
44 | return retval; |
||
45 | } |
||
46 | |||
47 | int _g_gnulib_fprintf (FILE *file, char const *format, ...) |
||
48 | { |
||
49 | va_list args; |
||
50 | int retval; |
||
51 | |||
52 | va_start (args, format); |
||
53 | retval = _g_gnulib_vfprintf (file, format, args); |
||
54 | va_end (args); |
||
55 | |||
56 | return retval; |
||
57 | } |
||
58 | |||
59 | int _g_gnulib_sprintf (char *string, char const *format, ...) |
||
60 | { |
||
61 | va_list args; |
||
62 | int retval; |
||
63 | |||
64 | va_start (args, format); |
||
65 | retval = _g_gnulib_vsprintf (string, format, args); |
||
66 | va_end (args); |
||
67 | |||
68 | return retval; |
||
69 | } |
||
70 | |||
71 | int _g_gnulib_snprintf (char *string, size_t n, char const *format, ...) |
||
72 | { |
||
73 | va_list args; |
||
74 | int retval; |
||
75 | |||
76 | va_start (args, format); |
||
77 | retval = _g_gnulib_vsnprintf (string, n, format, args); |
||
78 | va_end (args); |
||
79 | |||
80 | return retval; |
||
81 | } |
||
82 | |||
83 | int _g_gnulib_vprintf (char const *format, va_list args) |
||
84 | { |
||
85 | return _g_gnulib_vfprintf (stdout, format, args); |
||
86 | } |
||
87 | |||
88 | int _g_gnulib_vfprintf (FILE *file, char const *format, va_list args) |
||
89 | { |
||
90 | char *result; |
||
91 | size_t length, rlength; |
||
92 | |||
93 | result = vasnprintf (NULL, &length, format, args); |
||
94 | if (result == NULL) |
||
95 | return -1; |
||
96 | |||
97 | rlength = fwrite (result, 1, length, file); |
||
98 | free (result); |
||
99 | |||
100 | return rlength; |
||
101 | } |
||
102 | |||
103 | int _g_gnulib_vsprintf (char *string, char const *format, va_list args) |
||
104 | { |
||
105 | char *result; |
||
106 | size_t length; |
||
107 | |||
108 | result = vasnprintf (NULL, &length, format, args); |
||
109 | if (result == NULL) |
||
110 | return -1; |
||
111 | |||
112 | memcpy (string, result, length + 1); |
||
113 | free (result); |
||
114 | |||
115 | return length; |
||
116 | } |
||
117 | |||
118 | int _g_gnulib_vsnprintf (char *string, size_t n, char const *format, va_list args) |
||
119 | { |
||
120 | char *result; |
||
121 | size_t length; |
||
122 | |||
123 | result = vasnprintf (NULL, &length, format, args); |
||
124 | if (result == NULL) |
||
125 | return -1; |
||
126 | |||
127 | if (n > 0) |
||
128 | { |
||
129 | memcpy (string, result, MIN(length + 1, n)); |
||
130 | string[n - 1] = 0; |
||
131 | } |
||
132 | |||
133 | free (result); |
||
134 | |||
135 | return length; |
||
136 | } |
||
137 | |||
138 | int _g_gnulib_vasprintf (char **result, char const *format, va_list args) |
||
139 | { |
||
140 | size_t length; |
||
141 | |||
142 | *result = vasnprintf (NULL, &length, format, args); |
||
143 | if (*result == NULL) |
||
144 | return -1; |
||
145 | |||
146 | return length; |
||
147 | } |
||
148 | |||
149 | |||
150 | |||
151 | |||
152 |