\hypertarget{asprintf_8c_source}{}\doxysection{asprintf.\+c}
\label{asprintf_8c_source}\index{libkern/asprintf.c@{libkern/asprintf.c}}
\mbox{\hyperlink{asprintf_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00002}00002 \textcolor{comment}{ * Copyright (c) 2013-\/2015 Sandvine Inc.  All rights reserved.}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00003}00003 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00004}00004 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00005}00005 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00006}00006 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00007}00007 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00008}00008 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00009}00009 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00010}00010 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00012}00012 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00013}00013 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00014}00014 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00015}00015 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00016}00016 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00017}00017 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00018}00018 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00019}00019 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00020}00020 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00021}00021 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00022}00022 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00023}00023 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00024}00024 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00025}00025 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00026}00026 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00027}00027 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00028}\mbox{\hyperlink{asprintf_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00028}} \mbox{\hyperlink{asprintf_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00029}00029 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00030}00030 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00031}00031 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00033}00033 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <machine/stdarg.h>}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00035}00035 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00036}00036 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00037}\mbox{\hyperlink{asprintf_8c_add39d68debc286d24e977d4bb1b11995}{00037}} \mbox{\hyperlink{asprintf_8c_add39d68debc286d24e977d4bb1b11995}{vasprintf}}(\textcolor{keywordtype}{char} **buf, \textcolor{keyword}{struct} malloc\_type *mtp, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *format, va\_list va)}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00038}00038 \{}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00039}00039         \textcolor{keywordtype}{int} len, ret;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00040}00040         va\_list tmp\_va;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00041}00041         \textcolor{keywordtype}{char} dummy;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00042}00042 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00043}00043         va\_copy(tmp\_va, va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00044}00044         len = vsnprintf(\&dummy, 0, format, tmp\_va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00045}00045         va\_end(tmp\_va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00046}00046         \textcolor{keywordflow}{if} (len < 0) \{}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00047}00047                 *buf = NULL;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00048}00048                 \textcolor{keywordflow}{return} (len);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00049}00049         \}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00050}00050 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00051}00051         \textcolor{comment}{/* Account for null terminator. */}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00052}00052         len += 1;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00053}00053         *buf = malloc(len, mtp, M\_NOWAIT);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00054}00054         \textcolor{keywordflow}{if} (*buf == NULL)}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00055}00055                 \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00056}00056 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00057}00057         ret = vsnprintf(*buf, len, format, va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00058}00058         \textcolor{keywordflow}{if} (ret < 0) \{}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00059}00059                 free(*buf, mtp);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00060}00060                 *buf = NULL;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00061}00061         \}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00062}00062 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00063}00063         \textcolor{keywordflow}{return} (ret);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00064}00064 \}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00065}00065 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00066}00066 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00067}\mbox{\hyperlink{asprintf_8c_a75051270738eeb36a0c7375c4c0bb225}{00067}} \mbox{\hyperlink{asprintf_8c_a75051270738eeb36a0c7375c4c0bb225}{asprintf}}(\textcolor{keywordtype}{char} **buf, \textcolor{keyword}{struct} malloc\_type *mtp, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *format, ...)}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00068}00068 \{}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00069}00069         \textcolor{keywordtype}{int} ret;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00070}00070         va\_list va;}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00071}00071 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00072}00072         va\_start(va, format);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00073}00073         ret = \mbox{\hyperlink{asprintf_8c_add39d68debc286d24e977d4bb1b11995}{vasprintf}}(buf, mtp, format, va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00074}00074         va\_end(va);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00075}00075 }
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00076}00076         \textcolor{keywordflow}{return} (ret);}
\DoxyCodeLine{\Hypertarget{asprintf_8c_source_l00077}00077 \}}

\end{DoxyCode}
