xref: /aosp_15_r20/system/libbase/include/android-base/stringprintf.h (revision 8f0ba417480079999ba552f1087ae592091b9d02)
1*8f0ba417SAndroid Build Coastguard Worker /*
2*8f0ba417SAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*8f0ba417SAndroid Build Coastguard Worker  *
4*8f0ba417SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8f0ba417SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8f0ba417SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8f0ba417SAndroid Build Coastguard Worker  *
8*8f0ba417SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*8f0ba417SAndroid Build Coastguard Worker  *
10*8f0ba417SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8f0ba417SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8f0ba417SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8f0ba417SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8f0ba417SAndroid Build Coastguard Worker  * limitations under the License.
15*8f0ba417SAndroid Build Coastguard Worker  */
16*8f0ba417SAndroid Build Coastguard Worker 
17*8f0ba417SAndroid Build Coastguard Worker #pragma once
18*8f0ba417SAndroid Build Coastguard Worker 
19*8f0ba417SAndroid Build Coastguard Worker #include <stdarg.h>
20*8f0ba417SAndroid Build Coastguard Worker #include <string>
21*8f0ba417SAndroid Build Coastguard Worker 
22*8f0ba417SAndroid Build Coastguard Worker namespace android {
23*8f0ba417SAndroid Build Coastguard Worker namespace base {
24*8f0ba417SAndroid Build Coastguard Worker 
25*8f0ba417SAndroid Build Coastguard Worker // These printf-like functions are implemented in terms of vsnprintf, so they
26*8f0ba417SAndroid Build Coastguard Worker // use the same attribute for compile-time format string checking.
27*8f0ba417SAndroid Build Coastguard Worker 
28*8f0ba417SAndroid Build Coastguard Worker // Returns a string corresponding to printf-like formatting of the arguments.
29*8f0ba417SAndroid Build Coastguard Worker std::string StringPrintf(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
30*8f0ba417SAndroid Build Coastguard Worker 
31*8f0ba417SAndroid Build Coastguard Worker // Appends a printf-like formatting of the arguments to 'dst'.
32*8f0ba417SAndroid Build Coastguard Worker void StringAppendF(std::string* dst, const char* fmt, ...)
33*8f0ba417SAndroid Build Coastguard Worker     __attribute__((__format__(__printf__, 2, 3)));
34*8f0ba417SAndroid Build Coastguard Worker 
35*8f0ba417SAndroid Build Coastguard Worker // Appends a printf-like formatting of the arguments to 'dst'.
36*8f0ba417SAndroid Build Coastguard Worker void StringAppendV(std::string* dst, const char* format, va_list ap)
37*8f0ba417SAndroid Build Coastguard Worker     __attribute__((__format__(__printf__, 2, 0)));
38*8f0ba417SAndroid Build Coastguard Worker 
39*8f0ba417SAndroid Build Coastguard Worker }  // namespace base
40*8f0ba417SAndroid Build Coastguard Worker }  // namespace android
41