OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
sys_pipes_c.c
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23
24
25#include "hardware.inc"
26#include "pipes_c.inc"
27#include <stdio.h>
28
29#ifdef _WIN64
30
31#include <sys\types.h>
32#include <errno.h>
33#include <signal.h>
34#include <windows.h>
35#include <winbase.h>
36#include <process.h>
37#include <string.h>
38#include <ctype.h>
39#include <io.h>
40
41#define _FCALL
42
43#elif 1
44#include <stdlib.h>
45#include <unistd.h>
46#include <sys/types.h>
47#include <sys/param.h>
48#include <sys/stat.h>
49#include <sys/signal.h>
50#include <signal.h>
51#include <errno.h>
52#include <time.h>
53
54
55
56
57#define _FCALL
58
59#endif
60
61/***************************************************************************/
62
63void syserr(char *msg)
64{
65 fprintf(stderr,"SYSTEM ERROR>> ");
66 perror(msg);
67}
68
69void syserr_fatal(char *msg)
70{
71 fprintf(stderr,"SYSTEM ERROR>> ");
72 perror(msg);
73 exit(1);
74}
75
76void fatal(char *msg)
77{
78 fprintf(stderr,"%s\n", msg);
79 exit(1);
80}
81
82
83#ifdef _WIN64
84int readr(HANDLE pipe, char *buf, int nbytes)
85#else
86int readr(int pipe, char *buf, int nbytes)
87#endif
88{
89int error;
90
91#ifdef _WIN64
92BOOL fSuccess;
93unsigned long ncount,done;
94#else
95int ncount,done;
96#endif
97 ncount = nbytes;
98 while (ncount > 0)
99 {
100#ifdef _WIN64
101 fSuccess = ReadFile(pipe,buf,ncount*sizeof(TCHAR),&done,NULL);
102 if ( ! fSuccess)
103 {error = GetLastError(); done = -1;
104 if ((error == 109)||(error == 232)) printf("\nERROR Broken pipe\n\n");}
105#elif 1
106 done = read(pipe, buf, ncount);
107#endif
108 if (done < 0)
109 fatal("Failed reading fifo");
110 else if (done == 0)
111 break;
112 ncount -= done;
113 buf += done;
114 }
115 return 1;
116}
117
118/***************************************************************************/
119#ifdef _WIN64
120int writer(HANDLE pipe, char*buf, int nbytes)
121#else
122int writer(int pipe , char *buf, int nbytes)
123#endif
124{
125int error;
126#ifdef _WIN64
127BOOL fSuccess;
128unsigned long ncount,done;
129#else
130int ncount,done;
131#endif
132
133 ncount = nbytes;
134 while (ncount > 0)
135 {
136#ifdef _WIN64
137 fSuccess = WriteFile(pipe,buf,ncount*sizeof(TCHAR),&done,NULL);
138 if ( ! fSuccess)
139 {error = GetLastError(); done = -1;
140 if ((error == 109)||(error == 232)) printf("\nERROR Broken pipe\n\n");}
141#elif 1
142 done = write(pipe, buf, ncount);
143#endif
144 if (done < 0)
145 fatal("Failed writing fifo");
146 ncount -= done;
147 buf += done;
148 }
149 return 1;
150}
151
152
153
154
155
void syserr()
void fatal(char *msg)
Definition sys_pipes_c.c:76
int writer(int pipe, char *buf, int nbytes)
void syserr_fatal(char *msg)
Definition sys_pipes_c.c:69
int readr(int pipe, char *buf, int nbytes)
Definition sys_pipes_c.c:86