]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/mc-boot-ch/Gwrapc.c
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / mc-boot-ch / Gwrapc.c
CommitLineData
1eee94d3
GM
1/* Gwrapc.c wrap libc functions for mc.
2
a945c346 3Copyright (C) 2005-2024 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius@glam.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU Modula-2; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#include "config.h"
23#include "system.h"
24#include "ansidecl.h"
25
26#include "gm2-libs-host.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/* strtime returns the address of a string which describes the
33 local time. */
34
35char *
36wrapc_strtime (void)
37{
38#if defined(HAVE_CTIME)
39 time_t clock = time ((time_t *)0);
40 char *string = ctime (&clock);
41
42 string[24] = (char)0;
43
44 return string;
45#else
46 return "";
47#endif
48}
49
50int
51wrapc_filesize (int f, unsigned int *low, unsigned int *high)
52{
53 struct stat s;
54 int res = fstat (f, (struct stat *)&s);
55
56 if (res == 0)
57 {
58 *low = (unsigned int)s.st_size;
59 *high = (unsigned int)(s.st_size >> (sizeof (unsigned int) * 8));
60 }
61 return res;
62}
63
64/* filemtime returns the mtime of a file, f. */
65
66int
67wrapc_filemtime (int f)
68{
69 struct stat s;
70
71 if (fstat (f, (struct stat *)&s) == 0)
72 return s.st_mtime;
73 else
74 return -1;
75}
76
77/* getrand returns a random number between 0..n-1 */
78
79int
80wrapc_getrand (int n)
81{
82 return rand () % n;
83}
84
85#if defined(HAVE_PWD_H)
86#include <pwd.h>
87
88char *
89wrapc_getusername (void)
90{
91 return getpwuid (getuid ())->pw_gecos;
92}
93
94/* getnameuidgid fills in the, uid, and, gid, which represents
95 user, name. */
96
97void
98wrapc_getnameuidgid (char *name, int *uid, int *gid)
99{
100 struct passwd *p = getpwnam (name);
101
102 if (p == NULL)
103 {
104 *uid = -1;
105 *gid = -1;
106 }
107 else
108 {
109 *uid = p->pw_uid;
110 *gid = p->pw_gid;
111 }
112}
113#else
114char *
115wrapc_getusername (void)
116{
117 return "unknown";
118}
119
120void
121wrapc_getnameuidgid (char *name, int *uid, int *gid)
122{
123 *uid = -1;
124 *gid = -1;
125}
126#endif
127
128int
129wrapc_signbit (double r)
130{
131#if defined(HAVE_SIGNBIT)
132
133 /* signbit is a macro which tests its argument against sizeof(float),
134 sizeof(double). */
135 return signbit (r);
136#else
137 return 0;
138#endif
139}
140
141int
142wrapc_signbitl (long double r)
143{
144#if defined(HAVE_SIGNBITL)
145
146 /* signbit is a macro which tests its argument against sizeof(float),
147 sizeof(double). */
148 return signbitl (r);
149#else
150 return 0;
151#endif
152}
153
154int
155wrapc_signbitf (float r)
156{
157#if defined(HAVE_SIGNBITF)
158
159 /* signbit is a macro which tests its argument against sizeof(float),
160 sizeof(double). */
161 return signbitf (r);
162#else
163 return 0;
164#endif
165}
166
167/* init constructor for the module. */
168
169void
9fadd8de 170_M2_wrapc_init (int argc, char *argv[], char *envp[])
1eee94d3
GM
171{
172}
173
174/* finish deconstructor for the module. */
175
176void
9fadd8de 177_M2_wrapc_fini (int argc, char *argv[], char *envp[])
1eee94d3
GM
178{
179}
180
181#ifdef __cplusplus
182}
183#endif