Sebastian Kuschel reports that pfd_closing can be called for a socket
[u/mdw/putty] / unix / uxprint.c
1 /*
2 * Printing interface for PuTTY.
3 */
4
5 #include <assert.h>
6 #include <stdio.h>
7 #include "putty.h"
8
9 struct printer_job_tag {
10 FILE *fp;
11 };
12
13 printer_job *printer_start_job(char *printer)
14 {
15 printer_job *ret = snew(printer_job);
16 /*
17 * On Unix, we treat the printer string as the name of a
18 * command to pipe to - typically lpr, of course.
19 */
20 ret->fp = popen(printer, "w");
21 if (!ret->fp) {
22 sfree(ret);
23 ret = NULL;
24 }
25 return ret;
26 }
27
28 void printer_job_data(printer_job *pj, void *data, int len)
29 {
30 if (!pj)
31 return;
32
33 if (fwrite(data, 1, len, pj->fp) < len)
34 /* ignore */;
35 }
36
37 void printer_finish_job(printer_job *pj)
38 {
39 if (!pj)
40 return;
41
42 pclose(pj->fp);
43 sfree(pj);
44 }
45
46 /*
47 * There's no sensible way to enumerate printers under Unix, since
48 * practically any valid Unix command is a valid printer :-) So
49 * these are useless stub functions, and uxcfg.c will disable the
50 * drop-down list in the printer configurer.
51 */
52 printer_enum *printer_start_enum(int *nprinters_ptr) {
53 *nprinters_ptr = 0;
54 return NULL;
55 }
56 char *printer_get_name(printer_enum *pe, int i) { return NULL;
57 }
58 void printer_finish_enum(printer_enum *pe) { }