00001 /* 00002 * Copyright 2004, 2005 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* 00006 00007 Copyright (C) 1999-2001, Silicon Graphics, Inc. All Rights Reserved. 00008 00009 This program is free software; you can redistribute it and/or modify it 00010 under the terms of version 2.1 of the GNU Lesser General Public License 00011 as published by the Free Software Foundation. 00012 00013 This program is distributed in the hope that it would be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any 00016 license provided herein, whether implied or otherwise, is limited to 00017 this program in accordance with the express provisions of the 00018 GNU Lesser General Public License. 00019 00020 Patent licenses, if any, provided herein do not apply to combinations 00021 of this program with other product or programs, or any other product 00022 whatsoever. This program is distributed without any warranty that the 00023 program is delivered free of the rightful claim of any third person by 00024 way of infringement or the like. 00025 00026 See the GNU Lesser General Public License for more details. 00027 00028 You should have received a copy of the GNU General Public License along 00029 with this program; if not, write the Free Software Foundation, Inc., 59 00030 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00031 00032 */ 00033 00034 /* $Header: /proj/osprey/CVS/open64/osprey1.0/libU77/getcwd_.c,v 1.1.1.1 2005/10/21 19:00:00 marcel Exp $ */ 00035 /* 00036 * Get pathname of current working directory. 00037 * 00038 * calling sequence -32bit: 00039 * character*128 path 00040 * integer *4 getcwd, ierr 00041 * ierr = getcwd(path) 00042 * calling sequence -64bit: 00043 * character*128 path 00044 * integer *8 getcwd, ierr 00045 * ierr = getcwd(path) 00046 * or alternatively (-32bit and -64bit): 00047 * character*128 path 00048 * call getcwd(path) 00049 * where: 00050 * path will receive the pathname of the current working directory. 00051 * ierr will be non-zero if successful 00052 */ 00053 00054 #include <errno.h> 00055 #include <unistd.h> 00056 #include <sys/param.h> 00057 #ifndef MAXPATHLEN 00058 #define MAXPATHLEN 128 00059 #endif 00060 #include "externals.h" 00061 00062 #ifdef KEY /* Bug 1683 */ 00063 00064 #include "pathf90_libU_intrin.h" 00065 00066 pathf90_i4 00067 pathf90_getcwd(char *path, pathf90_i4 *status, int len) 00068 { 00069 char *p; 00070 char pathname[MAXPATHLEN]; 00071 pathf90_i4 junk; 00072 status = (0 == status) ? (&junk) : status; 00073 00074 /* Bug 3349: Modern Unix should have 2-arg getcwd; if the target OS is 00075 * unexpected, the code should fail instead of silently compiling with 00076 * neither getwd nor getcwd . 00077 */ 00078 # if defined(__linux) || defined(BUILD_OS_DARWIN) 00079 p = getcwd(pathname,MAXPATHLEN); 00080 # else 00081 # error "Check function getwd/getcwd signature" 00082 # endif 00083 00084 b_char(pathname, path, len); 00085 if (p) 00086 return(*status = 0); 00087 else 00088 return(*status = errno); 00089 } 00090 00091 #else 00092 00093 extern long 00094 getcwd_(char *path, int len) 00095 00096 { 00097 char *p; 00098 char pathname[MAXPATHLEN]; 00099 00100 #ifdef KEY 00101 /* Bug 3349: Modern Unix should have 2-arg getcwd; if the target OS is 00102 * unexpected, the code should fail instead of silently compiling with 00103 * neither getwd nor getcwd . 00104 */ 00105 # ifdef __linux 00106 p = getcwd(pathname,MAXPATHLEN); 00107 # else 00108 # error "Check function getwd/getcwd signature" 00109 # endif 00110 #else 00111 #ifdef _BSD 00112 extern char *getwd(); /* sjc #nit 27Jan88 */ 00113 p = getwd(pathname); 00114 #endif /* _BSD */ 00115 #if defined(_SYSV) || defined(_SYSTYPE_SVR4) 00116 p = getcwd(pathname,MAXPATHLEN); /* AGC #710 2/17/87 */ 00117 #endif /* _SYSV */ 00118 #endif /* KEY */ 00119 00120 b_char(pathname, path, len); 00121 #ifdef __sgi 00122 return((long)p); 00123 #else 00124 if (p) 00125 return(0); 00126 else 00127 return(errno); 00128 #endif 00129 } 00130 00131 #endif /* KEY Bug 1683 */
1.5.6