]> mj.ucw.cz Git - libucw.git/blob - lib/fb-temp.c
Added bit_array_assign(), replaced BIT_ARRAY_ALLOC by functions.
[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/conf.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 cfitem temp_config[] = {
20   { "Tempfiles",        CT_SECTION,     NULL },
21   { "Template",         CT_STRING,      &temp_template },
22   { NULL,               CT_STOP,        NULL }
23 };
24
25 static void CONSTRUCTOR temp_init_config(void)
26 {
27   cf_register(temp_config);
28 }
29
30 struct fastbuf *
31 bopen_tmp(uns buflen)
32 {
33   byte buf[256];
34   struct fastbuf *f;
35   static uns temp_counter;
36
37   sprintf(buf, temp_template, (int) getpid(), temp_counter++);
38   f = bopen(buf, O_RDWR | O_CREAT | O_TRUNC, buflen);
39   bconfig(f, BCONFIG_IS_TEMP_FILE, 1);
40   return f;
41 }