]> git.saurik.com Git - apple/libc.git/blame - libdarwin/h/stdio.h
Libc-1272.200.26.tar.gz
[apple/libc.git] / libdarwin / h / stdio.h
CommitLineData
70ad1dc8
A
1/*
2 * Copyright (c) 2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*!
25 * @header
26 * Non-standard, Darwin-specific additions for the stdio(3) family of APIs.
27 */
28#ifndef __DARWIN_STDIO_H
29#define __DARWIN_STDIO_H
30
31#include <os/base.h>
32#include <os/api.h>
33#include <sys/cdefs.h>
34
35__BEGIN_DECLS;
36
37/*!
38 * @function zsnprintf_np
39 * snprintf(3) variant which returns the numnber of bytes written less the null
40 * terminator.
41 *
42 * @param buff
43 * The buffer in which to write the string.
44 *
45 * @param len
46 * The length of the buffer.
47 *
48 * @param fmt
49 * The printf(3)-like format string.
50 *
51 * @param ...
52 * The arguments corresponding to the format string.
53 *
54 * @result
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:
59 *
60 * char *cur = buff;
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]);
64 * cur += n_written;
65 * left -= n_written;
66 * }
67 *
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.
71 */
72DARWIN_API_AVAILABLE_20170407
73OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL3 OS_FORMAT_PRINTF(3, 4)
74size_t
75zsnprintf_np(char *buff, size_t len, const char *fmt, ...);
76
77__END_DECLS;
78
79#endif // __DARWIN_STDIO_H