]> git.pld-linux.org Git - packages/xfig.git/blame - xfig-mkstemp.diff
- updated to 3.2.4
[packages/xfig.git] / xfig-mkstemp.diff
CommitLineData
ce6c6d46 1diff -ur xfig.3.2.3d.orig/f_readeps.c xfig.3.2.3d/f_readeps.c
2--- xfig.3.2.3d.orig/f_readeps.c Wed Apr 18 01:12:24 2001
3+++ xfig.3.2.3d/f_readeps.c Fri Mar 22 10:10:16 2002
4@@ -251,7 +251,7 @@
5 char buf[300];
6 FILE *tmpfp, *pixfile, *gsfile;
7 char *psnam, *driver;
8- int status, wid, ht, nbitmap;
9+ int status, wid, ht, nbitmap, fd;
10 char tmpfile[PATH_MAX],
11 pixnam[PATH_MAX],
12 errnam[PATH_MAX],
13@@ -273,8 +273,12 @@
14 /* re-open the pipe */
15 close_picfile(file, filetype);
a45c09fa 16 file = open_picfile(file, &filetype, PIPEOK, pixnam);
ce6c6d46 17- sprintf(tmpfile, "%s/%s%06d", TMPDIR, "xfig-eps", getpid());
18- if ((tmpfp = fopen(tmpfile, "wb")) == NULL) {
19+ snprintf(tmpfile, sizeof(tmpfile), "%s/xfig-eps.XXXXXX", TMPDIR);
20+ if ((fd = mkstemp(tmpfile)) == -1 || (tmpfp = fdopen(fd, "wb")) == NULL) {
21+ if (fd != -1) {
22+ unlink(tmpfile);
23+ close(fd);
24+ }
25 file_msg("Couldn't open tmp file %s, %s", tmpfile, strerror(errno));
26 return False;
27 }
28@@ -283,9 +287,21 @@
29 fclose(tmpfp);
30 }
31 /* make name /TMPDIR/xfig-pic.pix */
32- sprintf(pixnam, "%s/%s%06d.pix", TMPDIR, "xfig-pic", getpid());
33+ snprintf(pixnam, sizeof(pixnam), "%s/xfig-pic.XXXXXX", TMPDIR);
34+ if ((fd = mkstemp(pixnam)) == -1) {
35+ file_msg("Couldn't open tmp file %s, %s", pixnam, strerror(errno));
36+ return False;
37+ }
38+ close(fd);
39+
40 /* and file name for any error messages from gs */
41- sprintf(errnam, "%s/%s%06d.err", TMPDIR, "xfig-pic", getpid());
42+ snprintf(errnam, sizeof(errnam), "%s/xfig-picerr.XXXXXX", TMPDIR);
43+ if ((fd = mkstemp(errnam)) == -1) {
44+ file_msg("Couldn't open tmp file %s, %s", errnam, strerror(errno));
45+ return False;
46+ }
47+ close(fd);
48+
49 /* generate gs command line */
50 /* for monochrome, use pbm */
51 if (tool_cells <= 2 || appres.monochrome) {
52diff -ur xfig.3.2.3d.orig/f_readgif.c xfig.3.2.3d/f_readgif.c
53--- xfig.3.2.3d.orig/f_readgif.c Tue Feb 27 23:37:53 2001
54+++ xfig.3.2.3d/f_readgif.c Fri Mar 22 09:42:59 2002
55@@ -75,7 +75,7 @@
56 char buf[BUFLEN],pcxname[PATH_MAX];
57 FILE *giftopcx;
58 struct Cmap localColorMap[MAX_COLORMAP_SIZE];
59- int i, stat, size;
60+ int i, stat, size, fd;
61 int useGlobalColormap;
62 unsigned int bitPixel, red, green, blue;
63 unsigned char c;
64@@ -172,7 +172,13 @@
65 /* now call giftopnm and ppmtopcx */
66
67 /* make name for temp output file */
68- sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid());
69+ snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR);
70+ if ((fd = mkstemp(pcxname)) == -1) {
71+ file_msg("Cannot create temporary file\n");
72+ return FileInvalid;
73+ }
74+ close(fd);
75+
76 /* make command to convert gif to pcx into temp file */
77 sprintf(buf, "giftopnm | ppmtopcx > %s 2> /dev/null", pcxname);
78 if ((giftopcx = popen(buf,"w" )) == 0) {
79diff -ur xfig.3.2.3d.orig/f_readppm.c xfig.3.2.3d/f_readppm.c
80--- xfig.3.2.3d.orig/f_readppm.c Tue Feb 27 23:37:39 2001
81+++ xfig.3.2.3d/f_readppm.c Fri Mar 22 15:38:02 2002
82@@ -32,10 +32,16 @@
83 {
84 char buf[BUFLEN],pcxname[PATH_MAX];
85 FILE *giftopcx;
86- int stat, size;
87+ int stat, size, fd;
88
89 /* make name for temp output file */
90- sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid());
91+ snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR);
92+ if ((fd = mkstemp(pcxname)) == -1) {
93+ file_msg("Cannot open temp file %s: %s\n", pcxname, strerror(errno));
94+ return FileInvalid;
95+ }
96+ close(fd);
97+
98 /* make command to convert gif to pcx into temp file */
99 sprintf(buf, "ppmtopcx > %s 2> /dev/null", pcxname);
100 if ((giftopcx = popen(buf,"w" )) == 0) {
101diff -ur xfig.3.2.3d.orig/f_readtif.c xfig.3.2.3d/f_readtif.c
102--- xfig.3.2.3d.orig/f_readtif.c Tue Feb 27 23:37:11 2001
103+++ xfig.3.2.3d/f_readtif.c Fri Mar 22 15:38:24 2002
104@@ -32,11 +32,16 @@
105 {
106 char buf[2*PATH_MAX+40],pcxname[PATH_MAX];
107 FILE *tiftopcx;
108- int stat;
109+ int stat, fd;
110
111 /* make name for temp output file */
112- sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid());
113-
114+ snprintf(pcxname, sizeof(pcxname), "%s/xfig-pcx.XXXXXX", TMPDIR);
115+ if ((fd = mkstemp(pcxname)) == -1) {
116+ file_msg("Cannot open temp file %s: %s\n", pcxname, strerror(errno));
117+ return FileInvalid;
118+ }
119+ close(fd);
120+
121 /* make command to convert tif to pnm then to pcx into temp file */
122 /* for some reason, tifftopnm requires a file and can't work in a pipe */
123 sprintf(buf, "tifftopnm %s 2> /dev/null | ppmtopcx > %s 2> /dev/null",
124diff -ur xfig.3.2.3d.orig/f_util.c xfig.3.2.3d/f_util.c
125--- xfig.3.2.3d.orig/f_util.c Fri Mar 30 20:22:37 2001
126+++ xfig.3.2.3d/f_util.c Fri Mar 22 11:28:52 2002
127@@ -1056,14 +1056,20 @@
128 char *name;
129 {
a45c09fa 130 char line[RC_BUFSIZ+1], *tok;
ce6c6d46 131+ int fd;
132
133 /* make a temp filename in the user's home directory so we
134 can just rename it to .xfigrc after creating it */
135- sprintf(tmpname, "%s/%s%06d", userhome, "xfig-xfigrc", getpid());
136- tmpf = fopen(tmpname,"wb");
137- if (tmpf == 0) {
138- file_msg("Can't make temporary file for .xfigrc - error: %s",strerror(errno));
139- return -1;
140+ snprintf(tmpname, sizeof(tmpname), "%s/xfig-xfigrc.XXXXXX", userhome);
141+
142+ if ((fd = mkstemp(tmpname)) == -1 || (tmpf = fdopen(fd, "wb")) == NULL) {
143+ file_msg("Can't make temporary file for .xfigrc - error: %s",
144+ strerror(errno));
145+ if (fd != -1) {
146+ unlink(tmpname);
147+ close(fd);
148+ }
149+ return -1;
150 }
151 /* read the .xfigrc file and write all to temp file except file names */
152 xfigrc = fopen(xfigrc_name,"r");
153diff -ur xfig.3.2.3d.orig/main.c xfig.3.2.3d/main.c
154--- xfig.3.2.3d.orig/main.c Thu Jan 25 23:49:19 2001
155+++ xfig.3.2.3d/main.c Fri Mar 22 15:35:34 2002
156@@ -663,8 +663,10 @@
157 get_directory(orig_dir);
158
159 /* get the TMPDIR environment variable for temporary files */
160- if ((TMPDIR = getenv("XFIGTMPDIR"))==NULL)
161- TMPDIR = "/tmp";
162+ if ((TMPDIR = getenv("XFIGTMPDIR"))==NULL) {
163+ if ((TMPDIR = getenv("TMPDIR")) == NULL)
164+ TMPDIR = "/tmp";
165+ }
166
167 /* install actions to get to the functions with accelerators */
168 XtAppAddActions(tool_app, main_actions, XtNumber(main_actions));
169@@ -696,7 +698,14 @@
170 if (userhome != NULL && *strcpy(cut_buf_name, userhome) != '\0') {
171 strcat(cut_buf_name, "/.xfig");
172 } else {
173- sprintf(cut_buf_name, "%s/xfig%06d", TMPDIR, getpid());
174+ int fd;
175+ sprintf(cut_buf_name, "%s/xfig.XXXXXX", TMPDIR);
176+ if ((fd = mkstemp(cut_buf_name)) == -1) {
177+ fprintf(stderr, "Can't create temporary file for cut_buff: %s\n",
178+ strerror(errno));
179+ exit(0);
180+ }
181+ close(fd);
182 }
183
184 /*******************************************************************************/
185diff -ur xfig.3.2.3d.orig/mode.c xfig.3.2.3d/mode.c
186--- xfig.3.2.3d.orig/mode.c Wed Mar 21 19:40:32 2001
187+++ xfig.3.2.3d/mode.c Fri Mar 22 09:38:45 2002
188@@ -70,7 +70,7 @@
189
190 int cur_exp_lang; /* gets initialized in main.c */
191 Boolean batch_exists = False;
192-char batch_file[32];
193+char batch_file[PATH_MAX];
194
195 char *lang_items[] = {
196 "box", "latex", "epic", "eepic", "eepicemu", "pictex",
197diff -ur xfig.3.2.3d.orig/u_print.c xfig.3.2.3d/u_print.c
198--- xfig.3.2.3d.orig/u_print.c Mon Dec 11 20:52:38 2000
199+++ xfig.3.2.3d/u_print.c Fri Mar 22 12:53:38 2002
200@@ -71,9 +71,16 @@
201 char syspr[2*PATH_MAX+200];
202 char tmpfile[PATH_MAX];
a45c09fa 203 char *name;
ce6c6d46 204+ int fd;
205
206- sprintf(tmpfile, "%s/%s%06d", TMPDIR, "xfig-print", getpid());
207+ snprintf(tmpfile, sizeof(tmpfile), "%s/xfig-print.XXXXXX", TMPDIR);
208 warnexist = False;
209+ if ((fd = mkstemp(tmpfile)) == -1) {
210+ file_msg("Can't open temp file %s: %s\n", tmpfile, strerror(errno));
211+ return;
212+ }
213+ close(fd);
214+
215 init_write_tmpfile();
216 if (write_file(tmpfile, False)) {
217 end_write_tmpfile();
218@@ -181,14 +188,21 @@
219 char tmp_name[PATH_MAX];
220 char tmp_fig_file[PATH_MAX];
a45c09fa 221 char *outfile, *name, *real_lang;
ce6c6d46 222+ int fd;
223
224 /* if file exists, ask if ok */
225 if (!ok_to_write(file, "EXPORT"))
226 return (1);
227
228- sprintf(tmp_fig_file, "%s/%s%06d", TMPDIR, "xfig-fig", getpid());
229- /* write the fig objects to a temporary file */
230+ snprintf(tmp_fig_file, sizeof(tmp_fig_file), "%s/xfig-fig.XXXXXX", TMPDIR);
231 warnexist = False;
232+ if ((fd = mkstemp(tmp_fig_file)) == -1) {
233+ file_msg("Can't open temp file %s: %s\n", tmp_fig_file,
234+ strerror(errno));
235+ return 1;
236+ }
237+ close(fd);
238+
239 init_write_tmpfile();
240 if (write_file(tmp_fig_file, False)) {
241 end_write_tmpfile();
242@@ -389,10 +403,16 @@
243 char errfname[PATH_MAX];
244 FILE *errfile;
245 char str[400];
246- int status;
247+ int status, fd;
248
249 /* make temp filename for any errors */
250- sprintf(errfname, "%s/xfig-export%06d.err", TMPDIR, getpid());
251+ snprintf(errfname, sizeof(errfname), "%s/xfig-export.XXXXXX", TMPDIR);
252+ if ((fd = mkstemp(errfname)) == -1) {
253+ file_msg("Can't open temp file %s: %s\n", errfname, strerror(errno));
254+ return 1;
255+ }
256+ close(fd);
257+
258 /* direct any output from fig2dev to this file */
259 strcat(command, " 2> ");
260 strcat(command, errfname);
261diff -ur xfig.3.2.3d.orig/w_print.c xfig.3.2.3d/w_print.c
262--- xfig.3.2.3d.orig/w_print.c Wed Dec 13 01:08:56 2000
263+++ xfig.3.2.3d/w_print.c Fri Mar 22 15:37:25 2002
264@@ -286,10 +286,10 @@
265 Widget w;
266 {
267 FILE *infp,*outfp;
268- char tmp_exp_file[32];
269+ char tmp_exp_file[PATH_MAX];
270 char str[255];
a45c09fa 271 char backgrnd[10], grid[80];
ce6c6d46 272-
273+ int fd;
274 if (writing_batch || emptyfigure_msg(print_msg))
275 return;
276
277@@ -297,11 +297,20 @@
278 /* this could happen if the user presses the button too fast */
279 writing_batch = True;
280
281- /* make a temporary name to write the batch stuff to */
282- sprintf(batch_file, "%s/%s%06d", TMPDIR, "xfig-batch", getpid());
283 /* make a temporary name to write this figure to */
284- sprintf(tmp_exp_file, "%s/%s%06d", TMPDIR, "xfig-exp", getpid());
285- batch_exists = True;
286+ snprintf(tmp_exp_file, sizeof(tmp_exp_file), "%s/xfig-exp.XXXXXX",
287+ TMPDIR);
288+
289+ if (batch_exists != True) {
290+ /* make a temporary name to write the batch stuff to */
291+ sprintf(batch_file, "%s/xfig-batch.XXXXXX", TMPDIR);
292+ if ((fd = mkstemp(batch_file)) == -1) {
293+ file_msg("Error creating temporary file");
294+ return;
295+ }
296+ close(fd);
297+ batch_exists = True;
298+ }
299 if (!print_popup)
300 create_print_panel(w);
301
302@@ -313,6 +322,12 @@
303
304 /* make a #rrggbb string from the background color */
305 make_rgb_string(export_background_color, backgrnd);
306+
307+ if ((fd = mkstemp(tmp_exp_file)) == -1) {
308+ file_msg("Error creating temporary file");
309+ return;
310+ }
311+ close(fd);
312
313 print_to_file(tmp_exp_file, "ps", appres.magnification, 0, 0, backgrnd,
314 NULL, FALSE, print_all_layers, 0, FALSE);
315diff -ur xfig.3.2.3d.orig/w_srchrepl.c xfig.3.2.3d/w_srchrepl.c
316--- xfig.3.2.3d.orig/w_srchrepl.c Mon Sep 11 19:23:31 2000
317+++ xfig.3.2.3d/w_srchrepl.c Fri Mar 22 08:26:45 2002
318@@ -777,7 +777,7 @@
319 char *cmd;
320 char str[300];
321 FILE *fp;
322- int len, i;
323+ int len, i, fd;
324 Boolean done = FALSE;
325 static int lines = 0;
326
327@@ -790,9 +790,12 @@
328 }
329 lines = 0;
330
331- sprintf(filename, "%s/xfig-spell.%d", TMPDIR, (int)getpid());
332- fp = fopen(filename, "w");
333- if (fp == NULL) {
334+ snprintf(filename, sizeof(filename), "%s/xfig-spell.XXXXXX", TMPDIR);
335+ if ((fd = mkstemp(filename)) == -1 || (fp = fdopen(fd, "w")) == NULL) {
336+ if (fd != -1) {
337+ unlink(filename);
338+ close(fd);
339+ }
340 file_msg("Can't open temporary file: %s: %s\n", filename, strerror(errno));
341 } else {
342 /* locate all text objects and write them to file fp */
This page took 0.122717 seconds and 4 git commands to generate.