1 /************************************************************************
2 * Some routines common to procmail and formail *
3 * *
4 * Copyright (c) 1990-1999, S.R. van den Berg, The Netherlands *
5 * #include "../README" *
6 ************************************************************************/
7 #ifdef RCS
8 static /*const*/char rcsid[]=
9 "$Id: common.c,v 1.28 2001/06/23 08:18:39 guenther Exp $";
10 #endif
11 #include "procmail.h"
12 #include "sublib.h"
13 #include "robust.h"
14 #include "shell.h"
15 #include "misc.h"
16 #include "common.h"
17
shexec(argv)18 void shexec(argv)const char*const*argv;
19 { int i;char**newargv;const char**p;
20 #ifdef SIGXCPU
21 signal(SIGXCPU,SIG_DFL);signal(SIGXFSZ,SIG_DFL);
22 #endif
23 #ifdef SIGLOST
24 signal(SIGLOST,SIG_DFL);
25 #endif /* or is it a shell script ? */
26 signal(SIGPIPE,SIG_DFL);execvp(*argv,(char*const*)argv);
27 for(p=(const char**)argv,i=1;i++,*p++;); /* count the arguments */
28 newargv=malloc(i*sizeof*p); /* no shell script? -> trouble */
29 for(*(p=(const char**)newargv)=binsh;*++p= *argv++;);
30 execv(*newargv,newargv);free(newargv);nlog("Failed to execute");
31 logqnl(*argv);
32 exit(EX_UNAVAILABLE);
33 }
34
detab(p)35 void detab(p)char*p;
36 { while(p=strpbrk(p,"\t\n\v\f\r"))
37 *p=' '; /* take out all tabs and other specials */
38 }
39
skpspace(chp)40 char*skpspace(chp)const char*chp;
41 { for(;;chp++)
42 switch(*chp)
43 { case ' ':case '\t':
44 continue;
45 default:
46 return (char*)chp;
47 }
48 }
49
50 #ifdef NOstrcspn
strcspn(whole,sub)51 int strcspn(whole,sub)const char*const whole,*const sub;
52 { const register char*p;
53 p=whole;
54 while(*p&&!strchr(sub,*p))
55 p++;
56 return p-whole;
57 }
58 #endif
59
waitfor(pid)60 int waitfor(pid)const pid_t pid; /* wait for a specific process */
61 { int i;pid_t j;
62 while(pid!=(j=wait(&i))||WIFSTOPPED(i))
63 if(-1==j)
64 return NO_PROCESS;
65 else if(!pid)
66 break;
67 return lexitcode=WIFEXITED(i)?WEXITSTATUS(i):-WTERMSIG(i);
68 }
69
70 #ifdef NOstrncasecmp
strncasecmp(a,b,l)71 int strncasecmp(a,b,l)register const char*a,*b;register size_t l;
72 { unsigned i,j;
73 if(l) /* case insensitive strncmp */
74 do
75 { while(*a&&*a==*b&&--l)
76 a++,b++;
77 if(!l)
78 break;
79 if((i= *a++)-'A'<='Z'-'A')
80 i+='a'-'A';
81 if((j= *b++)-'A'<='Z'-'A')
82 j+='a'-'A';
83 if(j!=i)
84 return i>j?1:-1;
85 }
86 while(i&&j&&--l);
87 return 0;
88 }
89 #endif
90