]> git.llucax.com Git - software/mutt-debian.git/blob - pgpewrap.c
#define PATH_MAX _POSIX_PATH_MAX. (Fixed in upstream hg, though differently.)
[software/mutt-debian.git] / pgpewrap.c
1 /*
2  * C version by Wessel Dankers <wsl@fruit.eu.org>
3  *
4  * This code is in the public domain.
5  *
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12
13 void print_usage(const char *progname) {
14         fprintf(stderr, "Command line usage: %s [flags] -- prefix [recipients]\n", progname);
15         exit(1);
16 }
17
18 int main(int argc, char **argv) {
19         char **opts, **opt, *pfx;
20         int i;
21
22         if (argc <= 1) {
23                 print_usage(argv[0]);
24         }
25
26         opts = malloc((2 * argc + 1) * sizeof (* opts));        /* __MEM_CHECKED__ */
27         if(!opts) {
28                 perror(argv[0]);
29                 exit(2);
30         }
31
32         if (argc < 2)
33         {
34           fprintf (stderr,
35                    "Command line usage: %s [flags] -- prefix [recipients]\n",
36                    argv[0]);
37           return 1;
38         }
39
40         opt = opts;
41         *opt++ = argv[1];
42         pfx = NULL;
43
44         for(i = 2; i < argc; ) {
45                 if(!strcmp(argv[i], "--")) {
46                         i += 2;
47                         if(i > argc) {
48                                 print_usage(argv[0]);
49                         }
50                         pfx = argv[i-1];
51                 }
52                 if(pfx)
53                         *opt++ = pfx;
54                 *opt++ = argv[i++];
55         }
56         *opt = NULL;
57
58         execvp(opts[0], opts);
59         perror(argv[0]);
60         return 2;
61 }