]> git.pld-linux.org Git - packages/xemacs.git/blob - xemacs-mmencode.patch
- patch from rawhide.
[packages/xemacs.git] / xemacs-mmencode.patch
1 --- xemacs-21.1.9/lib-src/mmencode.c.chmou      Thu Mar 23 18:26:34 2000
2 +++ xemacs-21.1.9/lib-src/mmencode.c    Thu Mar 23 18:26:55 2000
3 @@ -20,6 +20,13 @@
4  #include <string.h>
5  #include <errno.h>
6  
7 +/* required for open */
8 +#include <sys/types.h>
9 +#include <sys/stat.h>
10 +#include <fcntl.h>
11 +
12 +extern int errno;
13 +
14  static void
15  output64chunk(int c1, int c2, int c3, int pads, FILE *outfile);
16  
17 @@ -429,6 +436,29 @@
18      }    
19  }
20  
21 +/* not safe on nfs filesystems, but this is close */
22 +FILE *
23 +safeopen(char *filename, char *mode)
24 +{
25 +    FILE *ret;
26 +    int fd;
27 +    int flags;
28 +
29 +    if(mode[0] == 'w') {
30 +        flags = O_EXCL | O_CREAT | O_WRONLY;
31 +    }
32 +    else {
33 +        flags = O_RDONLY;
34 +    }
35 +    
36 +    fd = open(filename, flags);
37 +    
38 +    if(fd == -1) {
39 +        return 0;
40 +    }
41 +    
42 +    return fdopen(fd, mode);
43 +}
44  
45  /*
46  Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
47 @@ -454,6 +484,7 @@
48  int main(int argc, char *argv[])
49  {
50      int encode = 1, which = BASE64, i, portablenewlines = 0;
51 +    struct stat theStat;
52      FILE *fp = stdin;
53      FILE *fpo = stdout;
54  
55 @@ -465,7 +496,12 @@
56                         fprintf(stderr, "mimencode: -o requires a file name.\n");
57                         exit(-1);
58                     }
59 -                   fpo = fopen(argv[i], "w");
60 +                   fpo = safeopen(argv[i], "w");
61 +            if(fpo == 0) {
62 +                printf("Can't open output file(%s): %s\n",
63 +                       argv[i], strerror(errno));
64 +                exit(1);
65 +            }
66                     if (!fpo) {
67                         perror(argv[i]);
68                         exit(-1);
69 @@ -490,15 +526,35 @@
70              }
71          } else {
72  #ifdef MSDOS
73 -            if (encode)
74 -                fp = fopen(argv[i], "rb");
75 +            if (encode) {
76 +                fp = safeopen(argv[i], "rb");
77 +                if(fp == 0) {
78 +                    exit(1);
79 +                }
80 +                
81 +            }
82              else
83              {
84 -                fp = fopen(argv[i], "rt");
85 +                fp = safeopen(argv[i], "rt");
86 +                if(fp == 0) exit(1);
87                  setmode(fileno(fpo), O_BINARY);
88              } /* else */
89  #else
90 -            fp = fopen(argv[i], "r");
91 +            fp = safeopen(argv[i], "r");
92 +            if(fp == 0) {
93 +                printf("Unable to open read file(%s): %s\n",
94 +                       argv[i], strerror(errno));
95 +                exit(1);
96 +            }
97 +            /* ok change the permissions on the output file to match
98 +               the permissions on the input file */
99 +            if(fstat(fileno(fp), &theStat) == -1) {
100 +                printf("Unable to stat read file: %s\n", strerror(errno));
101 +                exit(3);
102 +            }
103 +            fchmod(fileno(fpo),
104 +                   theStat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
105 +
106  #endif /* MSDOS */
107              if (!fp) {
108                  perror(argv[i]);
This page took 0.07133 seconds and 4 git commands to generate.