xref: /titanic_44/usr/src/lib/libnsl/dial/strecpy.c (revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
2261961e0fSrobinson 
2361961e0fSrobinson /*
24*e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2561961e0fSrobinson  * Use is subject to license terms.
2661961e0fSrobinson  */
2761961e0fSrobinson 
287c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
297c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
307c478bd9Sstevel@tonic-gate 
3161961e0fSrobinson #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
33*e8031f0aSraf #include "mt.h"
347c478bd9Sstevel@tonic-gate #include "uucp.h"
357c478bd9Sstevel@tonic-gate 
3661961e0fSrobinson #ifndef SMALL
377c478bd9Sstevel@tonic-gate /*
3861961e0fSrobinson  *	strecpy(output, input, except)
3961961e0fSrobinson  *	strccpy copys the input string to the output string expanding
4061961e0fSrobinson  *	any non-graphic character with the C escape sequence.
4161961e0fSrobinson  *	Escape sequences produced are those defined in "The C Programming
4261961e0fSrobinson  *	Language" pages 180-181.
4361961e0fSrobinson  *	Characters in the except string will not be expanded.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
4661961e0fSrobinson static char *
strecpy(char * pout,char * pin,char * except)4761961e0fSrobinson strecpy(char *pout, char *pin, char *except)
487c478bd9Sstevel@tonic-gate {
4961961e0fSrobinson 	unsigned	c;
5061961e0fSrobinson 	char		*output;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	output = pout;
537c478bd9Sstevel@tonic-gate 	while ((c = *pin++) != 0) {
547c478bd9Sstevel@tonic-gate 		if (!isprint(c) && (!except || !strchr(except, c))) {
557c478bd9Sstevel@tonic-gate 			*pout++ = '\\';
567c478bd9Sstevel@tonic-gate 			switch (c) {
577c478bd9Sstevel@tonic-gate 			case '\n':
587c478bd9Sstevel@tonic-gate 				*pout++ = 'n';
597c478bd9Sstevel@tonic-gate 				continue;
607c478bd9Sstevel@tonic-gate 			case '\t':
617c478bd9Sstevel@tonic-gate 				*pout++ = 't';
627c478bd9Sstevel@tonic-gate 				continue;
637c478bd9Sstevel@tonic-gate 			case '\b':
647c478bd9Sstevel@tonic-gate 				*pout++ = 'b';
657c478bd9Sstevel@tonic-gate 				continue;
667c478bd9Sstevel@tonic-gate 			case '\r':
677c478bd9Sstevel@tonic-gate 				*pout++ = 'r';
687c478bd9Sstevel@tonic-gate 				continue;
697c478bd9Sstevel@tonic-gate 			case '\f':
707c478bd9Sstevel@tonic-gate 				*pout++ = 'f';
717c478bd9Sstevel@tonic-gate 				continue;
727c478bd9Sstevel@tonic-gate 			case '\v':
737c478bd9Sstevel@tonic-gate 				*pout++ = 'v';
747c478bd9Sstevel@tonic-gate 				continue;
757c478bd9Sstevel@tonic-gate 			case '\\':
767c478bd9Sstevel@tonic-gate 				continue;
777c478bd9Sstevel@tonic-gate 			default:
787c478bd9Sstevel@tonic-gate 				sprintf(pout, "%.3o", c);
797c478bd9Sstevel@tonic-gate 				pout += 3;
807c478bd9Sstevel@tonic-gate 				continue;
817c478bd9Sstevel@tonic-gate 			}
827c478bd9Sstevel@tonic-gate 		}
837c478bd9Sstevel@tonic-gate 		if (c == '\\' && (!except || !strchr(except, c)))
847c478bd9Sstevel@tonic-gate 			*pout++ = '\\';
857c478bd9Sstevel@tonic-gate 		*pout++ = (char)c;
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 	*pout = '\0';
887c478bd9Sstevel@tonic-gate 	return (output);
897c478bd9Sstevel@tonic-gate }
9061961e0fSrobinson #endif
91