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
7 +/* required for open */
8 +#include <sys/types.h>
15 output64chunk(int c1, int c2, int c3, int pads, FILE *outfile);
21 +/* not safe on nfs filesystems, but this is close */
23 +safeopen(char *filename, char *mode)
29 + if(mode[0] == 'w') {
30 + flags = O_EXCL | O_CREAT | O_WRONLY;
36 + fd = open(filename, flags);
42 + return fdopen(fd, mode);
46 Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
48 int main(int argc, char *argv[])
50 int encode = 1, which = BASE64, i, portablenewlines = 0;
51 + struct stat theStat;
56 fprintf(stderr, "mimencode: -o requires a file name.\n");
59 - fpo = fopen(argv[i], "w");
60 + fpo = safeopen(argv[i], "w");
62 + printf("Can't open output file(%s): %s\n",
63 + argv[i], strerror(errno));
74 - fp = fopen(argv[i], "rb");
76 + fp = safeopen(argv[i], "rb");
84 - fp = fopen(argv[i], "rt");
85 + fp = safeopen(argv[i], "rt");
86 + if(fp == 0) exit(1);
87 setmode(fileno(fpo), O_BINARY);
90 - fp = fopen(argv[i], "r");
91 + fp = safeopen(argv[i], "r");
93 + printf("Unable to open read file(%s): %s\n",
94 + argv[i], strerror(errno));
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));
103 + fchmod(fileno(fpo),
104 + theStat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));