xref: /freebsd/sbin/ipf/libipf/printbuf.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert 
1041edb306SCy Schubert #include <ctype.h>
1141edb306SCy Schubert 
1241edb306SCy Schubert #include "ipf.h"
1341edb306SCy Schubert 
1441edb306SCy Schubert 
1541edb306SCy Schubert void
printbuf(char * buf,int len,int zend)16*efeb8bffSCy Schubert printbuf(char *buf, int len, int zend)
1741edb306SCy Schubert {
1841edb306SCy Schubert 	char *s;
1941edb306SCy Schubert 	int c;
2041edb306SCy Schubert 	int i;
2141edb306SCy Schubert 
2241edb306SCy Schubert 	for (s = buf, i = len; i; i--) {
2341edb306SCy Schubert 		c = *s++;
2441edb306SCy Schubert 		if (isprint(c))
2541edb306SCy Schubert 			putchar(c);
2641edb306SCy Schubert 		else
2741edb306SCy Schubert 			PRINTF("\\%03o", c);
2841edb306SCy Schubert 		if ((c == '\0') && zend)
2941edb306SCy Schubert 			break;
3041edb306SCy Schubert 	}
3141edb306SCy Schubert }
32