FreeCalypso > hg > falcon-mail-tools
comparison f-demime/attach_out.c @ 0:7e0d08176f32
f-demime starting code
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 06 May 2023 06:14:03 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7e0d08176f32 |
|---|---|
| 1 /* | |
| 2 * This module contains code for creating (writing) secondary output files | |
| 3 * intended for storing attached base64 blobs. | |
| 4 */ | |
| 5 | |
| 6 #include <sys/file.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <strings.h> | |
| 11 #include <unistd.h> | |
| 12 #include "defs.h" | |
| 13 | |
| 14 extern char *att_filename_buf, *att_filename_tail; | |
| 15 extern void (*dec_outf)(); | |
| 16 | |
| 17 static unsigned att_count; | |
| 18 static FILE *att_outf; | |
| 19 static int giveup_flag; | |
| 20 | |
| 21 static void | |
| 22 output_func(ch) | |
| 23 { | |
| 24 putc(ch, att_outf); | |
| 25 } | |
| 26 | |
| 27 init_attach_out() | |
| 28 { | |
| 29 int fd; | |
| 30 | |
| 31 if (giveup_flag) | |
| 32 return(-1); | |
| 33 for (;;) { | |
| 34 if (att_count >= 10000) { | |
| 35 giveup_flag = 1; | |
| 36 return(-1); | |
| 37 } | |
| 38 sprintf(att_filename_tail, "%04u", att_count++); | |
| 39 fd = open(att_filename_buf, O_WRONLY|O_CREAT|O_EXCL, 0644); | |
| 40 if (fd >= 0) | |
| 41 break; | |
| 42 } | |
| 43 att_outf = fdopen(fd, "w"); | |
| 44 if (!att_outf) { | |
| 45 perror("fdopen"); | |
| 46 close(fd); | |
| 47 return(-1); | |
| 48 } | |
| 49 dec_outf = output_func; | |
| 50 return(0); | |
| 51 } | |
| 52 | |
| 53 void | |
| 54 attach_out_finish() | |
| 55 { | |
| 56 fclose(att_outf); | |
| 57 } |
