xref: /titanic_44/usr/src/lib/libnsl/dial/strecpy.c (revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968)
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 2006 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 "mt.h"
34 #include "uucp.h"
35 
36 #ifndef SMALL
37 /*
38  *	strecpy(output, input, except)
39  *	strccpy copys the input string to the output string expanding
40  *	any non-graphic character with the C escape sequence.
41  *	Escape sequences produced are those defined in "The C Programming
42  *	Language" pages 180-181.
43  *	Characters in the except string will not be expanded.
44  */
45 
46 static char *
47 strecpy(char *pout, char *pin, char *except)
48 {
49 	unsigned	c;
50 	char		*output;
51 
52 	output = pout;
53 	while ((c = *pin++) != 0) {
54 		if (!isprint(c) && (!except || !strchr(except, c))) {
55 			*pout++ = '\\';
56 			switch (c) {
57 			case '\n':
58 				*pout++ = 'n';
59 				continue;
60 			case '\t':
61 				*pout++ = 't';
62 				continue;
63 			case '\b':
64 				*pout++ = 'b';
65 				continue;
66 			case '\r':
67 				*pout++ = 'r';
68 				continue;
69 			case '\f':
70 				*pout++ = 'f';
71 				continue;
72 			case '\v':
73 				*pout++ = 'v';
74 				continue;
75 			case '\\':
76 				continue;
77 			default:
78 				sprintf(pout, "%.3o", c);
79 				pout += 3;
80 				continue;
81 			}
82 		}
83 		if (c == '\\' && (!except || !strchr(except, c)))
84 			*pout++ = '\\';
85 		*pout++ = (char)c;
86 	}
87 	*pout = '\0';
88 	return (output);
89 }
90 #endif
91