2 * Copyright (c) 2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * Non-standard, Darwin-specific additions for the stdio(3) family of APIs.
28 #ifndef __DARWIN_STDIO_H
29 #define __DARWIN_STDIO_H
33 #include <sys/cdefs.h>
38 * @function zsnprintf_np
39 * snprintf(3) variant which returns the numnber of bytes written less the null
43 * The buffer in which to write the string.
46 * The length of the buffer.
49 * The printf(3)-like format string.
52 * The arguments corresponding to the format string.
55 * The number of bytes written into the buffer, less the null terminator. This
56 * routine is useful for successive string printing that may be lossy, as it
57 * will simply return zero when there is no space left in the destination
58 * buffer, i.e. enables the following pattern:
61 * size_t left = sizeof(buff);
62 * for (i = 0; i < n_strings; i++) {
63 * size_t n_written = zsnprintf_np(buff, left, "%s", strings[i]);
68 * This loop will safely terminate without any special care since, as soon as
69 * the buffer's space is exhausted, all further calls to zsnprintf_np() will
70 * write nothing and return zero.
72 DARWIN_API_AVAILABLE_20170407
73 OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL3
OS_FORMAT_PRINTF(3, 4)
75 zsnprintf_np(char *buff
, size_t len
, const char *fmt
, ...);
79 #endif // __DARWIN_STDIO_H