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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
|
<table class="head">
<tr>
<td class="head-ltitle">NV(9)</td>
<td class="head-vol">Kernel Developer's Manual</td>
<td class="head-rtitle">NV(9)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">nvlist_create</code>,
<code class="Nm">nvlist_destroy</code>,
<code class="Nm">nvlist_error</code>,
<code class="Nm">nvlist_set_error</code>,
<code class="Nm">nvlist_empty</code>, <code class="Nm">nvlist_flags</code>,
<code class="Nm">nvlist_exists</code>, <code class="Nm">nvlist_free</code>,
<code class="Nm">nvlist_clone</code>, <code class="Nm">nvlist_dump</code>,
<code class="Nm">nvlist_fdump</code>, <code class="Nm">nvlist_size</code>,
<code class="Nm">nvlist_pack</code>, <code class="Nm">nvlist_unpack</code>,
<code class="Nm">nvlist_send</code>, <code class="Nm">nvlist_recv</code>,
<code class="Nm">nvlist_xfer</code>,
<code class="Nm">nvlist_in_array</code>,
<code class="Nm">nvlist_next</code>, <code class="Nm">nvlist_add</code>,
<code class="Nm">nvlist_move</code>, <code class="Nm">nvlist_get</code>,
<code class="Nm">nvlist_take</code>, <code class="Nm">nvlist_append</code>
— <span class="Nd">library for name/value pairs</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
<p class="Pp"><span class="Lb">Name/value pairs library (libnv, -lnv)</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">sys/nv.h</a>></code></p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_create</code>(<var class="Fa" style="white-space: nowrap;">int
flags</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_destroy</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">nvlist_error</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_set_error</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">int
error</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_empty</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">nvlist_flags</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_in_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_clone</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_dump</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">int
fd</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_fdump</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">FILE
*fp</var>);</p>
<p class="Pp"><var class="Ft">size_t</var>
<br/>
<code class="Fn">nvlist_size</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">void *</var>
<br/>
<code class="Fn">nvlist_pack</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">size_t
*sizep</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_unpack</code>(<var class="Fa" style="white-space: nowrap;">const
void *buf</var>, <var class="Fa" style="white-space: nowrap;">size_t
size</var>, <var class="Fa" style="white-space: nowrap;">int
flags</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">nvlist_send</code>(<var class="Fa" style="white-space: nowrap;">int
sock</var>, <var class="Fa" style="white-space: nowrap;">const nvlist_t
*nvl</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_recv</code>(<var class="Fa" style="white-space: nowrap;">int
sock</var>, <var class="Fa" style="white-space: nowrap;">int
flags</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_xfer</code>(<var class="Fa" style="white-space: nowrap;">int
sock</var>, <var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">int
flags</var>);</p>
<p class="Pp"><var class="Ft">const char *</var>
<br/>
<code class="Fn">nvlist_next</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">int
*typep</var>, <var class="Fa" style="white-space: nowrap;">void
**cookiep</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_type</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int
type</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_null</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_bool</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_number</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_string</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_nvlist</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_descriptor</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_binary</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_bool_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_number_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_string_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_exists_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_null</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_bool</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">bool
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_number</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">uint64_t
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_string</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const char
*value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_stringf</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const char
*valuefmt</var>,
<var class="Fa" style="white-space: nowrap;">...</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_stringv</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const char
*valuefmt</var>, <var class="Fa" style="white-space: nowrap;">va_list
valueap</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_nvlist</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const nvlist_t
*value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_descriptor</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_binary</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const void
*value</var>, <var class="Fa" style="white-space: nowrap;">size_t
size</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_bool_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const bool
*value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_number_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const uint64_t
*value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_string_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const char * const
* value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const nvlist_t *
const * value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_add_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const int
*value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_string</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">char
*value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_nvlist</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">nvlist_t
*value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_descriptor</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_binary</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">void *value</var>,
<var class="Fa" style="white-space: nowrap;">size_t size</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_bool_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">bool *value</var>,
<var class="Fa" style="white-space: nowrap;">size_t nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_number_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">uint64_t
*value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_string_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">char
**value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">nvlist_t
**value</var>, <var class="Fa" style="white-space: nowrap;">size_t
nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_move_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int *value</var>,
<var class="Fa" style="white-space: nowrap;">size_t nitems</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_get_bool</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">uint64_t</var>
<br/>
<code class="Fn">nvlist_get_number</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">const char *</var>
<br/>
<code class="Fn">nvlist_get_string</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">const nvlist_t *</var>
<br/>
<code class="Fn">nvlist_get_nvlist</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">nvlist_get_descriptor</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">const void *</var>
<br/>
<code class="Fn">nvlist_get_binary</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*sizep</var>);</p>
<p class="Pp"><var class="Ft">const bool *</var>
<br/>
<code class="Fn">nvlist_get_bool_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">const uint64_t *</var>
<br/>
<code class="Fn">nvlist_get_number_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">const char * const *</var>
<br/>
<code class="Fn">nvlist_get_string_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">const nvlist_t * const *</var>
<br/>
<code class="Fn">nvlist_get_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">const int *</var>
<br/>
<code class="Fn">nvlist_get_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">const nvlist_t *</var>
<br/>
<code class="Fn">nvlist_get_parent</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">void
**cookiep</var>);</p>
<p class="Pp"><var class="Ft">const nvlist_t *</var>
<br/>
<code class="Fn">nvlist_get_array_next</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>);</p>
<p class="Pp"><var class="Ft">const nvlist_t *</var>
<br/>
<code class="Fn">nvlist_get_pararr</code>(<var class="Fa" style="white-space: nowrap;">const
nvlist_t *nvl</var>, <var class="Fa" style="white-space: nowrap;">void
**cookiep</var>);</p>
<p class="Pp"><var class="Ft">bool</var>
<br/>
<code class="Fn">nvlist_take_bool</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">uint64_t</var>
<br/>
<code class="Fn">nvlist_take_number</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">char *</var>
<br/>
<code class="Fn">nvlist_take_string</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t *</var>
<br/>
<code class="Fn">nvlist_take_nvlist</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">nvlist_take_descriptor</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void *</var>
<br/>
<code class="Fn">nvlist_take_binary</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*sizep</var>);</p>
<p class="Pp"><var class="Ft">bool *</var>
<br/>
<code class="Fn">nvlist_take_bool_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">uint64_t **</var>
<br/>
<code class="Fn">nvlist_take_number_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">char **</var>
<br/>
<code class="Fn">nvlist_take_string_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">nvlist_t **</var>
<br/>
<code class="Fn">nvlist_take_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">int *</var>
<br/>
<code class="Fn">nvlist_take_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">size_t
*nitems</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_append_bool_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const bool
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_append_number_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const uint64_t
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_append_string_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const char * const
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_append_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">const nvlist_t *
const value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_append_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int
value</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_type</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>, <var class="Fa" style="white-space: nowrap;">int
type</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_null</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_bool</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_number</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_string</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_nvlist</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_descriptor</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_binary</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_bool_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_number_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_string_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_nvlist_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">nvlist_free_descriptor_array</code>(<var class="Fa" style="white-space: nowrap;">nvlist_t
*nvl</var>, <var class="Fa" style="white-space: nowrap;">const char
*name</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The <code class="Nm">libnv</code> library permits creating and
managing name value pairs as well as sending and receiving them over
sockets. A group (list) of name value pairs is called an
<code class="Nm">nvlist</code>. The API supports the following data types
for values:</p>
<dl class="Bl-ohang Bd-indent">
<dt id="null"><a class="permalink" href="#null"><b class="Sy">null</b></a>
(<a class="permalink" href="#NV_TYPE_NULL"><b class="Sy" id="NV_TYPE_NULL">NV_TYPE_NULL</b></a>)</dt>
<dd>There is no data associated with the name.</dd>
<dt id="bool"><a class="permalink" href="#bool"><b class="Sy">bool</b></a>
(<a class="permalink" href="#NV_TYPE_BOOL"><b class="Sy" id="NV_TYPE_BOOL">NV_TYPE_BOOL</b></a>)</dt>
<dd>The value can be either <code class="Dv">true</code> or
<code class="Dv">false</code>.</dd>
<dt id="number"><a class="permalink" href="#number"><b class="Sy">number</b></a>
(<a class="permalink" href="#NV_TYPE_NUMBER"><b class="Sy" id="NV_TYPE_NUMBER">NV_TYPE_NUMBER</b></a>)</dt>
<dd>The value is a number stored as <var class="Vt">uint64_t</var>.</dd>
<dt id="string"><a class="permalink" href="#string"><b class="Sy">string</b></a>
(<a class="permalink" href="#NV_TYPE_STRING"><b class="Sy" id="NV_TYPE_STRING">NV_TYPE_STRING</b></a>)</dt>
<dd>The value is a C string.</dd>
<dt id="nvlist"><a class="permalink" href="#nvlist"><b class="Sy">nvlist</b></a>
(<a class="permalink" href="#NV_TYPE_NVLIST"><b class="Sy" id="NV_TYPE_NVLIST">NV_TYPE_NVLIST</b></a>)</dt>
<dd>The value is a nested nvlist.</dd>
<dt id="descriptor"><a class="permalink" href="#descriptor"><b class="Sy">descriptor</b></a>
(<a class="permalink" href="#NV_TYPE_DESCRIPTOR"><b class="Sy" id="NV_TYPE_DESCRIPTOR">NV_TYPE_DESCRIPTOR</b></a>)</dt>
<dd>The value is a file descriptor. Note that file descriptors can be sent
only over <a class="Xr">unix(4)</a> domain sockets.</dd>
<dt id="binary"><a class="permalink" href="#binary"><b class="Sy">binary</b></a>
(<a class="permalink" href="#NV_TYPE_BINARY"><b class="Sy" id="NV_TYPE_BINARY">NV_TYPE_BINARY</b></a>)</dt>
<dd>The value is a binary buffer.</dd>
<dt id="NV_TYPE_BOOL_ARRAY"><b class="Sy">bool array</b>
(<a class="permalink" href="#NV_TYPE_BOOL_ARRAY"><b class="Sy">NV_TYPE_BOOL_ARRAY</b></a>)</dt>
<dd>The value is an array of boolean values.</dd>
<dt id="NV_TYPE_NUMBER_ARRAY"><b class="Sy">number array</b>
(<a class="permalink" href="#NV_TYPE_NUMBER_ARRAY"><b class="Sy">NV_TYPE_NUMBER_ARRAY</b></a>)</dt>
<dd>The value is an array of numbers, each stored as
<var class="Vt">uint64_t</var>.</dd>
<dt id="NV_TYPE_STRING_ARRAY"><b class="Sy">string array</b>
(<a class="permalink" href="#NV_TYPE_STRING_ARRAY"><b class="Sy">NV_TYPE_STRING_ARRAY</b></a>)</dt>
<dd>The value is an array of C strings.</dd>
<dt id="NV_TYPE_NVLIST_ARRAY"><b class="Sy">nvlist array</b>
(<a class="permalink" href="#NV_TYPE_NVLIST_ARRAY"><b class="Sy">NV_TYPE_NVLIST_ARRAY</b></a>)</dt>
<dd>The value is an array of nvlists. When an nvlist is added to an array, it
becomes part of the primary nvlist. Traversing these arrays can be done
using the
<a class="permalink" href="#nvlist_get_array_next"><code class="Fn" id="nvlist_get_array_next">nvlist_get_array_next</code></a>()
and <code class="Fn">nvlist_get_pararr</code>() functions.</dd>
<dt id="NV_TYPE_DESCRIPTOR_ARRAY"><b class="Sy">descriptor array</b>
(<a class="permalink" href="#NV_TYPE_DESCRIPTOR_ARRAY"><b class="Sy">NV_TYPE_DESCRIPTOR_ARRAY</b></a>)</dt>
<dd>The value is an array of files descriptors.</dd>
</dl>
<p class="Pp" id="nvlist_create">The
<a class="permalink" href="#nvlist_create"><code class="Fn">nvlist_create</code></a>()
function allocates memory and initializes an nvlist.</p>
<p class="Pp">The following flags can be provided:</p>
<p class="Pp"></p>
<div class="Bd-indent">
<dl class="Bl-tag Bl-compact">
<dt id="NV_FLAG_IGNORE_CASE"><a class="permalink" href="#NV_FLAG_IGNORE_CASE"><code class="Dv">NV_FLAG_IGNORE_CASE</code></a></dt>
<dd>Perform case-insensitive lookups of provided names.</dd>
<dt id="NV_FLAG_NO_UNIQUE"><a class="permalink" href="#NV_FLAG_NO_UNIQUE"><code class="Dv">NV_FLAG_NO_UNIQUE</code></a></dt>
<dd>Names in the nvlist do not have to be unique.</dd>
</dl>
</div>
<p class="Pp" id="nvlist_destroy">The
<a class="permalink" href="#nvlist_destroy"><code class="Fn">nvlist_destroy</code></a>()
function destroys the given nvlist. This function does nothing if
<var class="Fa">nvl</var> is <code class="Dv">NULL</code>. This function
never modifies <var class="Va">errno</var>.</p>
<p class="Pp" id="nvlist_error">The
<a class="permalink" href="#nvlist_error"><code class="Fn">nvlist_error</code></a>()
function returns the first error set on <var class="Fa">nvl</var>. If
<var class="Fa">nvl</var> is not in the error state, this function returns
zero. If <var class="Fa">nvl</var> is <code class="Dv">NULL</code>,
<code class="Er">ENOMEM</code> is returned.</p>
<p class="Pp" id="nvlist_set_error">The
<a class="permalink" href="#nvlist_set_error"><code class="Fn">nvlist_set_error</code></a>()
function sets an the error value for <var class="Fa">nvl</var>. Subsequent
calls to <code class="Fn">nvlist_error</code>() will return
<var class="Fa">error</var>. This function cannot be used to clear the error
state from an nvlist. This function does nothing if the nvlist is already in
the error state.</p>
<p class="Pp" id="nvlist_empty">The
<a class="permalink" href="#nvlist_empty"><code class="Fn">nvlist_empty</code></a>()
function returns <code class="Dv">true</code> if <var class="Fa">nvl</var>
is empty and <code class="Dv">false</code> otherwise. The nvlist must not be
in the error state.</p>
<p class="Pp" id="nvlist_flags">The
<a class="permalink" href="#nvlist_flags"><code class="Fn">nvlist_flags</code></a>()
function returns the flags used to create <var class="Fa">nvl</var> with the
<code class="Fn">nvlist_create</code>(),
<code class="Fn">nvlist_recv</code>(),
<code class="Fn">nvlist_unpack</code>(), or
<code class="Fn">nvlist_xfer</code>() functions.</p>
<p class="Pp" id="nvlist_in_array">The
<a class="permalink" href="#nvlist_in_array"><code class="Fn">nvlist_in_array</code></a>()
function returns <code class="Dv">true</code> if <var class="Fa">nvl</var>
is part of an array that is a member of another nvlist.</p>
<p class="Pp" id="nvlist_clone">The
<a class="permalink" href="#nvlist_clone"><code class="Fn">nvlist_clone</code></a>()
function clones <var class="Fa">nvl</var>. The clone shares no resources
with its origin. This also means that all file descriptors that are part of
the nvlist will be duplicated with the <a class="Xr">dup(2)</a> system call
before placing them in the clone.</p>
<p class="Pp" id="nvlist_dump">The
<a class="permalink" href="#nvlist_dump"><code class="Fn">nvlist_dump</code></a>()
function dumps nvlist content for debugging purposes to the file descriptor
<var class="Fa">fd</var>.</p>
<p class="Pp" id="nvlist_fdump">The
<a class="permalink" href="#nvlist_fdump"><code class="Fn">nvlist_fdump</code></a>()
dumps nvlist content for debugging purposes to the file stream
<var class="Fa">fp</var>.</p>
<p class="Pp" id="nvlist_size">The
<a class="permalink" href="#nvlist_size"><code class="Fn">nvlist_size</code></a>()
function returns the size of the binary buffer that would be generated by
the <code class="Fn">nvlist_pack</code>() function.</p>
<p class="Pp" id="nvlist_pack">The
<a class="permalink" href="#nvlist_pack"><code class="Fn">nvlist_pack</code></a>()
function converts the given nvlist to a binary buffer. The function
allocates memory for the buffer which should be freed with the
<a class="Xr">free(3)</a> function. If the <var class="Fa">sizep</var>
argument is not <code class="Dv">NULL</code>, the size of the buffer is
stored there. This function returns <code class="Dv">NULL</code> in case of
an error (allocation failure). If the nvlist contains any file descriptors
<code class="Dv">NULL</code> will be returned. The nvlist must not be in the
error state.</p>
<p class="Pp" id="nvlist_unpack">The
<a class="permalink" href="#nvlist_unpack"><code class="Fn">nvlist_unpack</code></a>()
function converts a binary buffer to a new nvlist. The
<var class="Fa">flags</var> argument has the same meaning as the
<var class="Fa">flags</var> argument passed to
<code class="Fn">nvlist_create</code>(). If <var class="Fa">flags</var> do
not match the flags used to create the initial nvlist before it was packed,
this function will fail. The flags of nested nvlists are not validated by
this function. The caller is responsible for validating the flags on any
nested nvlists using <code class="Fn">nvlist_flags</code>(). This function
returns the new nvlist on success or <code class="Dv">NULL</code> in case of
an error.</p>
<p class="Pp" id="nvlist_send">The
<a class="permalink" href="#nvlist_send"><code class="Fn">nvlist_send</code></a>()
function sends <var class="Fa">nvl</var> over the socket
<var class="Fa">sock</var>. Note that nvlists that contain file descriptors
can only be sent over <a class="Xr">unix(4)</a> domain sockets.</p>
<p class="Pp" id="nvlist_recv">The
<a class="permalink" href="#nvlist_recv"><code class="Fn">nvlist_recv</code></a>()
function receives an nvlist over the socket <var class="Fa">sock</var>. As
with <code class="Fn">nvlist_unpack</code>(), the
<var class="Fa">flags</var> argument is used to construct the new nvlist and
must match the flags used to construct the original nvlist written to
<var class="Fa">sock</var> by the peer. The flags of nested nvlists are not
validated by this function. The caller is responsible for validating the
flags on any nested nvlists using <code class="Fn">nvlist_flags</code>().
This function returns the new nvlist on success or
<code class="Dv">NULL</code> in case of an error.</p>
<p class="Pp" id="nvlist_xfer">The
<a class="permalink" href="#nvlist_xfer"><code class="Fn">nvlist_xfer</code></a>()
function sends <var class="Fa">nvl</var> over the socket
<var class="Fa">sock</var> argument and then receives a new nvlist over the
same socket. The <var class="Fa">flags</var> argument applies to the new
nvlist similar to <code class="Fn">nvlist_recv</code>(). The nvlist
<var class="Fa">nvl</var> is always destroyed. This function returns the new
nvlist on success or <code class="Dv">NULL</code> in case of an error.</p>
<p class="Pp" id="nvlist_next">The
<a class="permalink" href="#nvlist_next"><code class="Fn">nvlist_next</code></a>()
function iterates over <var class="Fa">nvl</var> returning the names and
types of subsequent elements. The <var class="Fa">cookiep</var> argument
determines which element is returned. If <var class="Va">*cookiep</var> is
<code class="Dv">NULL</code>, the values for the first element in the list
are returned. Otherwise, <var class="Va">*cookiep</var> should contain the
result of a prior call to <code class="Fn">nvlist_next</code>() in which
case values for the next element from <var class="Fa">nvl</var> are
returned. This function returns <code class="Dv">NULL</code> when there are
no more elements on <var class="Fa">nvl</var>. The
<var class="Fa">typep</var> argument can be <code class="Dv">NULL</code>.
Elements may not be removed from <var class="Fa">nvl</var> the nvlist while
traversing it. <var class="Fa">nvl</var> must not be in the error state.
Additional actions can be performed on an element identified by a cookie via
the <a class="Xr">cnv(9)</a> API .</p>
<p class="Pp" id="nvlist_exists">The
<a class="permalink" href="#nvlist_exists"><code class="Fn">nvlist_exists</code></a>()
function returns <code class="Dv">true</code> if an element named
<var class="Fa">name</var> exists in <var class="Fa">nvl</var> (regardless
of type) or <code class="Dv">false</code> otherwise. The nvlist must not be
in the error state.</p>
<p class="Pp" id="nvlist_exists_type">The
<a class="permalink" href="#nvlist_exists_type"><code class="Fn">nvlist_exists_type</code></a>()
function returns <code class="Dv">true</code> if an element named
<var class="Fa">name</var> of type <var class="Fa">type</var> exists or
<code class="Dv">false</code> otherwise. The nvlist must not be in the error
state.</p>
<p class="Pp" id="nvlist_exists_null">The
<a class="permalink" href="#nvlist_exists_null"><code class="Fn">nvlist_exists_null</code></a>(),
<a class="permalink" href="#nvlist_exists_bool"><code class="Fn" id="nvlist_exists_bool">nvlist_exists_bool</code></a>(),
<a class="permalink" href="#nvlist_exists_number"><code class="Fn" id="nvlist_exists_number">nvlist_exists_number</code></a>(),
<a class="permalink" href="#nvlist_exists_string"><code class="Fn" id="nvlist_exists_string">nvlist_exists_string</code></a>(),
<a class="permalink" href="#nvlist_exists_nvlist"><code class="Fn" id="nvlist_exists_nvlist">nvlist_exists_nvlist</code></a>(),
<a class="permalink" href="#nvlist_exists_descriptor"><code class="Fn" id="nvlist_exists_descriptor">nvlist_exists_descriptor</code></a>(),
<a class="permalink" href="#nvlist_exists_binary"><code class="Fn" id="nvlist_exists_binary">nvlist_exists_binary</code></a>(),
<a class="permalink" href="#nvlist_exists_bool_array"><code class="Fn" id="nvlist_exists_bool_array">nvlist_exists_bool_array</code></a>(),
<a class="permalink" href="#nvlist_exists_number_array"><code class="Fn" id="nvlist_exists_number_array">nvlist_exists_number_array</code></a>(),
<a class="permalink" href="#nvlist_exists_string_array"><code class="Fn" id="nvlist_exists_string_array">nvlist_exists_string_array</code></a>(),
<a class="permalink" href="#nvlist_exists_nvlist_array"><code class="Fn" id="nvlist_exists_nvlist_array">nvlist_exists_nvlist_array</code></a>(),
<a class="permalink" href="#nvlist_exists_descriptor_array"><code class="Fn" id="nvlist_exists_descriptor_array">nvlist_exists_descriptor_array</code></a>()
functions return <code class="Dv">true</code> if element named
<var class="Fa">name</var> with the type determined by the function name
exists or <code class="Dv">false</code> otherwise. The nvlist must not be in
the error state.</p>
<p class="Pp" id="nvlist_add_null">The
<a class="permalink" href="#nvlist_add_null"><code class="Fn">nvlist_add_null</code></a>(),
<a class="permalink" href="#nvlist_add_bool"><code class="Fn" id="nvlist_add_bool">nvlist_add_bool</code></a>(),
<a class="permalink" href="#nvlist_add_number"><code class="Fn" id="nvlist_add_number">nvlist_add_number</code></a>(),
<a class="permalink" href="#nvlist_add_string"><code class="Fn" id="nvlist_add_string">nvlist_add_string</code></a>(),
<a class="permalink" href="#nvlist_add_stringf"><code class="Fn" id="nvlist_add_stringf">nvlist_add_stringf</code></a>(),
<a class="permalink" href="#nvlist_add_stringv"><code class="Fn" id="nvlist_add_stringv">nvlist_add_stringv</code></a>(),
<a class="permalink" href="#nvlist_add_nvlist"><code class="Fn" id="nvlist_add_nvlist">nvlist_add_nvlist</code></a>(),
<a class="permalink" href="#nvlist_add_descriptor"><code class="Fn" id="nvlist_add_descriptor">nvlist_add_descriptor</code></a>(),
<a class="permalink" href="#nvlist_add_binary"><code class="Fn" id="nvlist_add_binary">nvlist_add_binary</code></a>(),
<a class="permalink" href="#nvlist_add_bool_array"><code class="Fn" id="nvlist_add_bool_array">nvlist_add_bool_array</code></a>(),
<a class="permalink" href="#nvlist_add_number_array"><code class="Fn" id="nvlist_add_number_array">nvlist_add_number_array</code></a>(),
<a class="permalink" href="#nvlist_add_string_array"><code class="Fn" id="nvlist_add_string_array">nvlist_add_string_array</code></a>(),
<code class="Fn">nvlist_add_nvlist_array</code>(),
<a class="permalink" href="#nvlist_add_descriptor_array"><code class="Fn" id="nvlist_add_descriptor_array">nvlist_add_descriptor_array</code></a>()
functions add an element to <var class="Fa">nvl</var>. When adding a string
or binary buffer, these functions allocate memory and copy the data. When
adding an nvlist, the <var class="Fa">value</var> nvlist is cloned and the
clone is added to <var class="Fa">nvl</var>. When adding a file descriptor,
the descriptor is duplicated via the <a class="Xr">dup(2)</a> system call
and the new file descriptor is added. The array functions fail if there are
any <code class="Dv">NULL</code> elements in the array, or if the array
pointer is <code class="Dv">NULL</code>. If an error occurs while adding a
new element, an internal error is set which can be examined using the
<code class="Fn">nvlist_error</code>() function.</p>
<p class="Pp" id="nvlist_move_string">The
<a class="permalink" href="#nvlist_move_string"><code class="Fn">nvlist_move_string</code></a>(),
<a class="permalink" href="#nvlist_move_nvlist"><code class="Fn" id="nvlist_move_nvlist">nvlist_move_nvlist</code></a>(),
<a class="permalink" href="#nvlist_move_descriptor"><code class="Fn" id="nvlist_move_descriptor">nvlist_move_descriptor</code></a>(),
<a class="permalink" href="#nvlist_move_binary"><code class="Fn" id="nvlist_move_binary">nvlist_move_binary</code></a>(),
<a class="permalink" href="#nvlist_move_bool_array"><code class="Fn" id="nvlist_move_bool_array">nvlist_move_bool_array</code></a>(),
<a class="permalink" href="#nvlist_move_number_array"><code class="Fn" id="nvlist_move_number_array">nvlist_move_number_array</code></a>(),
<a class="permalink" href="#nvlist_move_string_array"><code class="Fn" id="nvlist_move_string_array">nvlist_move_string_array</code></a>(),
<code class="Fn">nvlist_move_nvlist_array</code>(),
<a class="permalink" href="#nvlist_move_descriptor_array"><code class="Fn" id="nvlist_move_descriptor_array">nvlist_move_descriptor_array</code></a>()
functions add an element to <var class="Fa">nvl</var>, but unlike the
<a class="permalink" href="#nvlist_add__type_"><code class="Fn" id="nvlist_add__type_">nvlist_add_<type></code></a>()
functions they consume the given resource. For string, file descriptor,
binary buffer, or nvlist values, no value should be moved into an nvlist
multiple times; doing so will cause that value to be freed multiple times.
Note that strings or binary buffers must be allocated with
<a class="Xr">malloc(3)</a>, and the pointers will be released via
<a class="Xr">free(3)</a> when <var class="Fa">nvl</var> is destroyed. The
array functions fail if there are any <code class="Dv">NULL</code> elements,
or if the array pointer is <code class="Dv">NULL</code>. If an error occurs
while adding new element, the resource is destroyed and an internal error is
set which can be examined using the <code class="Fn">nvlist_error</code>()
function.</p>
<p class="Pp" id="nvlist_get_bool">The
<a class="permalink" href="#nvlist_get_bool"><code class="Fn">nvlist_get_bool</code></a>(),
<a class="permalink" href="#nvlist_get_number"><code class="Fn" id="nvlist_get_number">nvlist_get_number</code></a>(),
<a class="permalink" href="#nvlist_get_string"><code class="Fn" id="nvlist_get_string">nvlist_get_string</code></a>(),
<a class="permalink" href="#nvlist_get_nvlist"><code class="Fn" id="nvlist_get_nvlist">nvlist_get_nvlist</code></a>(),
<a class="permalink" href="#nvlist_get_descriptor"><code class="Fn" id="nvlist_get_descriptor">nvlist_get_descriptor</code></a>(),
<a class="permalink" href="#nvlist_get_binary"><code class="Fn" id="nvlist_get_binary">nvlist_get_binary</code></a>(),
<a class="permalink" href="#nvlist_get_bool_array"><code class="Fn" id="nvlist_get_bool_array">nvlist_get_bool_array</code></a>(),
<a class="permalink" href="#nvlist_get_number_array"><code class="Fn" id="nvlist_get_number_array">nvlist_get_number_array</code></a>(),
<a class="permalink" href="#nvlist_get_string_array"><code class="Fn" id="nvlist_get_string_array">nvlist_get_string_array</code></a>(),
<a class="permalink" href="#nvlist_get_nvlist_array"><code class="Fn" id="nvlist_get_nvlist_array">nvlist_get_nvlist_array</code></a>(),
<a class="permalink" href="#nvlist_get_descriptor_array"><code class="Fn" id="nvlist_get_descriptor_array">nvlist_get_descriptor_array</code></a>()
functions return the value of the first element in <var class="Fa">nvl</var>
named <var class="Fa">name</var>. For string, nvlist, file descriptor,
binary buffer, or array values, the returned resource must not be modified -
it still belongs to <var class="Fa">nvl</var>.</p>
<p class="Pp">If an element named <var class="Fa">name</var> does not exist, the
program aborts. To avoid this, the caller should check for the existence of
the element before trying to obtain the value or use the
<a class="Xr">dnv(9)</a> extension which provides a default value in the
case of a missing element.</p>
<p class="Pp">The nvlist must not be in the error state.</p>
<p class="Pp" id="nvlist_get_parent">The
<a class="permalink" href="#nvlist_get_parent"><code class="Fn">nvlist_get_parent</code></a>()
function returns the parent nvlist of <var class="Fa">nvl</var>.</p>
<p class="Pp" id="nvlist_get_array_next~2">The
<a class="permalink" href="#nvlist_get_array_next~2"><code class="Fn">nvlist_get_array_next</code></a>()
function returns the next element after <var class="Fa">nvl</var> from an
array of nvlists. If <var class="Fa">nvl</var> is not in an array of nvlists
or it is the last element, this function returns
<code class="Dv">NULL</code>. An nvlist is only in an nvlist array if it was
added to an nvlist array using
<a class="permalink" href="#nvlist_add_nvlist_array"><code class="Fn" id="nvlist_add_nvlist_array">nvlist_add_nvlist_array</code></a>(),
<a class="permalink" href="#nvlist_append_nvlist_array"><code class="Fn" id="nvlist_append_nvlist_array">nvlist_append_nvlist_array</code></a>(),
or
<a class="permalink" href="#nvlist_move_nvlist_array"><code class="Fn" id="nvlist_move_nvlist_array">nvlist_move_nvlist_array</code></a>().</p>
<p class="Pp" id="nvlist_get_pararr">The
<a class="permalink" href="#nvlist_get_pararr"><code class="Fn">nvlist_get_pararr</code></a>()
function returns the next element after
<a class="permalink" href="#nvl"><code class="Fn" id="nvl">nvl</code></a>()
from an array of nvlists. If <code class="Fn">nvl</code>() is the last
element in an array of nvlists, the parent nvlist of <var class="Fa">nvl
is</var> returned. If <code class="Fn">nvl</code>() is not in an array of
nvlists, <code class="Dv">NULL</code> is returned.</p>
<p class="Pp" id="nvlist_take_bool">The
<a class="permalink" href="#nvlist_take_bool"><code class="Fn">nvlist_take_bool</code></a>(),
<a class="permalink" href="#nvlist_take_number"><code class="Fn" id="nvlist_take_number">nvlist_take_number</code></a>(),
<a class="permalink" href="#nvlist_take_string"><code class="Fn" id="nvlist_take_string">nvlist_take_string</code></a>(),
<a class="permalink" href="#nvlist_take_nvlist"><code class="Fn" id="nvlist_take_nvlist">nvlist_take_nvlist</code></a>(),
<a class="permalink" href="#nvlist_take_descriptor"><code class="Fn" id="nvlist_take_descriptor">nvlist_take_descriptor</code></a>(),
<a class="permalink" href="#nvlist_take_binary"><code class="Fn" id="nvlist_take_binary">nvlist_take_binary</code></a>(),
<a class="permalink" href="#nvlist_take_bool_array"><code class="Fn" id="nvlist_take_bool_array">nvlist_take_bool_array</code></a>(),
<a class="permalink" href="#nvlist_take_number_array"><code class="Fn" id="nvlist_take_number_array">nvlist_take_number_array</code></a>(),
<a class="permalink" href="#nvlist_take_string_array"><code class="Fn" id="nvlist_take_string_array">nvlist_take_string_array</code></a>(),
<a class="permalink" href="#nvlist_take_nvlist_array"><code class="Fn" id="nvlist_take_nvlist_array">nvlist_take_nvlist_array</code></a>(),
<a class="permalink" href="#nvlist_take_descriptor_array"><code class="Fn" id="nvlist_take_descriptor_array">nvlist_take_descriptor_array</code></a>()
functions return the value of the element named <var class="Fa">name</var>
and remove the element from <var class="Fa">nvl</var>. For string and binary
buffer values, the caller is responsible for freeing the returned value
using the <a class="Xr">free(3)</a> function. For nvlist values, the caller
is responsible for destroying the returned nvlist using the
<code class="Fn">nvlist_destroy</code>() function. For file descriptor
values, the caller is responsible for closing the returned descriptor using
the
<a class="permalink" href="#close"><code class="Fn" id="close">close</code></a>(<var class="Fa">2</var>)
system call. For array values, the caller is responsible for destroying
every element of the array based on the element type. In addition, the
caller must also free the pointer to the array using the
<a class="Xr">free(3)</a> function.</p>
<p class="Pp">If an element named <var class="Fa">name</var> does not exist, the
program aborts. To avoid this, the caller should check for the existence of
the element before trying to obtain the value or use the
<a class="Xr">dnv(9)</a> extension which provides a default value in the
case of a missing element.</p>
<p class="Pp">The nvlist must not be in the error state.</p>
<p class="Pp" id="nvlist_append_bool_array">The
<a class="permalink" href="#nvlist_append_bool_array"><code class="Fn">nvlist_append_bool_array</code></a>(),
<a class="permalink" href="#nvlist_append_number_array"><code class="Fn" id="nvlist_append_number_array">nvlist_append_number_array</code></a>(),
<a class="permalink" href="#nvlist_append_string_array"><code class="Fn" id="nvlist_append_string_array">nvlist_append_string_array</code></a>(),
<code class="Fn">nvlist_append_nvlist_array</code>(),
<a class="permalink" href="#nvlist_append_descriptor_array"><code class="Fn" id="nvlist_append_descriptor_array">nvlist_append_descriptor_array</code></a>()
functions append an element to an existing array using the same semantics as
the add functions (that is, the element will be copied when applicable). If
the array named <var class="Fa">name</var> does not exist, then it will be
created as if using the
<a class="permalink" href="#nvlist_add__type__array"><code class="Fn" id="nvlist_add__type__array">nvlist_add_<type>_array</code></a>()
function. If an error occurs while appending a new element, an internal
error is set on <var class="Fa">nvl</var>.</p>
<p class="Pp" id="nvlist_free">The
<a class="permalink" href="#nvlist_free"><code class="Fn">nvlist_free</code></a>()
function removes the first element named <var class="Fa">name</var> from
<var class="Fa">nvl</var> (regardless of type) and frees all resources
associated with it. If no element named <var class="Fa">name</var> exists,
the program aborts. The nvlist must not be in the error state.</p>
<p class="Pp" id="nvlist_free_type">The
<a class="permalink" href="#nvlist_free_type"><code class="Fn">nvlist_free_type</code></a>()
function removes the first element named <var class="Fa">name</var> of type
<var class="Fa">type</var> from <var class="Fa">nvl</var> and frees all
resources associated with it. If no element named <var class="Fa">name</var>
of type <var class="Fa">type</var> exists, the program aborts. The nvlist
must not be in the error state.</p>
<p class="Pp" id="nvlist_free_null">The
<a class="permalink" href="#nvlist_free_null"><code class="Fn">nvlist_free_null</code></a>(),
<a class="permalink" href="#nvlist_free_bool"><code class="Fn" id="nvlist_free_bool">nvlist_free_bool</code></a>(),
<a class="permalink" href="#nvlist_free_number"><code class="Fn" id="nvlist_free_number">nvlist_free_number</code></a>(),
<a class="permalink" href="#nvlist_free_string"><code class="Fn" id="nvlist_free_string">nvlist_free_string</code></a>(),
<a class="permalink" href="#nvlist_free_nvlist"><code class="Fn" id="nvlist_free_nvlist">nvlist_free_nvlist</code></a>(),
<a class="permalink" href="#nvlist_free_descriptor"><code class="Fn" id="nvlist_free_descriptor">nvlist_free_descriptor</code></a>(),
<a class="permalink" href="#nvlist_free_binary"><code class="Fn" id="nvlist_free_binary">nvlist_free_binary</code></a>(),
<a class="permalink" href="#nvlist_free_bool_array"><code class="Fn" id="nvlist_free_bool_array">nvlist_free_bool_array</code></a>(),
<a class="permalink" href="#nvlist_free_number_array"><code class="Fn" id="nvlist_free_number_array">nvlist_free_number_array</code></a>(),
<a class="permalink" href="#nvlist_free_string_array"><code class="Fn" id="nvlist_free_string_array">nvlist_free_string_array</code></a>(),
<a class="permalink" href="#nvlist_free_nvlist_array"><code class="Fn" id="nvlist_free_nvlist_array">nvlist_free_nvlist_array</code></a>(),
<a class="permalink" href="#nvlist_free_descriptor_array"><code class="Fn" id="nvlist_free_descriptor_array">nvlist_free_descriptor_array</code></a>()
functions remove the first element named <var class="Fa">name</var> with the
type determined by the function name from <var class="Fa">nvl</var> free all
resources associated with it. If no element named <var class="Fa">name</var>
with the appropriate type exists, the program aborts. The nvlist must not be
in the error state.</p>
<section class="Ss">
<h2 class="Ss" id="Notes"><a class="permalink" href="#Notes">Notes</a></h2>
<p class="Pp">The <code class="Fn">nvlist_pack</code>() and
<code class="Fn">nvlist_unpack</code>() functions handle byte-order
conversions, so binary buffers can be packed and unpacked on hosts with
different endianness.</p>
<p class="Pp" id="nvlist_recv~2">The
<a class="permalink" href="#nvlist_recv~2"><code class="Fn">nvlist_recv</code></a>(),
<code class="Fn">nvlist_send</code>(), and
<code class="Fn">nvlist_xfer</code>() functions can transfer nvlists between
hosts with different endianness.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="Kernel_Considerations"><a class="permalink" href="#Kernel_Considerations">Kernel
Considerations</a></h2>
<p class="Pp">The <code class="Nm">nv</code>, <code class="Nm">cnv</code>, and
<code class="Nm">dnv</code> APIs can be used in the kernel with the
following differences:</p>
<ul class="Bl-bullet">
<li>File descriptor and file descriptor array value types are not
supported.</li>
<li><code class="Fn">nvlist_recv</code>(),
<code class="Fn">nvlist_send</code>(), and
<code class="Fn">nvlist_xfer</code>() are not supported.</li>
<li>All memory allocations use the <code class="Dv">M_NVLIST</code> memory
type with <a class="Xr">malloc(9)</a> and <a class="Xr">free(9)</a>. As a
result, any allocated buffers moved into an nvlist must be allocated with
<code class="Dv">M_NVLIST</code>, and buffers returned by functions such
as <code class="Fn">nvlist_pack</code>() must be freed with
<code class="Dv">M_NVLIST</code>.</li>
</ul>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<p class="Pp">The following example demonstrates how to prepare an nvlist and
send it over a <a class="Xr">unix(4)</a> domain socket.</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl;
int fd;
fd = open("/tmp/foo", O_RDONLY);
if (fd < 0)
err(1, "open(\"/tmp/foo\") failed");
nvl = nvlist_create(0);
/*
* There is no need to check if nvlist_create() succeeded
* as the nvlist_add_<type>() functions can cope.
* If it failed, nvlist_send() will fail.
*/
nvlist_add_string(nvl, "filename", "/tmp/foo");
nvlist_add_number(nvl, "flags", O_RDONLY);
/*
* We just want to send the descriptor, so we can give it
* for the nvlist to consume (that is why we use nvlist_move
* not nvlist_add).
*/
nvlist_move_descriptor(nvl, "fd", fd);
if (nvlist_send(sock, nvl) < 0) {
nvlist_destroy(nvl);
err(1, "nvlist_send() failed");
}
nvlist_destroy(nvl);</pre>
</div>
<p class="Pp">Receiving an nvlist and retrieving element values:</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl;
const char *command;
char *filename;
int fd;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
/* For command we accept a pointer to the nvlist's internal buffer. */
command = nvlist_get_string(nvl, "command");
/*
* For filename we remove it from the nvlist and take
* ownership of the buffer.
*/
filename = nvlist_take_string(nvl, "filename");
/* The same for the file descriptor. */
fd = nvlist_take_descriptor(nvl, "fd");
printf("command=%s filename=%s fd=%d0, command, filename, fd);
/* command is freed by nvlist_destroy() */
nvlist_destroy(nvl);
free(filename);
close(fd);</pre>
</div>
<p class="Pp">Iterating over an nvlist:</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
cookie = NULL;
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
printf("%s=", name);
switch (type) {
case NV_TYPE_NUMBER:
printf("%ju", (uintmax_t)nvlist_get_number(nvl, name));
break;
case NV_TYPE_STRING:
printf("%s", nvlist_get_string(nvl, name));
break;
default:
printf("N/A");
break;
}
printf("\n");
}</pre>
</div>
<p class="Pp">Iterating over every nested nvlist:</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
cookie = NULL;
do {
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
}
}
} while ((nvl = nvlist_get_parent(nvl, &cookie)) != NULL);</pre>
</div>
<p class="Pp">Iterating over every nested nvlist and every nvlist element:</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl;
const nvlist_t * const *array;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == null)
err(1, "nvlist_recv() failed");
cookie = NULL;
do {
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
} else if (type == NV_TYPE_NVLIST_ARRAY) {
nvl = nvlist_get_nvlist_array(nvl, name, NULL)[0];
cookie = NULL;
}
}
} while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);</pre>
</div>
<p class="Pp">Or alternatively:</p>
<div class="Bd Pp Li">
<pre>nvlist_t *nvl, *tmp;
const nvlist_t * const *array;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == null)
err(1, "nvlist_recv() failed");
cooke = NULL;
tmp = nvl;
do {
do {
nvl = tmp;
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
} else if (type == NV_TYPE_NVLIST_ARRAY) {
nvl = nvlist_get_nvlist_array(nvl, name,
NULL)[0];
cookie = NULL;
}
}
cookie = NULL;
} while ((tmp = nvlist_get_array_next(nvl)) != NULL);
} while ((tmp = nvlist_get_parent(nvl, &cookie)) != NULL);</pre>
</div>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">close(2)</a>, <a class="Xr">dup(2)</a>,
<a class="Xr">open(2)</a>, <a class="Xr">err(3)</a>,
<a class="Xr">free(3)</a>, <a class="Xr">printf(3)</a>,
<a class="Xr">unix(4)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Nm">libnv</code> library appeared in
<span class="Ux">FreeBSD 11.0</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">The <code class="Nm">libnv</code> library was implemented by
<span class="An">Pawel Jakub Dawidek</span>
<<a class="Mt" href="mailto:pawel@dawidek.net">pawel@dawidek.net</a>>
under sponsorship from the FreeBSD Foundation.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">January 3, 2025</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|