xref: /onnv-gate/usr/src/lib/libnsl/dial/strecpy.c (revision 1219:f89f56c2d9ac)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate 
230Sstevel@tonic-gate /*
24*1219Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25132Srobinson  * Use is subject to license terms.
26132Srobinson  */
27132Srobinson 
28132Srobinson /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29132Srobinson /*	  All Rights Reserved	*/
30132Srobinson 
31132Srobinson #pragma ident	"%Z%%M%	%I%	%E% SMI"
32132Srobinson 
33*1219Sraf #include "mt.h"
34*1219Sraf #include "uucp.h"
350Sstevel@tonic-gate 
36132Srobinson #ifndef SMALL
37132Srobinson /*
38132Srobinson  *	strecpy(output, input, except)
39132Srobinson  *	strccpy copys the input string to the output string expanding
40132Srobinson  *	any non-graphic character with the C escape sequence.
41132Srobinson  *	Escape sequences produced are those defined in "The C Programming
42132Srobinson  *	Language" pages 180-181.
43132Srobinson  *	Characters in the except string will not be expanded.
44132Srobinson  */
45132Srobinson 
46132Srobinson static char *
strecpy(char * pout,char * pin,char * except)47132Srobinson strecpy(char *pout, char *pin, char *except)
480Sstevel@tonic-gate {
49132Srobinson 	unsigned	c;
50132Srobinson 	char		*output;
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	output = pout;
530Sstevel@tonic-gate 	while ((c = *pin++) != 0) {
54132Srobinson 		if (!isprint(c) && (!except || !strchr(except, c))) {
550Sstevel@tonic-gate 			*pout++ = '\\';
56132Srobinson 			switch (c) {
570Sstevel@tonic-gate 			case '\n':
580Sstevel@tonic-gate 				*pout++ = 'n';
590Sstevel@tonic-gate 				continue;
600Sstevel@tonic-gate 			case '\t':
610Sstevel@tonic-gate 				*pout++ = 't';
620Sstevel@tonic-gate 				continue;
630Sstevel@tonic-gate 			case '\b':
640Sstevel@tonic-gate 				*pout++ = 'b';
650Sstevel@tonic-gate 				continue;
660Sstevel@tonic-gate 			case '\r':
670Sstevel@tonic-gate 				*pout++ = 'r';
680Sstevel@tonic-gate 				continue;
690Sstevel@tonic-gate 			case '\f':
700Sstevel@tonic-gate 				*pout++ = 'f';
710Sstevel@tonic-gate 				continue;
720Sstevel@tonic-gate 			case '\v':
730Sstevel@tonic-gate 				*pout++ = 'v';
740Sstevel@tonic-gate 				continue;
750Sstevel@tonic-gate 			case '\\':
760Sstevel@tonic-gate 				continue;
770Sstevel@tonic-gate 			default:
780Sstevel@tonic-gate 				sprintf(pout, "%.3o", c);
790Sstevel@tonic-gate 				pout += 3;
800Sstevel@tonic-gate 				continue;
810Sstevel@tonic-gate 			}
820Sstevel@tonic-gate 		}
83132Srobinson 		if (c == '\\' && (!except || !strchr(except, c)))
840Sstevel@tonic-gate 			*pout++ = '\\';
85132Srobinson 		*pout++ = (char)c;
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 	*pout = '\0';
88132Srobinson 	return (output);
890Sstevel@tonic-gate }
90132Srobinson #endif
91