ypclnt_error.c revision 256281
1178476Sjb/*- 2178476Sjb * Copyright (c) 2002 Networks Associates Technology, Inc. 3178476Sjb * All rights reserved. 4178476Sjb * 5178476Sjb * This software was developed for the FreeBSD Project by ThinkSec AS and 6178476Sjb * NAI Labs, the Security Research Division of Network Associates, Inc. 7178476Sjb * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 8178476Sjb * DARPA CHATS research program. 9178476Sjb * 10178476Sjb * Redistribution and use in source and binary forms, with or without 11178476Sjb * modification, are permitted provided that the following conditions 12178476Sjb * are met: 13178476Sjb * 1. Redistributions of source code must retain the above copyright 14178476Sjb * notice, this list of conditions and the following disclaimer. 15178476Sjb * 2. Redistributions in binary form must reproduce the above copyright 16178476Sjb * notice, this list of conditions and the following disclaimer in the 17178476Sjb * documentation and/or other materials provided with the distribution. 18178476Sjb * 3. The name of the author may not be used to endorse or promote 19178476Sjb * products derived from this software without specific prior written 20178476Sjb * permission. 21178476Sjb * 22178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25178476Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26178476Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27178476Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28178476Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29178476Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30178476Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31178476Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32178476Sjb * SUCH DAMAGE. 33178476Sjb * 34178476Sjb * $FreeBSD: stable/10/lib/libypclnt/ypclnt_error.c 94575 2002-04-13 06:20:02Z des $ 35178476Sjb */ 36178476Sjb 37178476Sjb#include <stdarg.h> 38178476Sjb#include <stdio.h> 39178476Sjb#include <stdlib.h> 40178476Sjb 41178476Sjb#include "ypclnt.h" 42178476Sjb 43178476Sjbvoid 44178476Sjbypclnt_error(ypclnt_t *ypclnt, const char *func, const char *fmt, ...) 45178476Sjb{ 46178476Sjb char *errmsg; 47178476Sjb va_list ap; 48178476Sjb 49178476Sjb free(ypclnt->error); 50178476Sjb ypclnt->error = NULL; 51178476Sjb if (fmt == NULL) 52178476Sjb return; 53178476Sjb 54178476Sjb va_start(ap, fmt); 55178476Sjb vasprintf(&errmsg, fmt, ap); 56178476Sjb va_end(ap); 57178476Sjb asprintf(&ypclnt->error, "%s(): %s", func, errmsg); 58178476Sjb free(errmsg); 59178476Sjb} 60178476Sjb