xref: /illumos-gate/usr/src/lib/libnsl/dial/strecpy.c (revision 1da57d55)
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  */
227c478bd9Sstevel@tonic-gate 
2361961e0fSrobinson /*
24*e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2561961e0fSrobinson  * Use is subject to license terms.
2661961e0fSrobinson  */
2761961e0fSrobinson 
2861961e0fSrobinson /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2961961e0fSrobinson /*	  All Rights Reserved	*/
307c478bd9Sstevel@tonic-gate 
31*e8031f0aSraf #include "mt.h"
32*e8031f0aSraf #include "uucp.h"
337c478bd9Sstevel@tonic-gate 
3461961e0fSrobinson #ifndef SMALL
357c478bd9Sstevel@tonic-gate /*
3661961e0fSrobinson  *	strecpy(output, input, except)
3761961e0fSrobinson  *	strccpy copys the input string to the output string expanding
3861961e0fSrobinson  *	any non-graphic character with the C escape sequence.
3961961e0fSrobinson  *	Escape sequences produced are those defined in "The C Programming
4061961e0fSrobinson  *	Language" pages 180-181.
4161961e0fSrobinson  *	Characters in the except string will not be expanded.
4261961e0fSrobinson  */
437c478bd9Sstevel@tonic-gate 
4461961e0fSrobinson static char *
strecpy(char * pout,char * pin,char * except)4561961e0fSrobinson strecpy(char *pout, char *pin, char *except)
467c478bd9Sstevel@tonic-gate {
4761961e0fSrobinson 	unsigned	c;
4861961e0fSrobinson 	char		*output;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	output = pout;
517c478bd9Sstevel@tonic-gate 	while ((c = *pin++) != 0) {
5261961e0fSrobinson 		if (!isprint(c) && (!except || !strchr(except, c))) {
537c478bd9Sstevel@tonic-gate 			*pout++ = '\\';
5461961e0fSrobinson 			switch (c) {
557c478bd9Sstevel@tonic-gate 			case '\n':
567c478bd9Sstevel@tonic-gate 				*pout++ = 'n';
577c478bd9Sstevel@tonic-gate 				continue;
587c478bd9Sstevel@tonic-gate 			case '\t':
597c478bd9Sstevel@tonic-gate 				*pout++ = 't';
607c478bd9Sstevel@tonic-gate 				continue;
617c478bd9Sstevel@tonic-gate 			case '\b':
627c478bd9Sstevel@tonic-gate 				*pout++ = 'b';
637c478bd9Sstevel@tonic-gate 				continue;
647c478bd9Sstevel@tonic-gate 			case '\r':
657c478bd9Sstevel@tonic-gate 				*pout++ = 'r';
667c478bd9Sstevel@tonic-gate 				continue;
677c478bd9Sstevel@tonic-gate 			case '\f':
687c478bd9Sstevel@tonic-gate 				*pout++ = 'f';
697c478bd9Sstevel@tonic-gate 				continue;
707c478bd9Sstevel@tonic-gate 			case '\v':
717c478bd9Sstevel@tonic-gate 				*pout++ = 'v';
727c478bd9Sstevel@tonic-gate 				continue;
737c478bd9Sstevel@tonic-gate 			case '\\':
747c478bd9Sstevel@tonic-gate 				continue;
757c478bd9Sstevel@tonic-gate 			default:
767c478bd9Sstevel@tonic-gate 				sprintf(pout, "%.3o", c);
777c478bd9Sstevel@tonic-gate 				pout += 3;
787c478bd9Sstevel@tonic-gate 				continue;
797c478bd9Sstevel@tonic-gate 			}
807c478bd9Sstevel@tonic-gate 		}
8161961e0fSrobinson 		if (c == '\\' && (!except || !strchr(except, c)))
827c478bd9Sstevel@tonic-gate 			*pout++ = '\\';
8361961e0fSrobinson 		*pout++ = (char)c;
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 	*pout = '\0';
8661961e0fSrobinson 	return (output);
877c478bd9Sstevel@tonic-gate }
8861961e0fSrobinson #endif
89