Debian Codegraph @

gcc/m2/mc-boot-ch/Gwrapc.c

raw
1 /* Gwrapc.c wrap libc functions for mc.
2
3 Copyright (C) 2005-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
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)
11 any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along 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
29 extern "C" {
30 #endif
31
32 /* strtime returns the address of a string which describes the
33 local time. */
34
35 char *
36 wrapc_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
50 int
51 wrapc_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
66 int
67 wrapc_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
79 int
80 wrapc_getrand (int n)
81 {
82 return rand () % n;
83 }
84
85 #if defined(HAVE_PWD_H)
86 #include <pwd.h>
87
88 char *
89 wrapc_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
97 void
98 wrapc_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
114 char *
115 wrapc_getusername (void)
116 {
117 return "unknown";
118 }
119
120 void
121 wrapc_getnameuidgid (char *name, int *uid, int *gid)
122 {
123 *uid = -1;
124 *gid = -1;
125 }
126 #endif
127
128 int
129 wrapc_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
141 int
142 wrapc_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
154 int
155 wrapc_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 /* SeekSet return the system libc SEEK_SET value. */
168
169 int
170 wrapc_SeekSet (void)
171 {
172 return SEEK_SET;
173 }
174
175 /* SeekEnd return the system libc SEEK_END value. */
176
177 int
178 wrapc_SeekEnd (void)
179 {
180 return SEEK_END;
181 }
182
183 /* ReadOnly return the system value of O_RDONLY. */
184
185 int
186 wrapc_ReadOnly (void)
187 {
188 return O_RDONLY;
189 }
190
191 /* WriteOnly return the system value of O_WRONLY. */
192
193 int
194 wrapc_WriteOnly (void)
195 {
196 return O_WRONLY;
197 }
198
199 /* init constructor for the module. */
200
201 void
202 _M2_wrapc_init (int argc, char *argv[], char *envp[])
203 {
204 }
205
206 /* finish deconstructor for the module. */
207
208 void
209 _M2_wrapc_fini (int argc, char *argv[], char *envp[])
210 {
211 }
212
213 #ifdef __cplusplus
214 }
215 #endif