]> mj.ucw.cz Git - libucw.git/blob - lib/fb-temp.c
New functions for manipulating attribute lists: obj_prepend_attr()
[libucw.git] / lib / fb-temp.c
1 /*
2  *      Sherlock Library -- Temporary Fastbufs
3  *
4  *      (c) 2002 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8 #include "lib/conf.h"
9 #include "lib/fastbuf.h"
10
11 #include <unistd.h>
12 #include <sys/fcntl.h>
13
14 static byte *temp_template = "/tmp/temp%d.%d";
15
16 static struct cfitem temp_config[] = {
17   { "Tempfiles",        CT_SECTION,     NULL },
18   { "Template",         CT_STRING,      &temp_template },
19   { NULL,               CT_STOP,        NULL }
20 };
21
22 static void CONSTRUCTOR temp_init_config(void)
23 {
24   cf_register(temp_config);
25 }
26
27 struct fastbuf *
28 bopen_tmp(uns bufsize)
29 {
30   byte buf[256];
31   struct fastbuf *f;
32   static uns temp_counter;
33
34   sprintf(buf, temp_template, (int) getpid(), temp_counter++);
35   f = bopen(buf, O_RDWR | O_CREAT | O_EXCL, bufsize);
36   f->is_temp_file = 1;
37   return f;
38 }