Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Feb 2001 04:05:34 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        "Kenneth D. Merry" <ken@kdm.org>
Cc:        arch@FreeBSD.ORG
Subject:   Re: sbufs in userland
Message-ID:  <Pine.BSF.4.21.0102270336450.19382-100000@besplex.bde.org>
In-Reply-To: <20010226003319.A19994@panzer.kdm.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 26 Feb 2001, Kenneth D. Merry wrote:

> ...
> I would like to use the sbuf(9) interface to do the string formatting,
> since it is fairly superior to my current string formatting method (see
> scsi_sense_string() in sys/cam/scsi/scsi_all.c).
> ...

> Code without sbufs:
> 
> 	switch (error_code) {
> 	case SSD_DEFERRED_ERROR:
> 		retlen = snprintf(tmpstr, tmpstrlen, "Deferred Error: ");
> 
> 		if ((tmplen = str_len - cur_len - 1) < 0)
> 			goto sst_bailout;
> 
> 		strncat(str, tmpstr, tmplen);
> 		cur_len += retlen;
> 		str[str_len - 1] = '\0';
> 		/* FALLTHROUGH */

This seems to be insufficiently large to be correct :-).  It doesn't check
for snprintf failing (retlen == -1) or truncating (retlen >= tmpstrlen).

> 
> Code with sbufs:
> 
> 	switch (error_code) {
> 	case SSD_DEFERRED_ERROR:
> 		sbuf_printf(sb, "Deferred Error: ");
> 
> 		/* FALLTHROUGH */

Code with an funopen(3)'d stream:

	switch (error_code) {
	case SSD_DEFERRED_ERROR:
		fprintf(fp, "Deferred Error: ");

		/* FALLTHROUGH */

:-).

funopen() is more general than sbufs, so it is not quite as easy to use,
but I think it is easy enough.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0102270336450.19382-100000>