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
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.
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]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984 AT&T */
28 /* All Rights Reserved */
29 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */
33 * Library routine to GET the Current Working Directory.
34 * arg1 is a pointer to a character buffer into which the
35 * path name of the current directory is placed by the
36 * subroutine. arg1 may be zero, in which case the
37 * subroutine will call malloc to get the required space.
38 * arg2 is the length of the buffer space for the path-name.
39 * If the actual path-name is longer than (arg2-2), or if
40 * the value of arg2 is not at least 3, the subroutine will
41 * return a value of zero, with errno set as appropriate.
45 #include <sys/errno.h>
48 extern char *malloc(), *fgets(), *strchr();
49 extern int errno
, pclose();
64 if((arg1
= malloc((unsigned)arg2
)) == 0) {
69 if((pipe
= popen("pwd", "r")) == 0)
71 (void) fgets(arg1
, arg2
, pipe
);
73 trm
= strchr(arg1
, '\0');
74 if(*(trm
-1) != '\n') {