1*b722e422Schristos /* $NetBSD: strerror_ss.c,v 1.2 2017/01/12 00:43:55 christos Exp $ */
22a1a34d5Schristos
32a1a34d5Schristos /*-
42a1a34d5Schristos * Copyright (c) 2017 The NetBSD Foundation, Inc.
52a1a34d5Schristos * All rights reserved.
62a1a34d5Schristos *
72a1a34d5Schristos * This code is derived from software contributed to The NetBSD Foundation
82a1a34d5Schristos * by Christos Zoulas.
92a1a34d5Schristos *
102a1a34d5Schristos * Redistribution and use in source and binary forms, with or without
112a1a34d5Schristos * modification, are permitted provided that the following conditions
122a1a34d5Schristos * are met:
132a1a34d5Schristos * 1. Redistributions of source code must retain the above copyright
142a1a34d5Schristos * notice, this list of conditions and the following disclaimer.
152a1a34d5Schristos * 2. Redistributions in binary form must reproduce the above copyright
162a1a34d5Schristos * notice, this list of conditions and the following disclaimer in the
172a1a34d5Schristos * documentation and/or other materials provided with the distribution.
182a1a34d5Schristos *
192a1a34d5Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
202a1a34d5Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
212a1a34d5Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
222a1a34d5Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
232a1a34d5Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
242a1a34d5Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
252a1a34d5Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
262a1a34d5Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
272a1a34d5Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
282a1a34d5Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
292a1a34d5Schristos * POSSIBILITY OF SUCH DAMAGE.
302a1a34d5Schristos */
312a1a34d5Schristos #include <sys/cdefs.h>
32*b722e422Schristos __RCSID("$NetBSD: strerror_ss.c,v 1.2 2017/01/12 00:43:55 christos Exp $");
332a1a34d5Schristos
342a1a34d5Schristos #include "namespace.h"
352a1a34d5Schristos
362a1a34d5Schristos #include <errno.h>
372a1a34d5Schristos #include <stdio.h>
382a1a34d5Schristos #include <string.h>
392a1a34d5Schristos
402a1a34d5Schristos #include "extern.h"
412a1a34d5Schristos
422a1a34d5Schristos #ifdef __weak_alias
__weak_alias(strerror_r_ss,_strerror_r_ss)432a1a34d5Schristos __weak_alias(strerror_r_ss,_strerror_r_ss)
442a1a34d5Schristos #endif
452a1a34d5Schristos
462a1a34d5Schristos int
472a1a34d5Schristos strerror_r_ss(int num, char *buf, size_t len)
482a1a34d5Schristos {
492a1a34d5Schristos if (num >= 0 || num < sys_nerr)
502a1a34d5Schristos strlcpy(buf, sys_errlist[num], len);
512a1a34d5Schristos else
522a1a34d5Schristos snprintf_ss(buf, len, "Unknown error %d", num);
532a1a34d5Schristos return 0;
542a1a34d5Schristos }
552a1a34d5Schristos
562a1a34d5Schristos __aconst char *
strerror_ss(int num)572a1a34d5Schristos strerror_ss(int num)
582a1a34d5Schristos {
592a1a34d5Schristos static char buf[64];
602a1a34d5Schristos
612a1a34d5Schristos strerror_r_ss(num, buf, sizeof(buf));
622a1a34d5Schristos return buf;
632a1a34d5Schristos }
64