1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/*----------------------------------------------------------------------------
-- --
-- FLORIST (FSU Implementation of POISX.5) COMPONENTS --
-- --
-- --
-- P O S I X - M A C R O S . C --
-- --
-- Copyright (c) 1996 Florida State University (FSU), All Rights Reserved. --
-- Copyright (C) 1997-2010, AdaCore --
-- --
-- This file is a component of FLORIST, an implementation of an Ada API --
-- for the POSIX OS services, for use with the GNAT Ada compiler and --
-- the FSU Gnu Ada Runtime Library (GNARL). The interface is intended --
-- to be close to that specified in IEEE STD 1003.5: 1990 and IEEE STD --
-- 1003.5b: 1996. --
-- --
-- FLORIST is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. FLORIST 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 --
-- General Public License for more details. You should have received a --
-- copy of the GNU General Public License distributed with GNARL; see --
-- file COPYING. If not, write to the Free Software Foundation, 59 --
-- Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
----------------------------------------------------------------------------*/
/* file: posix-macros.c
--------------------
These subprograms provide access to POSIX functionality that is
provided for C programs via macros.
*/
#define _REENTRANT
#include "pconfig.h"
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <errno.h>
/* This definition is need for multi-threaded error codes on Solaris */
int s_isdir(mode_t mode) {
#ifdef S_ISDIR
return S_ISDIR(mode);
#else
return -1;
#endif
}
int s_ischr(mode_t mode) {
#ifdef S_ISCHR
return S_ISCHR(mode);
#else
return -1;
#endif
}
int s_isblk(mode_t mode) {
#ifdef S_ISBLK
return S_ISBLK(mode);
#else
return -1;
#endif
}
int s_isreg(mode_t mode) {
#ifdef S_ISREG
return S_ISREG(mode);
#else
return -1;
#endif
}
int s_islnk(mode_t mode) {
#ifdef S_ISLNK
return S_ISLNK(mode);
#else
return -1;
#endif
}
int s_issock(mode_t mode) {
#ifdef S_ISSOCK
return S_ISSOCK(mode);
#else
return -1;
#endif
}
int s_isfifo(mode_t mode) {
#ifdef S_ISFIFO
return S_ISFIFO(mode);
#else
return -1;
#endif
}
int s_ismsg(mode_t mode) {
#ifdef S_ISMSG
return S_ISMSG(mode);
#else
return -1;
#endif
}
int s_typeismq(struct stat *p) {
#ifdef S_TYPEISMQ
return S_TYPEISMQ(p);
#else
return 0;
#endif
}
int s_issem(mode_t mode) {
#ifdef S_ISSEM
return S_ISSEM(mode);
#else
return -1;
#endif
}
int s_typeissem(struct stat *p) {
#ifdef S_TYPEISSEM
return S_TYPEISSEM(p);
#else
return 0;
#endif
}
int s_isshm(mode_t mode) {
#ifdef S_ISSHM
return S_ISSHM(mode);
#else
return -1;
#endif
}
int s_typeisshm(struct stat *p) {
#ifdef S_TYPEISSHM
return S_TYPEISSHM(p);
#else
return 0;
#endif
}
int wifexited(int stat_val) {
#ifdef WIFEXITED
return WIFEXITED(stat_val);
#else
return -1;
#endif
}
int wexitstatus(int stat_val) {
#ifdef WEXITSTATUS
return WEXITSTATUS(stat_val);
#else
return -1;
#endif
}
int wifsignaled(int stat_val) {
#ifdef WIFSIGNALED
return WIFSIGNALED(stat_val);
#else
return -1;
#endif
}
int wtermsig(int stat_val) {
#ifdef WTERMSIG
return WTERMSIG(stat_val);
#else
return -1;
#endif
}
int wifstopped(int stat_val) {
#ifdef WIFSTOPPED
return WIFSTOPPED(stat_val);
#else
return -1;
#endif
}
int wstopsig(int stat_val) {
#ifdef WSTOPSIG
return WSTOPSIG(stat_val);
#else
return -1;
#endif
}
int fetch_errno() {
return errno;
}
void store_errno(int value) {
errno = value;
}
/* The following are variadic functions and on some platforms, for
instance x86-64, calling a variadic function directly from Ada can
cause problems. Here we provide wrappers that we import instead. */
int __gnat_florist_open(const char *path, int oflag, mode_t mode) {
return open (path, oflag, mode);
}
sem_t *__gnat_florist_sem_open
(char *name, int oflag, mode_t mode, unsigned value) {
return sem_open (name, oflag, mode, value);
}
/* The following wrappers work around problems on systems where the
stat family of functions are implemented using macros. (eg. Tru64
5.1A and Linux.) */
int __gnat_florist_stat(const char *path, struct stat *buf) {
return stat(path, buf);
}
int __gnat_florist_lstat(const char *path, struct stat *buf) {
return lstat(path, buf);
}
int __gnat_florist_fstat(int fd, struct stat *buf) {
return fstat(fd, buf);
}
/* The following wrapper ensures that uname(3) is mapped correctly even
when it is defined as an inlined function. */
int __gnat_florist_uname (struct utsname *s) {
return uname (s);
}
|