00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #include <stdlib.h>
00038
00039 #include "hlrmisc.h"
00040 #include "log.h"
00041
00042 int hlr_allocCnt = 0 ;
00043
00044
00045 char *hlr_strmcpyI(char *to, char *from, int toLength) {
00046 to[toLength-1] = '\0' ;
00047 strncpy(to, from, toLength-1) ;
00048 return to ;
00049 }
00050
00051
00052
00053 char *hlr_strcpysFunc(char *to, char *from, int toLengthMax)
00054 {
00055
00056
00057 if (strlen(from) > toLengthMax)
00058 die("hlr_strcpys: overflow: toLengthMax=%d, strlen(from)=%d, from='%.50s...'",
00059 toLengthMax, strlen(from), from) ;
00060 strcpy(to, from) ;
00061 return to ;
00062 }
00063
00064
00065
00066 void *hlr_mallocs(size_t size)
00067 {
00068 void *p = malloc(size) ;
00069 if (!p)
00070 die("hlr_mallocs(%d)", size) ;
00071 return p ;
00072 }
00073
00074
00075
00076 void *hlr_callocs(size_t nelem, size_t elsize)
00077 {
00078 void *p = calloc(nelem, elsize) ;
00079 if (!p)
00080 die("hlr_callocs(%d,%d)", nelem, elsize) ;
00081 return p ;
00082 }
00083
00084
00085
00086 char *hlr_strdups(char *s1)
00087 {
00088 char *s2 = strdup(s1) ;
00089 if (!s2)
00090 die("hlr_strdups([%d bytes]) failed.", strlen(s1)+1) ;
00091 return s2 ;
00092 }
00093
00094
00095
00096 char *s0f(char *s)
00097 {
00098 return s0(s) ;
00099 }
00100
00101
00102
00110 int hlr_system(char *cmd, int nonZeroOK)
00111 {
00112 int rc = system(cmd) ;
00113 if (rc == -1 || (rc != 0 && !nonZeroOK))
00114 die("system(%s) exit status %d.", cmd, rc) ;
00115 return rc ;
00116 }
00117