FreeCalypso > hg > falcon-mail-tools
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/f-demime/attach_out.c Sat May 06 06:14:03 2023 +0000 @@ -0,0 +1,57 @@ +/* + * This module contains code for creating (writing) secondary output files + * intended for storing attached base64 blobs. + */ + +#include <sys/file.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "defs.h" + +extern char *att_filename_buf, *att_filename_tail; +extern void (*dec_outf)(); + +static unsigned att_count; +static FILE *att_outf; +static int giveup_flag; + +static void +output_func(ch) +{ + putc(ch, att_outf); +} + +init_attach_out() +{ + int fd; + + if (giveup_flag) + return(-1); + for (;;) { + if (att_count >= 10000) { + giveup_flag = 1; + return(-1); + } + sprintf(att_filename_tail, "%04u", att_count++); + fd = open(att_filename_buf, O_WRONLY|O_CREAT|O_EXCL, 0644); + if (fd >= 0) + break; + } + att_outf = fdopen(fd, "w"); + if (!att_outf) { + perror("fdopen"); + close(fd); + return(-1); + } + dec_outf = output_func; + return(0); +} + +void +attach_out_finish() +{ + fclose(att_outf); +}