/[monit]/monit/util.c
ViewVC logotype

Diff of /monit/util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38 by martinp, Wed Oct 30 00:47:14 2002 UTC revision 1.39 by chopp, Sat Nov 2 10:47:22 2002 UTC
# Line 86  void error(const char *format, ...) { Line 86  void error(const char *format, ...) {
86        
87    char msg[1024];    char msg[1024];
88    va_list ap;    va_list ap;
89    
90      ASSERT(format);
91        
92    va_start(ap,format);    va_start(ap,format);
93    vsnprintf(msg, 1024, format, ap);    vsnprintf(msg, 1024, format, ap);
# Line 123  int is_strdefined(char *p) { Line 125  int is_strdefined(char *p) {
125   */   */
126  char *stripfilename(char* path) {  char *stripfilename(char* path) {
127        
128    char *fname= strrchr(path, '/');    char *fname;
129    
130      ASSERT(path);
131    
132      fname= strrchr(path, '/');
133        
134    return (fname ? ++fname : path);    return (fname ? ++fname : path);
135        
# Line 138  void chomp(char *string) { Line 144  void chomp(char *string) {
144        
145    char *p;    char *p;
146    
147      ASSERT(chomp);
148    
149    if ((p= strchr(string, '\r'))   ||    if ((p= strchr(string, '\r'))   ||
150         (p= strchr(string, '\n'))) {         (p= strchr(string, '\n'))) {
151            
# Line 154  void chomp(char *string) { Line 162  void chomp(char *string) {
162   * @return s with leading and trailing spaces removed   * @return s with leading and trailing spaces removed
163   */   */
164  char *trim(char *s) {  char *trim(char *s) {
165    
166      ASSERT(s);
167        
168    ltrim(s);    ltrim(s);
169    rtrim(s);    rtrim(s);
# Line 172  char *ltrim(char *s) { Line 182  char *ltrim(char *s) {
182    
183    char *t= s;    char *t= s;
184    
185      ASSERT(s);
186    
187    while (*t==' ' || *t=='\t' || *t=='\r' || *t=='\n') t++;    while (*t==' ' || *t=='\t' || *t=='\r' || *t=='\n') t++;
188    
189    return strcpy(s, t);    return strcpy(s, t);
# Line 188  char *rtrim(char *s) { Line 200  char *rtrim(char *s) {
200        
201    char *t= s;    char *t= s;
202    
203      ASSERT(s);
204    
205    while (*s) s++;    while (*s) s++;
206    while (*--s==' ' || *s=='\t' || *s=='\r' || *s=='\n') *s= '\0';    while (*--s==' ' || *s=='\t' || *s=='\r' || *s=='\n') *s= '\0';
207    
# Line 207  char *trim_quotes(char *s) { Line 221  char *trim_quotes(char *s) {
221    char *t= s;    char *t= s;
222    char tmp=0;    char tmp=0;
223    
224      ASSERT(s);
225    
226    while (*t==39 || *t==34 ) {    while (*t==39 || *t==34 ) {
227    
228      tmp=*t;      tmp=*t;
# Line 253  void handle_string_escapes(char *buf) { Line 269  void handle_string_escapes(char *buf) {
269    int editpos;    int editpos;
270    int insertpos;    int insertpos;
271    
272      ASSERT(buf);
273    
274    for(editpos=insertpos=0; *(buf+editpos)!='\0'; editpos++, insertpos++) {    for(editpos=insertpos=0; *(buf+editpos)!='\0'; editpos++, insertpos++) {
275    
276      if(*(buf+editpos) == '\\' ) {      if(*(buf+editpos) == '\\' ) {
# Line 309  Process_T get_process(char *name) { Line 327  Process_T get_process(char *name) {
327        
328    Process_T p;    Process_T p;
329    
330      ASSERT(name);
331    
332    for (p= processlist; p; p= p->next)    for (p= processlist; p; p= p->next)
333        if (is(p->name, name)) return p;        if (is(p->name, name)) return p;
334    
# Line 326  int exist_process(char *name) { Line 346  int exist_process(char *name) {
346        
347    Process_T p;    Process_T p;
348    
349      ASSERT(name);
350    
351    for (p= processlist; p; p= p->next)    for (p= processlist; p; p= p->next)
352        if (is(p->name, name)) return TRUE;        if (is(p->name, name)) return TRUE;
353    
# Line 595  pid_t get_pid(char *pidfile) { Line 617  pid_t get_pid(char *pidfile) {
617    FILE *file= NULL;    FILE *file= NULL;
618    int pid= -1;    int pid= -1;
619    
620      ASSERT(pidfile);
621    
622    if (! exist_file(pidfile)) {    if (! exist_file(pidfile)) {
623            
624      return(FALSE);      return(FALSE);
# Line 726  char *get_ctime() { Line 750  char *get_ctime() {
750   */   */
751  char *get_process_uptime(char *pidfile) {  char *get_process_uptime(char *pidfile) {
752    
753    time_t ctime= (pidfile?file_changedtime(pidfile):0);    time_t ctime;
754    
755      ASSERT(pidfile);
756    
757      ctime = (pidfile?file_changedtime(pidfile):0);
758    
759    if(ctime) {    if(ctime) {
760            
761      time_t now= time(&now);      time_t now= time(&now);
# Line 788  char *get_uptime(time_t delta) { Line 817  char *get_uptime(time_t delta) {
817   */   */
818  int set_md5sum(char **dest, char *file) {  int set_md5sum(char **dest, char *file) {
819    
820      ASSERT(dest);
821      ASSERT(*dest);
822      ASSERT(file);
823    
824    if (! (*dest= get_md5sum(file))) {    if (! (*dest= get_md5sum(file))) {
825                    
826      return FALSE;      return FALSE;
# Line 804  int set_md5sum(char **dest, char *file) Line 837  int set_md5sum(char **dest, char *file)
837   */   */
838  char *get_md5sum(char *file) {  char *get_md5sum(char *file) {
839    
840      ASSERT(file);
841    
842    if (isreg_file(file)) {    if (isreg_file(file)) {
843            
844      FILE *f= fopen(file, "r");      FILE *f= fopen(file, "r");
# Line 851  char *get_md5sum(char *file) { Line 886  char *get_md5sum(char *file) {
886   */   */
887  int check_md5(char *file, char *sum) {  int check_md5(char *file, char *sum) {
888    
889    char *newSum= get_md5sum(file);    char *newSum;
890    
891      ASSERT(file);
892      ASSERT(sum);
893    
894      newSum= get_md5sum(file);
895    
896    if (newSum) {    if (newSum) {
897            
898      int rv;      int rv;
# Line 880  char *url_encode(char *uri) { Line 921  char *url_encode(char *uri) {
921    register int x, y;    register int x, y;
922    unsigned char *str;    unsigned char *str;
923    
924      ASSERT(uri);
925    
926    str= (unsigned char *)xmalloc(3 * strlen(uri) + 1);    str= (unsigned char *)xmalloc(3 * strlen(uri) + 1);
927    
928    for (x = 0, y = 0; uri[x]; x++, y++) {    for (x = 0, y = 0; uri[x]; x++, y++) {
# Line 937  char *format(const char *s, va_list ap) Line 980  char *format(const char *s, va_list ap)
980    int n;    int n;
981    int size= STRLEN;    int size= STRLEN;
982    char *buf= xmalloc(size);    char *buf= xmalloc(size);
983    
984      ASSERT(s);
985            
986    while(TRUE) {    while(TRUE) {
987                
# Line 993  static int is_unsafe(unsigned char *c) { Line 1038  static int is_unsafe(unsigned char *c) {
1038    
1039    int i;    int i;
1040    static unsigned char unsafe[]= "<>\"#{}|\\^~[]`";    static unsigned char unsafe[]= "<>\"#{}|\\^~[]`";
1041    
1042      ASSERT(c);
1043        
1044    if(33>*c || *c>176)    if(33>*c || *c>176)
1045        return TRUE;        return TRUE;

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26