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 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 /* LINTLIBRARY */ 31 32 #if defined(__STDC__) 33 #include "stdarg.h" 34 #else 35 #include "varargs.h" 36 #endif 37 38 #include "string.h" 39 #include "errno.h" 40 #include "stdlib.h" 41 42 #include "lp.h" 43 44 /** 45 ** makepath() - CREATE PATHNAME FROM COMPONENTS 46 **/ 47 48 /*VARARGS1*/ 49 char * 50 #if defined(__STDC__) 51 makepath ( 52 char * s, 53 ... 54 ) 55 #else 56 makepath (s, va_alist) 57 char * s; 58 va_dcl 59 #endif 60 { 61 va_list ap; 62 63 register char *component, 64 *p, 65 *q; 66 67 register int len; 68 69 char *ret; 70 71 72 #if defined(__STDC__) 73 va_start (ap, s); 74 #else 75 va_start (ap); 76 #endif 77 78 for (len = strlen(s) + 1; (component = va_arg(ap, char *)); ) 79 len += strlen(component) + 1; 80 81 va_end (ap); 82 83 if (!len) { 84 errno = 0; 85 return (0); 86 } 87 88 if (!(ret = Malloc(len))) { 89 errno = ENOMEM; 90 return (0); 91 } 92 93 #if defined(__STDC__) 94 va_start (ap, s); 95 #else 96 va_start (ap); 97 #endif 98 99 for ( 100 p = ret, component = s; 101 component; 102 component = va_arg(ap, char *) 103 ) { 104 for (q = component; *q; ) 105 *p++ = *q++; 106 *p++ = '/'; 107 } 108 p[-1] = 0; 109 110 va_end (ap); 111 112 return (ret); 113 } 114