-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisting8.html
executable file
·1978 lines (1697 loc) · 67.6 KB
/
listing8.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>FSMegaInfo - /FieldPrinter.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Darwin/index.html">Darwin</a> > <a href="../../samplecode/Darwin/idxFileManagement-date.html">File Management</a> > <A HREF="javascript:location.replace('index.html');">FSMegaInfo</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">FSMegaInfo</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/FieldPrinter.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/AliasManager.c</option>
<option value="listing2.html">/BSD.c</option>
<option value="listing3.html">/BSD.h</option>
<option value="listing4.html">/BSDAttrList.c</option>
<option value="listing5.html">/Command.c</option>
<option value="listing6.html">/Command.h</option>
<option value="listing7.html">/DiskArb.c</option>
<option value="listing8.html">/FieldPrinter.c</option>
<option value="listing9.html">/FieldPrinter.h</option>
<option value="listing10.html">/FileManager.c</option>
<option value="listing11.html">/FolderManager.c</option>
<option value="listing12.html">/FSMegaInfo.c</option>
<option value="listing13.html">/Read Me About FSMegaInfo.txt</option>
<option value="listing14.html">/Tests/ten-five-intel.txt</option>
<option value="listing15.html">/Tests/ten-five-one-ppc64.txt</option>
<option value="listing16.html">/Tests/ten-five-ppc.txt</option>
<option value="listing17.html">/Tests/ten-four-eleven-intel.txt</option>
<option value="listing18.html">/Tests/ten-four-eleven-ppc.txt</option></select>
</p>
</form>
<p><strong><a href="FSMegaInfo.zip">Download Sample</a></strong> (“FSMegaInfo.zip”, 522.7K)<BR>
<strong><a href="FSMegaInfo.dmg">Download Sample</a></strong> (“FSMegaInfo.dmg”, 920.2K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: FieldPrinter.c
Contains: Routines to pretty print structures.
Written by: DTS
Copyright: Copyright (c) 2008 Apple Inc. All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or
redistribution of this Apple software constitutes acceptance of
these terms. If you do not agree with these terms, please do
not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following
terms, and subject to these terms, Apple grants you a personal,
non-exclusive license, under Apple's copyrights in this
original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or
without modifications, in source and/or binary forms; provided
that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the
following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks
or logos of Apple Inc. may be used to endorse or promote
products derived from the Apple Software without specific prior
written permission from Apple. Except as expressly stated in
this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or
by other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis.
APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING
THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/////////////////////////////////////////////////////////////////
// Our prototypes
#include "FieldPrinter.h"
// System interfaces
#include <assert.h>
#include <dirent.h>
#include <grp.h>
#include <inttypes.h>
#include <membership.h>
#include <netdb.h>
#include <netinet/in.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
/////////////////////////////////////////////////////////////////
#pragma mark ***** Utilities
extern char * FPPStringToUTFCString(ConstStr255Param pstr, CFStringEncoding pstrEncoding)
// See comment in header.
{
CFStringRef str;
CFIndex strBufLen;
char * strBuf;
Boolean success;
assert(pstr != NULL);
strBuf = NULL;
str = CFStringCreateWithPascalString(NULL, pstr, pstrEncoding);
assert(str != NULL);
if (str != NULL) {
strBufLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8) + 1; // + 1 for null terminator
strBuf = (char *) malloc(strBufLen);
assert(strBuf != NULL);
if (strBuf != NULL) {
success = CFStringGetCString(str, strBuf, strBufLen, kCFStringEncodingUTF8);
assert(success);
if ( ! success ) {
free(strBuf);
strBuf = NULL;
}
}
CFRelease(str);
}
return strBuf;
}
extern void FPPrintFlags(unsigned long long flags, const FPFlagDesc *flagList, size_t nameWidth, uint32_t indent)
// See comment in header.
{
int flagIndex;
size_t thisLen;
assert(flagList != NULL);
// Calculate the length of the longest flag name (unless the caller
// specified one).
if (nameWidth == 0) {
flagIndex = 0;
while (flagList[flagIndex].flagName != NULL) {
thisLen = strlen(flagList[flagIndex].flagName);
if (thisLen > nameWidth) {
nameWidth = thisLen;
}
flagIndex += 1;
}
}
// Print each matching flag, clearing each flag that we recognise.
flagIndex = 0;
while (flagList[flagIndex].flagName != NULL) {
fprintf(stdout, "%*s%-*s = %s\n", (int) indent, "", (int) nameWidth, flagList[flagIndex].flagName, (flags & flagList[flagIndex].flagMask) ? "YES" : "NO");
flags &= ~flagList[flagIndex].flagMask;
flagIndex += 1;
}
// If any flags remain unrecognised, tell the user.
if (flags != 0) {
fprintf(stdout, "%*s... and others (0x%llx)\n", (int) indent, "", flags);
}
}
extern size_t FPFindFlagByName(const FPFlagDesc *flagList, const char *flagName)
// See comment in header.
{
bool found;
size_t flagIndex;
found = false;
flagIndex = 0;
while ( ! found && (flagList[flagIndex].flagName != NULL) ) {
found = (strcasecmp(flagName, flagList[flagIndex].flagName) == 0);
if ( ! found ) {
flagIndex += 1;
}
}
if ( ! found ) {
flagIndex = kFPNotFound;
}
return flagIndex;
}
extern size_t FPFindEnumByValue(const FPEnumDesc enumList[], int enumValue)
// See comment in header.
{
bool found;
size_t enumIndex;
found = false;
enumIndex = 0;
while ( ! found && (enumList[enumIndex].enumName != NULL) ) {
found = (enumList[enumIndex].enumValue == enumValue);
if ( ! found ) {
enumIndex += 1;
}
}
if ( ! found ) {
enumIndex = kFPNotFound;
}
return enumIndex;
}
extern size_t FPFindEnumByName(const FPEnumDesc enumList[], const char *enumName)
// See comment in header.
{
bool found;
size_t enumIndex;
found = false;
enumIndex = 0;
while ( ! found && (enumList[enumIndex].enumName != NULL) ) {
found = (strcasecmp(enumList[enumIndex].enumName, enumName) == 0);
if ( ! found ) {
enumIndex += 1;
}
}
if ( ! found ) {
enumIndex = kFPNotFound;
}
return enumIndex;
}
static void FPPrintFieldsCore(const FPFieldDesc fields[], const void *fieldBuf, size_t fieldBufSize, uint32_t indent, uint32_t verbose, FPEndian endian)
{
#pragma unused(fieldBufSize)
size_t nameWidth;
size_t nameLen;
size_t fieldIndex;
FPPrinter printer;
const void * info;
assert(fields != NULL);
assert(fieldBuf != NULL);
// Calculate the maximum field of the field names.
nameWidth = 0;
fieldIndex = 0;
while (fields[fieldIndex].fieldName != NULL) {
nameLen = strlen(fields[fieldIndex].fieldName);
if (nameLen > nameWidth) {
nameWidth = nameLen;
}
fieldIndex += 1;
}
// Print each field.
fieldIndex = 0;
while (fields[fieldIndex].fieldName != NULL) {
// Make sure the field is within the structure.
assert( fields[fieldIndex].fieldOffset < fieldBufSize );
assert( (fields[fieldIndex].fieldOffset + fields[fieldIndex].fieldSize) <= fieldBufSize);
// Process any endian override requested by the caller.
printer = fields[fieldIndex].fieldPrinter;
info = fields[fieldIndex].fieldInfo;
switch (endian) {
case kFPValueHostEndian:
// do nothing
break;
case kFPValueBigEndian:
if ( (printer == FPHex) || (printer == FPSDec) || (printer == FPUDec) || (printer == FPSignature) ) {
info = (const void *) (uintptr_t) endian;
} else if (printer == FPFlags) {
printer = FPFlagsBE;
} else {
assert(false);
}
break;
case kFPValueLittleEndian:
assert(false);
break;
default:
assert(false);
break;
}
// Call the printer routine.
printer(
fields[fieldIndex].fieldName,
fields[fieldIndex].fieldSize,
(((char *) fieldBuf) + fields[fieldIndex].fieldOffset),
indent,
nameWidth,
verbose,
info
);
fieldIndex += 1;
}
}
extern void FPPrintFields(const FPFieldDesc fields[], const void *fieldBuf, size_t fieldBufSize, uint32_t indent, uint32_t verbose)
// See comments in header.
{
FPPrintFieldsCore(fields, fieldBuf, fieldBufSize, indent, verbose, kFPValueHostEndian);
}
/////////////////////////////////////////////////////////////////
#pragma mark ***** Field Printer Routines
extern void FPNull(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints nothing, in about 20 lines )-:
//
// See definition of FPPrinter for a parameter description.
{
// Can't use FPStandardPreCondition because fieldSize is allowed to be
// zero in this case.
assert( fieldName != NULL );
// assert( fieldSize > 0 );
assert( fieldPtr != NULL );
assert( (nameWidth > 0) && ( ((size_t) nameWidth) >= strlen(fieldName) ) );
#pragma unused(fieldName)
#pragma unused(fieldSize)
#pragma unused(fieldPtr)
#pragma unused(indent)
#pragma unused(nameWidth)
#pragma unused(verbose)
#pragma unused(info)
// do nothing
}
extern void FPCString(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a C string field. The field is assumed to be UTF-8.
//
// See definition of FPPrinter for a parameter description.
{
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
fprintf(stdout, "%*s%-*s = '%s'\n", (int) indent, "", (int) nameWidth, fieldName, (const char *) fieldPtr);
}
extern void FPCStringPtr(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a C string pointer field. The encoding is assumed to be UTF-8.
//
// See definition of FPPrinter for a parameter description.
{
const char * strPtr;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(const char *));
strPtr = *((const char **) fieldPtr);
assert(strPtr != NULL);
fprintf(stdout, "%*s%-*s = %p ('%s')\n", (int) indent, "", (int) nameWidth, fieldName, strPtr, strPtr);
}
extern void FPPString(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a Pascal string field. info supplies the text encoding.
//
// See definition of FPPrinter for a parameter description.
{
char * strBuf;
#pragma unused(fieldSize)
#pragma unused(verbose)
assert( FPStandardPreCondition() );
strBuf = FPPStringToUTFCString(fieldPtr, (CFStringEncoding) (uintptr_t) info);
assert(strBuf != NULL);
if (strBuf != NULL) {
fprintf(stdout, "%*s%-*s = '%s'\n", (int) indent, "", (int) nameWidth, fieldName, strBuf);
}
free(strBuf);
}
extern void FPCFString(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a CFString field.
//
// See definition of FPPrinter for a parameter description.
{
CFStringRef str;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(CFStringRef));
str = *( (CFStringRef *) fieldPtr );
assert(str != NULL);
assert( CFGetTypeID(str) == CFStringGetTypeID() );
FPCFType(fieldName, sizeof(str), &str, indent, (int) nameWidth, verbose, NULL);
}
extern void FPCFType(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a CFType field.
//
// See definition of FPPrinter for a parameter description.
{
CFTypeRef value;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(CFTypeRef));
value = *( (CFTypeRef *) fieldPtr );
assert(value != NULL);
// First handle the compound types, CFDictionary and CFArray.
if ( CFGetTypeID(value) == CFDictionaryGetTypeID() ) {
FPCFDictionary(fieldName, sizeof(value), &value, indent, nameWidth, verbose, NULL);
} else if ( CFGetTypeID(value) == CFArrayGetTypeID() ) {
// FPCFArray(fieldName, sizeof(value), &value, indent, nameWidth, verbose, NULL);
fprintf(stderr, "*** CFArray skipped\n");
} else {
const char * quoteStr;
CFStringRef str;
CFIndex strBufLen;
char * strBuf;
Boolean success;
// Handle everything else, which hopefully can be converted to a string
// using CFStringCreateWithFormat.
quoteStr = "";
if ( CFGetTypeID(value) == CFStringGetTypeID() ) {
quoteStr = "'";
}
str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), value);
assert(str != NULL);
if (str != NULL) {
strBufLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8) + 1; // + 1 for null terminator
strBuf = (char *) malloc(strBufLen);
assert(strBuf != NULL);
if (strBuf != NULL) {
success = CFStringGetCString(str, strBuf, strBufLen, kCFStringEncodingUTF8);
assert(success);
if (success) {
fprintf(stdout, "%*s%-*s = %s%s%s\n", (int) indent, "", (int) nameWidth, fieldName, quoteStr, strBuf, quoteStr);
}
}
free(strBuf);
CFRelease(str);
}
}
}
static int KeyCompare(const void *left, const void *right)
// Comparison callback for sorting an array of CFDictionary keys.
{
CFStringRef leftString;
CFStringRef rightString;
assert(left != NULL);
assert(right != NULL);
leftString = *(CFStringRef *) left;
rightString = *(CFStringRef *) right;
assert(leftString != NULL);
assert(rightString != NULL);
return (int) CFStringCompare(leftString, rightString, 0);
}
extern void FPCFDictionary(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a CFDictionary field.
//
// See definition of FPPrinter for a parameter description.
{
CFDictionaryRef dict;
CFIndex dictCount;
CFIndex dictIndex;
Boolean success;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(CFDictionaryRef));
dict = *( (CFDictionaryRef *) fieldPtr );
assert(dict != NULL);
assert( CFGetTypeID(dict) == CFDictionaryGetTypeID() );
fprintf(stdout, "%*s%-*s = {\n", (int) indent, "", (int) nameWidth, fieldName);
dictCount = CFDictionaryGetCount(dict);
if (dictCount > 0) {
CFTypeRef * keys;
CFIndex keyWidth;
char * keyBuf;
CFIndex keyBufSize;
keys = malloc(dictCount * sizeof(CFTypeRef));
assert(keys != NULL);
CFDictionaryGetKeysAndValues(dict, (const void **) keys, NULL);
// Sort the keys so that we get consistent results for the benefit of the
// test script.
qsort(keys, dictCount, sizeof(*keys), KeyCompare);
// Calculate the maximum length of the keys. This is somewhat bogus because
// we're counting in Unicode characters, not UTF-8, but it will work for the
// common case where the keys are all ASCII.
keyWidth = 0;
for (dictIndex = 0; dictIndex < dictCount; dictIndex++) {
assert( CFGetTypeID(keys[dictIndex]) == CFStringGetTypeID() );
if ( CFStringGetLength(keys[dictIndex]) > keyWidth ) {
keyWidth = CFStringGetLength(keys[dictIndex]);
}
}
// Once we know the maximum key width, we can use it to allocate a buffer that's
// big enough to hold the UTF-8 representation of that width.
keyBufSize = CFStringGetMaximumSizeForEncoding(keyWidth, kCFStringEncodingUTF8) + 1;
keyBuf = malloc(keyBufSize);
assert(keyBuf != NULL);
// Now go through and print each field.
for (dictIndex = 0; dictIndex < dictCount; dictIndex++) {
CFTypeRef thisValue;
success = CFStringGetCString(keys[dictIndex], keyBuf, keyBufSize, kCFStringEncodingUTF8);
assert(success);
thisValue = CFDictionaryGetValue(dict, keys[dictIndex]);
FPCFType(keyBuf, sizeof(thisValue), &thisValue, indent + kStdIndent, keyWidth, verbose, NULL);
}
free(keyBuf);
free(keys);
}
fprintf(stdout, "%*s}\n", (int) indent, "");
}
extern void HFSUniStr255FieldPrinter(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints an HFSUniStr255 field.
//
// See definition of FPPrinter for a parameter description.
{
const HFSUniStr255 * hfsStr;
CFStringRef str;
#pragma unused(fieldSize)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(HFSUniStr255));
hfsStr = (const HFSUniStr255 *) fieldPtr;
assert(hfsStr != NULL);
str = CFStringCreateWithCharacters(NULL, hfsStr->unicode, hfsStr->length);
assert(str != NULL);
if (str != NULL) {
FPCFString(fieldName, sizeof(str), &str, indent, nameWidth, verbose, info);
}
CFRelease(str);
}
extern void FPPtr(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a generic pointer field.
//
// See definition of FPPrinter for a parameter description.
{
const void * ptr;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(void *));
ptr = *((const void **) fieldPtr);
fprintf(stdout, "%*s%-*s = %p\n", (int) indent, "", (int) nameWidth, fieldName, ptr);
}
extern void FPBoolean(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a Boolean field.
//
// See definition of FPPrinter for a parameter description.
{
Boolean b;
#pragma unused(fieldSize)
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
assert(fieldSize == sizeof(Boolean));
b = *((Boolean *) fieldPtr);
fprintf(stdout, "%*s%-*s = %s\n", (int) indent, "", (int) nameWidth, fieldName, b ? "YES" : "NO");
}
static bool SwapIt(const void *info)
{
FPEndian endian;
bool swap;
endian = (FPEndian) (uintptr_t) info;
swap = false;
switch (endian) {
case kFPValueHostEndian:
break;
case kFPValueBigEndian:
#if TARGET_RT_LITTLE_ENDIAN
swap = true;
#endif
break;
case kFPValueLittleEndian:
#if TARGET_RT_BIG_ENDIAN
swap = true;
#endif
break;
default:
assert(false);
break;
}
return swap;
}
static uint16_t Swap16(const void *fieldPtr, const void *info)
{
uint16_t x;
x = * (uint16_t *) fieldPtr;
if ( SwapIt(info) ) {
x = OSSwapInt16(x);
}
return x;
}
static uint32_t Swap32(const void *fieldPtr, const void *info)
{
uint32_t x;
x = * (uint32_t *) fieldPtr;
if ( SwapIt(info) ) {
x = OSSwapInt32(x);
}
return x;
}
static uint64_t Swap64(const void *fieldPtr, const void *info)
{
uint64_t x;
x = * (uint64_t *) fieldPtr;
if ( SwapIt(info) ) {
x = OSSwapInt64(x);
}
return x;
}
extern void FPHex(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a field in hex. There's special case code for each common size
// (8 bits, 16 bits, 32 bits, and 64 bits), and generic code for large sizes.
//
// See definition of FPPrinter for a parameter description.
{
size_t i;
#pragma unused(verbose)
#pragma unused(info)
assert( FPStandardPreCondition() );
switch (fieldSize) {
case sizeof(uint8_t):
fprintf(stdout, "%*s%-*s = 0x%02" PRIx8 "\n", (int) indent, "", (int) nameWidth, fieldName, *((uint8_t *) fieldPtr) );
break;
case sizeof(uint16_t):
fprintf(stdout, "%*s%-*s = 0x%04" PRIx16 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap16(fieldPtr, info) );
break;
case sizeof(uint32_t):
fprintf(stdout, "%*s%-*s = 0x%08" PRIx32 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap32(fieldPtr, info) );
break;
case sizeof(uint64_t):
fprintf(stdout, "%*s%-*s = 0x%016" PRIx64 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap64(fieldPtr, info) );
break;
default:
if (fieldSize > sizeof(uint64_t)) {
fprintf(stdout, "%*s%-*s = ", (int) indent, "", (int) nameWidth, fieldName);
i = 0;
while (i < fieldSize) {
do {
fprintf(stdout, "%02" PRIx8 " ", ((uint8_t *) fieldPtr)[i]);
i += 1;
} while ( (i < fieldSize) && ((i % 16) != 0) );
fprintf(stdout, "\n");
if (i < fieldSize) {
fprintf(stdout, "%*s%*s ", (int) indent, "", (int) nameWidth, "");
}
}
} else {
assert(false);
}
break;
}
}
extern void FPSDec(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a field as a signed decimal. There's special case code for each common
// size (8 bits, 16 bits, 32 bits, and 64 bits), and other sizes are printed as
// a hex dump.
//
// See definition of FPPrinter for a parameter description.
{
assert( FPStandardPreCondition() );
switch (fieldSize) {
case sizeof(int8_t):
fprintf(stdout, "%*s%-*s = %" PRId8 "\n", (int) indent, "", (int) nameWidth, fieldName, *((int8_t *) fieldPtr) );
break;
case sizeof(int16_t):
fprintf(stdout, "%*s%-*s = %" PRId16 "\n", (int) indent, "", (int) nameWidth, fieldName, (int16_t) Swap16(fieldPtr, info) );
break;
case sizeof(int32_t):
fprintf(stdout, "%*s%-*s = %" PRId32 "\n", (int) indent, "", (int) nameWidth, fieldName, (int32_t) Swap32(fieldPtr, info) );
break;
case sizeof(int64_t):
fprintf(stdout, "%*s%-*s = %" PRId64 "\n", (int) indent, "", (int) nameWidth, fieldName, (int64_t) Swap64(fieldPtr, info) );
break;
default:
FPHex(fieldName, fieldSize, fieldPtr, indent, nameWidth, verbose, info);
break;
}
}
extern void FPUDec(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a field as an unsigned decimal. There's special case code for each common
// size (8 bits, 16 bits, 32 bits, and 64 bits), and other sizes are printed as
// a hex dump.
//
// See definition of FPPrinter for a parameter description.
{
#pragma unused(info)
assert( FPStandardPreCondition() );
switch (fieldSize) {
case sizeof(uint8_t):
fprintf(stdout, "%*s%-*s = %" PRIu8 "\n", (int) indent, "", (int) nameWidth, fieldName, *((uint8_t *) fieldPtr) );
break;
case sizeof(uint16_t):
fprintf(stdout, "%*s%-*s = %" PRIu16 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap16(fieldPtr, info) );
break;
case sizeof(uint32_t):
fprintf(stdout, "%*s%-*s = %" PRIu32 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap32(fieldPtr, info) );
break;
case sizeof(uint64_t):
fprintf(stdout, "%*s%-*s = %" PRIu64 "\n", (int) indent, "", (int) nameWidth, fieldName, Swap64(fieldPtr, info) );
break;
default:
FPHex(fieldName, fieldSize, fieldPtr, indent, nameWidth, verbose, info);
break;
}
}
extern void FPSize(
const char * fieldName,
size_t fieldSize,
const void * fieldPtr,
uint32_t indent,
size_t nameWidth,
uint32_t verbose,
const void * info
)
// Prints a field in decimal along with an interpretation of the field as