FreeCalypso > hg > falcon-mail-tools
view f-demime/attach_out.c @ 6:cd2dcf6eed67
add top Makefile
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 06 May 2023 15:24:38 +0000 |
parents | 7e0d08176f32 |
children |
line wrap: on
line source
/* * 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); }