1253476Sjimharris/*-
2253476Sjimharris * Copyright (C) 2013 Intel Corporation
3253476Sjimharris * Copyright (C) 1997 Justin T. Gibbs
4253476Sjimharris * All rights reserved.
5253476Sjimharris *
6253476Sjimharris * Redistribution and use in source and binary forms, with or without
7253476Sjimharris * modification, are permitted provided that the following conditions
8253476Sjimharris * are met:
9253476Sjimharris * 1. Redistributions of source code must retain the above copyright
10253476Sjimharris *    notice, this list of conditions and the following disclaimer.
11253476Sjimharris * 2. Redistributions in binary form must reproduce the above copyright
12253476Sjimharris *    notice, this list of conditions and the following disclaimer in the
13253476Sjimharris *    documentation and/or other materials provided with the distribution.
14253476Sjimharris *
15253476Sjimharris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16253476Sjimharris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17253476Sjimharris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18253476Sjimharris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19253476Sjimharris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20253476Sjimharris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21253476Sjimharris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22253476Sjimharris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23253476Sjimharris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24253476Sjimharris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25253476Sjimharris * SUCH DAMAGE.
26253476Sjimharris */
27253476Sjimharris
28253476Sjimharris#include <sys/cdefs.h>
29253476Sjimharris__FBSDID("$FreeBSD$");
30253476Sjimharris
31253476Sjimharris#include <sys/param.h>
32253476Sjimharris#include <dev/nvme/nvme.h>
33253476Sjimharris
34253476Sjimharrisvoid
35253476Sjimharrisnvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen)
36253476Sjimharris{
37253476Sjimharris	uint8_t *cur_pos;
38253476Sjimharris
39253476Sjimharris	/* Trim leading/trailing spaces, nulls. */
40253476Sjimharris	while (srclen > 0 && src[0] == ' ')
41253476Sjimharris		src++, srclen--;
42253476Sjimharris	while (srclen > 0
43253476Sjimharris	    && (src[srclen - 1] == ' ' || src[srclen - 1] == '\0'))
44253476Sjimharris		srclen--;
45253476Sjimharris
46253476Sjimharris	while (srclen > 0 && dstlen > 1) {
47253476Sjimharris		cur_pos = dst;
48253476Sjimharris
49253476Sjimharris		/* Show '?' for non-printable characters. */
50253476Sjimharris		if (*src < 0x20 || *src >= 0x7F)
51253476Sjimharris			*cur_pos++ = '?';
52253476Sjimharris		else
53253476Sjimharris			*cur_pos++ = *src;
54253476Sjimharris		src++;
55253476Sjimharris		srclen--;
56253476Sjimharris		dstlen -= cur_pos - dst;
57253476Sjimharris		dst = cur_pos;
58253476Sjimharris	}
59253476Sjimharris	*dst = '\0';
60253476Sjimharris}
61253476Sjimharris
62