* config.gcc: Add sh-*-symbianelf target.
[official-gcc.git] / libgfortran / intrinsics / etime.c
blobcd11af927c6832217df27871dd4ed6bd03a818f8
1 /* Implementation of the ETIME intrinsic.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Contributed by Steven G. Kargl <kargls@comcast.net>.
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include <sys/types.h>
24 #include "libgfortran.h"
26 #include <stdio.h>
28 #if defined (HAVE_SYS_TIME_H) && defined (HAVE_SYS_RESOURCE_H)
29 #include <sys/time.h>
30 #include <sys/resource.h>
31 #endif
33 void
34 prefix(etime_sub) (gfc_array_r4 *t, GFC_REAL_4 *result)
36 GFC_REAL_4 tu, ts, tt, *tp;
37 index_type dim;
39 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
40 struct rusage rt;
42 if (getrusage(RUSAGE_SELF, &rt) == 0)
44 tu = (GFC_REAL_4)(rt.ru_utime.tv_sec + 1.e-6 * rt.ru_utime.tv_usec);
45 ts = (GFC_REAL_4)(rt.ru_stime.tv_sec + 1.e-6 * rt.ru_stime.tv_usec);
46 tt = tu + ts;
48 else
50 tu = -1.;
51 ts = -1.;
52 tt = -1.;
54 #else
55 tu = -1.;
56 ts = -1.;
57 tt = -1.;
58 #endif
60 if (((t->dim[0].ubound + 1 - t->dim[0].lbound)) < 2)
61 runtime_error ("Insufficient number of elements in TARRAY.");
63 if (t->dim[0].stride == 0)
64 t->dim[0].stride = 1;
66 tp = t->data;
68 *tp = tu;
69 tp += t->dim[0].stride;
70 *tp = ts;
71 *result = tt;
74 GFC_REAL_4
75 prefix(etime) (gfc_array_r4 *t)
77 GFC_REAL_4 val;
78 prefix(etime_sub) (t, &val);
79 return val;