]>
git.saurik.com Git - apple/security.git/blob - OSX/utilities/SecIOFormat.h
2 * Copyright (c) 2012-2014 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@
25 #ifndef _SECIOFORMAT_H_
26 #define _SECIOFORMAT_H_
27 // TODO: Name this file SecType.h? To match inttype.h?
31 // MARK: Guidlines and Examples
33 /* Tips for using printf and CFStringCreateWithFormat style functions.
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:
39 Type Format String Variants
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))
46 uint64_t "%"PRIu64 printf("sqlite3_rowid: %"PRIu64, rowid)
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.
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
65 // MARK: CFIndex printing support
67 // Note that CFIndex is signed so the u variants won't work.
69 # define PRIdCFIndex "lld"
70 # define PRIiCFIndex "lli"
71 # define PRIoCFIndex "llo"
72 # define PRIuCFIndex "llu"
73 # define PRIxCFIndex "llx"
74 # define PRIXCFIndex "llX"
76 # define PRIdCFIndex "ld"
77 # define PRIiCFIndex "li"
78 # define PRIoCFIndex "lo"
79 # define PRIuCFIndex "lu"
80 # define PRIxCFIndex "lx"
81 # define PRIXCFIndex "lX"
84 // MARK: OSStatus printing support
86 // Note that OSStatus is signed so the u variants won't work.
88 # define PRIdOSStatus "d"
89 # define PRIiOSStatus "i"
90 # define PRIoOSStatus "o"
91 # define PRIuOSStatus "u"
92 # define PRIxOSStatus "x"
93 # define PRIXOSStatus "X"
95 # define PRIdOSStatus "ld"
96 # define PRIiOSStatus "li"
97 # define PRIoOSStatus "lo"
98 # define PRIuOSStatus "lu"
99 # define PRIxOSStatus "lx"
100 # define PRIXOSStatus "lX"