1/*
2 * Copyright (c) 2012-2014 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#ifndef _SECIOFORMAT_H_
26#define _SECIOFORMAT_H_
27// TODO: Name this file SecType.h?  To match inttype.h?
28
29#include <inttypes.h>
30
31// MARK: Guidlines and Examples
32
33/*  Tips for using printf and CFStringCreateWithFormat style functions.
34
35    Avoid using casts in arguments to these functions like the plague.  If you
36    have to use them, think again.  You are probably wrong and you are writing
37    non portable code.  Instead try following this pattern:
38
39    Type        Format String       Variants
40    size_t      "%zu"
41    ssize_t     "%zd"
42    ptrdiff_t   "%td"               printf("array_len: %td", pos - begin)
43    OSStatus    "%"PRIdOSStatus     printf("%"PRIxCFIndex" returned", status)
44    CFIndex     "%"PRIdCFIndex      printf("ar[%"PRIdCFIndex"]=%p", ix, CFArrayGetValueAtIndex(ar, ix))
45    sint64_t    "%"PRId64
46    uint64_t    "%"PRIu64           printf("sqlite3_rowid: %"PRIu64, rowid)
47    sint32_t    "%"PRId32
48    uint32_t    "%"PRIu32
49    uint8_t     "%"PRIx8
50
51    All of the above examples also work inside a CFSTR(). For example:
52    CFStringAppendFormat(ms, NULL, CFSTR("ar[%"PRIdCFIndex"]=%p"), ix, CFArrayGetValueAtIndex(ar, ix))
53    Also you can use any of d i o u x X where appropriate for some of these types
54    although u x X are for unsigned types only.
55
56    Try to avoid using these types unless you know what you are doing because
57    they can lead to portability issues on different flavors of 32 and 64 bit
58    platforms:
59
60    int         "%d"
61    long        "%ld"
62    long long   "%lld"
63 */
64
65// MARK: CFIndex printing support
66
67// Note that CFIndex is signed so the u variants won't work.
68#ifdef __LLP64__
69#  define PRIdCFIndex    "lld"
70#  define PRIiCFIndex    "lli"
71#  define PRIoCFIndex    "llo"
72#  define PRIuCFIndex    "llu"
73#  define PRIxCFIndex    "llx"
74#  define PRIXCFIndex    "llX"
75#else
76#  define PRIdCFIndex    "ld"
77#  define PRIiCFIndex    "li"
78#  define PRIoCFIndex    "lo"
79#  define PRIuCFIndex    "lu"
80#  define PRIxCFIndex    "lx"
81#  define PRIXCFIndex    "lX"
82#endif
83
84// MARK: OSStatus printing support
85
86// Note that OSStatus is signed so the u variants won't work.
87#ifdef __LP64__
88#  define PRIdOSStatus    "d"
89#  define PRIiOSStatus    "i"
90#  define PRIoOSStatus    "o"
91#  define PRIuOSStatus    "u"
92#  define PRIxOSStatus    "x"
93#  define PRIXOSStatus    "X"
94#else
95#  define PRIdOSStatus    "ld"
96#  define PRIiOSStatus    "li"
97#  define PRIoOSStatus    "lo"
98#  define PRIuOSStatus    "lu"
99#  define PRIxOSStatus    "lx"
100#  define PRIXOSStatus    "lX"
101#endif
102
103#endif
104