EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eve-compat.cpp File Reference
#include "eve-core.h"
#include <time.h>
Include dependency graph for eve-compat.cpp:

Go to the source code of this file.

Functions

void Sleep (uint32 x)
 
uint32 GetTickCount ()
 
int CreateDirectory (const char *name, void *)
 
int asprintf (char **strp, const char *fmt,...)
 
int vasprintf (char **strp, const char *fmt, va_list ap)
 
std::string sprintf (const char *fmt,...)
 sprintf for std::string. More...
 
std::string vsprintf (const char *fmt, va_list ap)
 vsprintf for std::string. More...
 
int sprintf (std::string &str, const char *fmt,...)
 sprintf for std::string. More...
 
int vsprintf (std::string &str, const char *fmt, va_list ap)
 vsprintf for std::string. More...
 
float strtof (const char *nptr, char **endptr)
 
tm * localtime_r (const time_t *timep, tm *result)
 

Function Documentation

int asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Definition at line 57 of file eve-compat.cpp.

References vasprintf().

58 {
59  va_list ap;
60 
61  va_start( ap, fmt );
62  int res = ::vasprintf( strp, fmt, ap );
63  va_end( ap );
64 
65  return res;
66 }
int vasprintf(char **strp, const char *fmt, va_list ap)
Definition: eve-compat.cpp:70

Here is the call graph for this function:

int CreateDirectory ( const char *  name,
void *   
)

Definition at line 46 of file eve-compat.cpp.

Referenced by ImageServer::ImageServer(), PyCallable_Make_InnerDispatcher(), and StuffExtract().

47 {
48  // Create the directory with mode 0755
49  return 0 == ::mkdir( name,
50  S_IRUSR | S_IWUSR | S_IXUSR
51  | S_IRGRP | S_IXGRP
52  | S_IROTH | S_IXOTH );
53 }

Here is the caller graph for this function:

uint32 GetTickCount ( )

Definition at line 39 of file eve-compat.cpp.

Referenced by main(), TCPConnection::TCPConnectionLoop(), and BaseTCPServer::TCPServerLoop().

40 {
41  struct timespec ts;
42  ::clock_gettime(CLOCK_MONOTONIC, &ts);
43  return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
44 }

Here is the caller graph for this function:

tm* localtime_r ( const time_t *  timep,
tm *  result 
)

Definition at line 184 of file eve-compat.cpp.

Referenced by log_messageVA(), NewLog::PrintTime(), and NewLog::SetLogfileDefault().

185 {
186 # ifdef HAVE_LOCALTIME_S
187  const errno_t err = ::localtime_s( result, timep );
188  if( 0 != err )
189  {
190  errno = err;
191  return NULL;
192  }
193 # else /* !HAVE_LOCALTIME_S */
194  /* This is quite dangerous stuff (not necessarily
195  thread-safe), but what can we do? Also,
196  there is a chance that localtime will use
197  thread-specific memory (MS's localtime does that). */
198  ::memcpy( result, ::localtime( timep ), sizeof( tm ) );
199 # endif /* !HAVE_LOCALTIME_S */
200 
201  return result;
202 }

Here is the caller graph for this function:

void Sleep ( uint32  x)

Definition at line 32 of file eve-compat.cpp.

Referenced by main(), MRMutex::ReadLock(), Threading::RunLoop(), TCPConnection::TCPConnectionLoop(), BaseTCPServer::TCPServerLoop(), and MRMutex::WriteLock().

33 {
34  if( 0 < x )
35  ::usleep( 1000 * x );
36 }

Here is the caller graph for this function:

std::string sprintf ( const char *  fmt,
  ... 
)

sprintf for std::string.

Parameters
[in]fmtThe format string.
[in]...Arguments.
Returns
The printed string.

Definition at line 106 of file eve-compat.cpp.

References vsprintf().

Referenced by adres(), GetMTimeTillNow(), GetUTimeTillNow(), MakeIntString(), and MakeIntStringNoZero().

107 {
108  va_list ap;
109  va_start( ap, fmt );
110 
111  // The string buffer
112  std::string str;
113  // Print into the buffer
114  int code = ::vsprintf( str, fmt, ap );
115  assert( 0 <= code );
116 
117  va_end( ap );
118 
119  return str;
120 }
std::string vsprintf(const char *fmt, va_list ap)
vsprintf for std::string.
Definition: eve-compat.cpp:122

Here is the call graph for this function:

Here is the caller graph for this function:

int sprintf ( std::string &  str,
const char *  fmt,
  ... 
)

sprintf for std::string.

Parameters
[out]strWhere to store the result.
[in]fmtThe format string.
[in]...Arguments.
Returns
A value returned by vsprintf.

Definition at line 133 of file eve-compat.cpp.

References vsprintf().

134 {
135  va_list ap;
136 
137  va_start( ap, fmt );
138  int code = ::vsprintf( str, fmt, ap );
139  va_end( ap );
140 
141  return code;
142 }
std::string vsprintf(const char *fmt, va_list ap)
vsprintf for std::string.
Definition: eve-compat.cpp:122

Here is the call graph for this function:

float strtof ( const char *  nptr,
char **  endptr 
)

Definition at line 176 of file eve-compat.cpp.

Referenced by DBResultRow::GetFloat().

177 {
178  // Implement using strtod
179  return (float)::strtod( nptr, endptr );
180 }

Here is the caller graph for this function:

int vasprintf ( char **  strp,
const char *  fmt,
va_list  ap 
)

Definition at line 70 of file eve-compat.cpp.

References vsnprintf.

Referenced by PyPfxVisitor::_pfxExtend(), asprintf(), CustomError::CustomError(), DBcore::RunQuery(), DBcore::RunQueryLID(), Client::SelfChatMessage(), Client::SelfEveMail(), Client::SendErrorMsg(), Client::SendInfoModalMsg(), and Client::SendNotifyMsg().

71 {
72  // Return code
73  int code;
74  // Size of the buffer (doubled each cycle)
75  size_t size = 0x40;
76 
77  // No buffer yet
78  *strp = NULL;
79 
80  do
81  {
82  // Reallocate the buffer
83  *strp = (char*)::realloc( *strp, size );
84 
85  // Try to print into the buffer
86  code = ::vsnprintf( *strp, size, fmt, ap );
87  // Check for truncation
88  if( size <= code )
89  // Output truncated
90  code = -1;
91 
92  // Double the size of buffer
93  size <<= 1;
94  } while( 0 > code );
95 
96  // Reallocate to save memory
97  *strp = (char*)::realloc( *strp, code + 1 );
98  // Terminate the string
99  (*strp)[code] = '\0';
100 
101  // Return the code
102  return code;
103 }
#define vsnprintf
Definition: eve-compat.h:188

Here is the caller graph for this function:

std::string vsprintf ( const char *  fmt,
va_list  ap 
)

vsprintf for std::string.

Parameters
[in]fmtThe format string.
[in]apArguments.
Returns
The printed string.

Definition at line 122 of file eve-compat.cpp.

References vsprintf().

Referenced by sprintf(), and vsprintf().

123 {
124  // The string buffer
125  std::string str;
126  // Print into the buffer
127  int code = ::vsprintf( str, fmt, ap );
128  assert( 0 <= code );
129 
130  return str;
131 }
std::string vsprintf(const char *fmt, va_list ap)
vsprintf for std::string.
Definition: eve-compat.cpp:122

Here is the call graph for this function:

Here is the caller graph for this function:

int vsprintf ( std::string &  str,
const char *  fmt,
va_list  ap 
)

vsprintf for std::string.

Parameters
[out]strWhere to store the result.
[in]fmtThe format string.
[in]apArguments.
Returns
A value returned by vsnprintf.

Definition at line 144 of file eve-compat.cpp.

References vsnprintf.

145 {
146  // Return code
147  int code;
148  // Offset within the string
149  size_t offset = str.length();
150  // Size of the buffer
151  size_t size = 0x40;
152 
153  do
154  {
155  // Resize the buffer
156  str.resize( offset + size );
157 
158  // Try to print into the buffer
159  code = ::vsnprintf( &str[offset], size, fmt, ap );
160  // Check for truncation
161  if( size <= code )
162  // Output truncated
163  code = -1;
164 
165  // Double the size of the buffer
166  size <<= 1;
167  } while( 0 > code );
168 
169  // Resize to save memory
170  str.resize( offset + code );
171  // Return the code
172  return code;
173 }
#define vsnprintf
Definition: eve-compat.h:188