]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-libs-ch/wrapc.c
1 /* wrapc.c provide access to miscellaneous C library functions.
3 Copyright (C) 2005-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius@glam.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
32 #include "gm2-libs-host.h"
38 /* strtime - returns the address of a string which describes the
44 #if defined(HAVE_CTIME)
45 time_t clock
= time ((time_t *)0);
46 char *string
= ctime (&clock
);
57 wrapc_filesize (int f
, unsigned int *low
, unsigned int *high
)
60 int res
= fstat (f
, (struct stat
*)&s
);
64 *low
= (unsigned int)s
.st_size
;
65 *high
= (unsigned int)(s
.st_size
>> (sizeof (unsigned int) * 8));
70 /* filemtime - returns the mtime of a file, f. */
73 wrapc_filemtime (int f
)
77 if (fstat (f
, (struct stat
*)&s
) == 0)
83 /* fileinode - returns the inode associated with a file, f. */
85 #if defined(HAVE_SYS_STAT_H)
87 wrapc_fileinode (int f
, unsigned int *low
, unsigned int *high
)
91 if (fstat (f
, (struct stat
*)&s
) == 0)
93 *low
= (unsigned int)s
.st_ino
;
94 *high
= (unsigned int)(s
.st_ino
>> (sizeof (unsigned int) * 8));
102 wrapc_fileinode (int f
, unsigned int *low
, unsigned int *high
)
111 /* getrand - returns a random number between 0..n-1 */
114 wrapc_getrand (int n
)
119 #if defined(HAVE_PWD_H)
123 wrapc_getusername (void)
125 return getpwuid (getuid ())->pw_gecos
;
128 /* getnameuidgid - fills in the, uid, and, gid, which represents
132 wrapc_getnameuidgid (char *name
, int *uid
, int *gid
)
134 struct passwd
*p
= getpwnam (name
);
149 wrapc_getusername (void)
155 wrapc_getnameuidgid (char *name
, int *uid
, int *gid
)
163 wrapc_signbit (double r
)
165 #if defined(HAVE_SIGNBIT)
167 /* signbit is a macro which tests its argument against sizeof(float),
176 wrapc_signbitl (long double r
)
178 #if defined(HAVE_SIGNBITL)
180 /* signbit is a macro which tests its argument against sizeof(float),
189 wrapc_signbitf (float r
)
191 #if defined(HAVE_SIGNBITF)
193 /* signbit is a macro which tests its argument against sizeof(float),
201 /* isfinite - provide non builtin alternative to the gcc builtin
202 isfinite. Returns 1 if x is finite and 0 if it is not. */
205 wrapc_isfinite (double x
)
207 return (fpclassify (x
) != FP_NAN
&& fpclassify (x
) != FP_INFINITE
);
210 /* isfinitel - provide non builtin alternative to the gcc builtin
211 isfinite. Returns 1 if x is finite and 0 if it is not. */
214 wrapc_isfinitel (long double x
)
216 return (fpclassify (x
) != FP_NAN
&& fpclassify (x
) != FP_INFINITE
);
219 /* isfinitef - provide non builtin alternative to the gcc builtin
220 isfinite. Returns 1 if x is finite and 0 if it is not. */
223 wrapc_isfinitef (float x
)
225 return (fpclassify (x
) != FP_NAN
&& fpclassify (x
) != FP_INFINITE
);
228 /* isnan - provide non builtin alternative to the gcc builtin isnan.
229 Returns 1 if x is a NaN otherwise return 0. */
232 wrapc_isnan (double x
)
237 /* isnanf - provide non builtin alternative to the gcc builtin isnanf.
238 Returns 1 if x is a NaN otherwise return 0. */
241 wrapc_isnanf (float x
)
246 /* isnanl - provide non builtin alternative to the gcc builtin isnanl.
247 Returns 1 if x is a NaN otherwise return 0. */
250 wrapc_isnanl (long double x
)
255 /* init - init/finish functions for the module */
258 _M2_wrapc_init (int argc
, char *argv
[], char *envp
[])