main.c
static char *
extract(const uint8_t * buf, size_t buflen)
{
	char * s;

	/* Advance past leading spaces. */
	while ((buflen > 0) && (buf[0] == ' ')) {
		buf++;
		buflen--;
	}

	/* Remove trailing NULs and spaces. */
	while (buflen > 0) {
		if ((buf[buflen - 1] == '\0') || (buf[buflen - 1] == ' '))
			buflen--;
		else
			break;
	}

	/* Duplicate what's left. */
	if ((s = malloc(buflen + 1)) == NULL)
		err(1, "malloc");
	memcpy(s, buf, buflen);
	s[buflen] = '\0';

	/* Return extracted string. */
	return (s);
}
/* Extract a string from NVMe metadata. */
Extract a string from NVMe metadata.
Extract a string from NVMe metadata .
static char *
extract(const uint8_t * buf, size_t buflen)
{
	char * s;
	while ((buflen > 0) && (buf[0] == ' ')) {
		buf++;
		buflen--;
	}
	while (buflen > 0) {
		if ((buf[buflen - 1] == '\0') || (buf[buflen - 1] == ' '))
			buflen--;
		else
			break;
	}
	if ((s = malloc(buflen + 1)) == NULL)
		err(1, "malloc");
	memcpy(s, buf, buflen);
	s[buflen] = '\0';
	return (s);
}
static char * extract ( const uint8_t * buf , size_t buflen ) { char * s ; while ( ( buflen > 0 ) && ( buf [ 0 ] == ' ' ) ) { buf ++ ; buflen -- ; } while ( buflen > 0 ) { if ( ( buf [ buflen - 1 ] == ' \0 ' ) || ( buf [ buflen - 1 ] == ' ' ) ) buflen -- ; else break ; } if ( ( s = malloc ( buflen + 1 ) ) == NULL ) err ( 1 , " " ) ; memcpy ( s , buf , buflen ) ; s [ buflen ] = ' \0 ' ; return ( s ) ; }
Extract a string from NVMe metadata.
Extract a string from NVMe metadata .
/* Advance past leading spaces. */ /* Remove trailing NULs and spaces. */ /* Duplicate what's left. */ /* Return extracted string. */