diff options
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/Makefile.am | 1 | ||||
-rw-r--r-- | libgfortran/Makefile.in | 14 | ||||
-rw-r--r-- | libgfortran/intrinsics/getcwd.c | 71 |
3 files changed, 84 insertions, 2 deletions
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index 91d70b8..060166a 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -49,6 +49,7 @@ intrinsics/erf.c \ intrinsics/eoshift0.c \ intrinsics/eoshift2.c \ intrinsics/etime.c \ +intrinsics/getcwd.c \ intrinsics/getXid.c \ intrinsics/ishftc.c \ intrinsics/pack_generic.c \ diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index ded21b6..fb06ca5 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -120,8 +120,8 @@ am__objects_32 = backspace.lo close.lo endfile.lo format.lo inquire.lo \ unit.lo unix.lo write.lo am__objects_33 = associated.lo abort.lo args.lo bessel.lo \ c99_functions.lo cpu_time.lo cshift0.lo date_and_time.lo \ - env.lo erf.lo eoshift0.lo eoshift2.lo etime.lo getXid.lo \ - ishftc.lo pack_generic.lo size.lo spread_generic.lo \ + env.lo erf.lo eoshift0.lo eoshift2.lo etime.lo getcwd.lo \ + getXid.lo ishftc.lo pack_generic.lo size.lo spread_generic.lo \ string_intrinsics.lo rand.lo random.lo reshape_generic.lo \ reshape_packed.lo selected_int_kind.lo selected_real_kind.lo \ system_clock.lo transpose_generic.lo unpack_generic.lo \ @@ -321,6 +321,7 @@ intrinsics/erf.c \ intrinsics/eoshift0.c \ intrinsics/eoshift2.c \ intrinsics/etime.c \ +intrinsics/getcwd.c \ intrinsics/getXid.c \ intrinsics/ishftc.c \ intrinsics/pack_generic.c \ @@ -2086,6 +2087,15 @@ etime.obj: intrinsics/etime.c etime.lo: intrinsics/etime.c $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o etime.lo `test -f 'intrinsics/etime.c' || echo '$(srcdir)/'`intrinsics/etime.c +getcwd.o: intrinsics/getcwd.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getcwd.o `test -f 'intrinsics/getcwd.c' || echo '$(srcdir)/'`intrinsics/getcwd.c + +getcwd.obj: intrinsics/getcwd.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getcwd.obj `if test -f 'intrinsics/getcwd.c'; then $(CYGPATH_W) 'intrinsics/getcwd.c'; else $(CYGPATH_W) '$(srcdir)/intrinsics/getcwd.c'; fi` + +getcwd.lo: intrinsics/getcwd.c + $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getcwd.lo `test -f 'intrinsics/getcwd.c' || echo '$(srcdir)/'`intrinsics/getcwd.c + getXid.o: intrinsics/getXid.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getXid.o `test -f 'intrinsics/getXid.c' || echo '$(srcdir)/'`intrinsics/getXid.c diff --git a/libgfortran/intrinsics/getcwd.c b/libgfortran/intrinsics/getcwd.c new file mode 100644 index 0000000..86afa6c --- /dev/null +++ b/libgfortran/intrinsics/getcwd.c @@ -0,0 +1,71 @@ +/* Implementation of the GETCWD intrinsic. + Copyright (C) 2004 Free Software Foundation, Inc. + Contributed by Steven G. Kargl <kargls@comcast.net>. + +This file is part of the GNU Fortran 95 runtime library (libgfortran). + +Libgfortran is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +Libgfortran is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with libgfor; see the file COPYING.LIB. If not, +write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "libgfortran.h" + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include <errno.h> + +void +prefix(getcwd_i4_sub) (char * cwd, GFC_INTEGER_4 * status, + gfc_charlen_type cwd_len) +{ + char str[cwd_len + 1], *s; + GFC_INTEGER_4 stat; + + memset(cwd, ' ', (size_t) cwd_len); + + if (!getcwd (str, (size_t) cwd_len + 1)) + stat = errno; + else + { + stat = 0; + memcpy (cwd, str, strlen (str)); + } + if (status != NULL) + *status = stat; +} + +void +prefix(getcwd_i8_sub) (char * cwd, GFC_INTEGER_8 * status, + gfc_charlen_type cwd_len) +{ + GFC_INTEGER_4 status4; + + prefix (getcwd_i4_sub) (cwd, &status4, cwd_len); + if (status) + *status = status4; +} + +GFC_INTEGER_4 +prefix(getcwd) (char * cwd, gfc_charlen_type cwd_len) +{ + GFC_INTEGER_4 status; + prefix(getcwd_i4_sub) (cwd, &status, cwd_len); + return status; +} |