]> mj.ucw.cz Git - libucw.git/blob - lib/fb-temp.c
conf: parsing IP address fixed
[libucw.git] / lib / fb-temp.c
1 /*
2  *      UCW Library -- Temporary Fastbufs
3  *
4  *      (c) 2002--2004 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "lib/conf2.h"
12 #include "lib/fastbuf.h"
13
14 #include <unistd.h>
15 #include <sys/fcntl.h>
16
17 static byte *temp_template = "/tmp/temp%d.%d";
18
19 static struct cf_section temp_config = {
20   CF_ITEMS {
21     CF_STRING("Template", &temp_template),
22     CF_END
23   }
24 };
25
26 static void CONSTRUCTOR temp_init_config(void)
27 {
28   cf_declare_section("Tempfiles", &temp_config, 0);
29 }
30
31 struct fastbuf *
32 bopen_tmp(uns buflen)
33 {
34   byte buf[256];
35   struct fastbuf *f;
36   static uns temp_counter;
37
38   sprintf(buf, temp_template, (int) getpid(), temp_counter++);
39   f = bopen(buf, O_RDWR | O_CREAT | O_TRUNC, buflen);
40   bconfig(f, BCONFIG_IS_TEMP_FILE, 1);
41   return f;
42 }