Mobile API Reference  MicroStrategy 2019
PDCstring.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : PDCstring.h
3 // AUTHOR : Perl Script
4 // CREATION : 6/13/02
5 // Copyright (C) MicroStrategy, Inc. 2002
6 //==============================================================================================
7 #ifndef PDCstring_h
8 #define PDCstring_h
9 
10 // this must be the *first* file included
11 #include "ProtectedSource/Prolog.h"
12 
13 #include <string.h>
14 #include "PDCerrno.h"
15 
16 #if !defined(WIN32) && defined(WIN64)
17 
40 inline errno_t memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
41 {
42  _VALIDATE_RETURN_ERRCODE(dest!=NULL,EINVAL);
43  _VALIDATE_RETURN_ERRCODE(src!=NULL,EINVAL);
44  _VALIDATE_RETURN_ERRCODE(count>=0 && sizeInBytes>=count,EINVAL);
45  ::memcpy(dest,src,count);
46  return 0;
47 }
48 
66 inline errno_t memmove_s(void *dest, size_t sizeInBytes, const void* src, size_t count)
67 {
68  _VALIDATE_RETURN_ERRCODE(dest!=NULL,EINVAL);
69  _VALIDATE_RETURN_ERRCODE(src!=NULL,EINVAL);
70  _VALIDATE_RETURN_ERRCODE(count>=0 && sizeInBytes>=count,EINVAL);
71  ::memmove(dest,src,count);
72  return 0;
73 }
74 
95 inline errno_t strcat_s(char *strDestination, size_t sizeInBytes, const char *strSource)
96 {
97  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
98  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
99  _VALIDATE_RETURN_ERRCODE(sizeInBytes>strlen(strSource)+strlen(strDestination),EINVAL);
100  ::strcat(strDestination,strSource);
101  return 0;
102 }
103 
121 inline errno_t strcpy_s(char *strDestination, size_t sizeInBytes, const char *strSource)
122 {
123  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
124  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
125  _VALIDATE_RETURN_ERRCODE(sizeInBytes>strlen(strSource),EINVAL);
126  ::strcpy(strDestination,strSource);
127  return 0;
128 }
129 
150 inline errno_t strncat_s(char *strDestination, size_t sizeInBytes, const char *strSource, size_t count)
151 {
152  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
153  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
154  _VALIDATE_RETURN_ERRCODE(sizeInBytes>strlen(strSource)+(count>strlen(strSource)?strlen(strSource):count),EINVAL);
155  ::strncat(strDestination,strSource,count);
156  return 0;
157 }
158 
178 inline errno_t strncpy_s(char *strDestination, size_t sizeInBytes, const char *strSource, size_t count)
179 {
180  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
181  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
182  size_t len=(count>strlen(strSource)?strlen(strSource):count);
183  _VALIDATE_RETURN_ERRCODE(sizeInBytes>len,EINVAL);
184  ::strncpy(strDestination,strSource,len);
185  strDestination[len]=NULL;
186  return 0;
187 }
188 
189 #endif
190 
191 // 2005-04-19 vovechkin
192 // HP-UX does not have the ::strsignal() function.
193 #if defined(__hpux)
194 #include <signal.h>
195 
196 inline const char* strsignal(int n)
197 {
198  switch (n)
199  {
200  // according to POSIX, all systems must define these signals:
201  case SIGABRT: return "Process abort.";
202  case SIGALRM: return "Alarm clock.";
203  case SIGBUS: return "Bus error.";
204  case SIGCHLD: return "Child status changed.";
205  case SIGCONT: return "Continued.";
206  case SIGFPE: return "Erroneous arithmetic operation.";
207  case SIGHUP: return "Hangup.";
208  case SIGILL: return "Illegal instruction.";
209  case SIGINT: return "Interrupt.";
210  case SIGKILL: return "Kill.";
211  case SIGPIPE: return "Broken pipe.";
212  case SIGQUIT: return "Quit.";
213  case SIGSEGV: return "Segmentation fault.";
214  case SIGSTOP: return "Stopped.";
215  case SIGTERM: return "Terminated.";
216  case SIGTSTP: return "Stopped from terminal.";
217  case SIGTTIN: return "Background process attempting to read from terminal.";
218  case SIGTTOU: return "Background process attempting to write to terminal.";
219  case SIGUSR1: return "User-defined signal 1.";
220  case SIGUSR2: return "User-defined signal 2.";
221  case SIGPOLL: return "Pollable event.";
222 // case SIGPROF: return "Profiling timer expired.";
223  case SIGSYS: return "Bad system call.";
224  case SIGTRAP: return "Trace or breakpoint trap.";
225  case SIGURG: return "High bandwidth data is available at a socket.";
226  case SIGVTALRM: return "Virtual timer expired.";
227  case SIGXCPU: return "CPU time limit exceeded.";
228  case SIGXFSZ: return "File size limit exceeded.";
229 
230  // these are optional
231  #ifdef SIGEMT
232  case SIGEMT: return "Emulation trap.";
233  #endif
234 
235  #ifdef SIGPWR
236  case SIGPWR: return "Power fail or restart.";
237  #endif
238 
239  #ifdef SIGWINCH
240  case SIGWINCH:return "Window size change.";
241  #endif
242 
243  #ifdef SIGPROF
244  case SIGPROF: return "Profiling timer expired.";
245  #endif
246 
247  #ifdef SIGFREEZE
248  case SIGFREEZE: return "Checkpoint freeze.";
249  #endif
250 
251  #ifdef SIGTHAW
252  case SIGTHAW: return "Checkpoint thaw.";
253  #endif
254 
255  #ifdef SIGLOST
256  case SIGLOST: return "Resource lost.";
257  #endif
258 
259  #ifdef SIGXRES
260  case SIGXRES: return "Resource control exceeded.";
261  #endif
262  }
263 
264  return NULL;
265 }
266 #endif // __hpux
267 
268 // this must be the *last* file included
269 #include "ProtectedSource/Epilog.h"
270 
271 #endif // PDCstring_h
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
Definition: PDCerrno.h:21
UINT len
Definition: Msi_bstr.h:37
#define NULL
Definition: Null.h:10