xref: /illumos-gate/usr/src/lib/libnsl/dial/strecpy.c (revision 814a60b13c0ad90e5d2edfd29a7a84bbf416cc1a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved	*/
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include	"uucp.h"
34 
35 #ifndef SMALL
36 /*
37  *	strecpy(output, input, except)
38  *	strccpy copys the input string to the output string expanding
39  *	any non-graphic character with the C escape sequence.
40  *	Escape sequences produced are those defined in "The C Programming
41  *	Language" pages 180-181.
42  *	Characters in the except string will not be expanded.
43  */
44 
45 static char *
46 strecpy(char *pout, char *pin, char *except)
47 {
48 	unsigned	c;
49 	char		*output;
50 
51 	output = pout;
52 	while ((c = *pin++) != 0) {
53 		if (!isprint(c) && (!except || !strchr(except, c))) {
54 			*pout++ = '\\';
55 			switch (c) {
56 			case '\n':
57 				*pout++ = 'n';
58 				continue;
59 			case '\t':
60 				*pout++ = 't';
61 				continue;
62 			case '\b':
63 				*pout++ = 'b';
64 				continue;
65 			case '\r':
66 				*pout++ = 'r';
67 				continue;
68 			case '\f':
69 				*pout++ = 'f';
70 				continue;
71 			case '\v':
72 				*pout++ = 'v';
73 				continue;
74 			case '\\':
75 				continue;
76 			default:
77 				sprintf(pout, "%.3o", c);
78 				pout += 3;
79 				continue;
80 			}
81 		}
82 		if (c == '\\' && (!except || !strchr(except, c)))
83 			*pout++ = '\\';
84 		*pout++ = (char)c;
85 	}
86 	*pout = '\0';
87 	return (output);
88 }
89 #endif
90