TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
arch.cpp
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <arch.h>
17#include <unistd.h>
18#include <math.h>
19#ifdef __CYGWIN__
20#include <cstring>
21
22void srand48(int s)
23{
24 srand(s);
25 //cerr<< "srand48 not implemented with Visual "<<endl;
26 //Process::exit();
27}
28
29double drand48()
30{
31 return double(rand())/RAND_MAX;
32 // cerr<< "drand48 not implemented with Visual "<<endl;Process::exit();return 1.;
33}
34
35char* strdup(const char* str)
36{
37 size_t len = strlen(str);
38 char* x = (char*)malloc(len + 1); /* 1 for the null terminator */
39 if (!x)
40 return nullptr; /* malloc could not allocate memory */
41 memcpy(x, str, len + 1); /* copy the string into the new buffer */
42 return x;
43}
44#endif
45#ifdef MICROSOFT
46#include <direct.h>
47
48double atanh(const double& x)
49{
50 // must be x>-1, x<1, if not return Nan (Not a Number)
51 if(!(x>-1.0 && x<1.0)) return sqrt(-1.0);
52 return log((1.0+x)/(1.0-x))/2.0;
53 // cerr<< "atanh not implemented with Visual "<<endl;Process::exit(); return (x);
54}
55#endif
56#include <Process.h>
57#include <iostream>
58using std::cerr;
59using std::endl;
60
61static char* buf=0; //new char[801];
62// pwd :
63// alloue une chaine!
64void desalloue_pwd()
65{
66 // si on a alloue le buf on le detruit ...
67#if defined(_CSH_) || defined(linux) || defined(cygwin) || defined(MICROSOFT)
68 if (buf)
69 delete [] buf;
70 buf=0;
71#endif
72}
73char * pwd()
74{
75#if defined(_CSH_) || defined(linux) || defined(cygwin) || defined(MICROSOFT) || defined(__APPLE__)
76 if (buf==0)
77 buf=new char[801];
78#endif
79#ifdef MICROSOFT
80 int longueur=800;
81 _getcwd(buf, longueur);
82#else
83#if defined(_CSH_) || defined(linux) || defined(cygwin) || defined(__APPLE__)
84 int longueur=800;
85 if (getcwd(buf, longueur)==nullptr)
86 {
87 cerr << "getcwd returns an error code." << endl;
89 };
90#else
91 buf=getenv("PWD");
92#endif
93#endif
94 return buf;
95}
96
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455