temporarily lower the rights. I need it somewhere.
* Sherlock Library -- Object Buckets
*
* (c) 2001--2004 Martin Mares <mj@ucw.cz>
+ * (c) 2004 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
struct fb_bucket {
struct fastbuf fb;
+ int can_overwrite;
sh_off_t start_pos;
uns bucket_size;
byte buffer[0];
}
static int
-obuck_bconfig(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+obuck_bconfig(struct fastbuf *f, uns item, int value)
{
switch (item)
{
- case BCONFIG_CAN_OVERWRITE:
- return 2;
+ case BCONFIG_CAN_OVERWRITE: ;
+ int old_value = FB_BUCKET(f)->can_overwrite;
+ if (value >= 0 && value <= 2)
+ FB_BUCKET(f)->can_overwrite = value;
+ return old_value;
default:
return -1;
}
b->config = NULL;
FB_BUCKET(b)->start_pos = start;
FB_BUCKET(b)->bucket_size = 0;
+ FB_BUCKET(b)->can_overwrite = 2;
bwrite(b, &obuck_create_hdr, sizeof(obuck_create_hdr));
return b;
* Sherlock Library -- Fast Buffered I/O on Static Buffers
*
* (c) 2003 Martin Mares <mj@ucw.cz>
+ * (c) 2004 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#include "lib/lib.h"
#include "lib/fastbuf.h"
+static int
+fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+{
+ switch (item)
+ {
+ case BCONFIG_CAN_OVERWRITE:
+ // XXX: should we enable changing the value?
+ return 1;
+ default:
+ return -1;
+ }
+}
+
static int
fbbuf_refill(struct fastbuf *f UNUSED)
{
f->spout = NULL;
f->seek = NULL;
f->close = NULL;
- f->config = NULL;
+ f->config = fbbuf_config;
}
static void
die("fbbuf: buffer overflow on write");
}
-static int
-fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
-{
- switch (item)
- {
- case BCONFIG_CAN_OVERWRITE:
- return 1;
- default:
- return -1;
- }
-}
-
void
fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
{
* Sherlock Library -- Fast Buffered I/O on Files
*
* (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ * (c) 2004 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
struct fastbuf fb;
int fd; /* File descriptor, -1 if not a real file */
int is_temp_file; /* 0=normal file, 1=temporary file, delete on close, -1=shared FD */
+ int can_overwrite;
};
#define FB_FILE(f) ((struct fb_file *)(f)->is_fastbuf)
case BCONFIG_IS_TEMP_FILE:
FB_FILE(f)->is_temp_file = value;
return 0;
- case BCONFIG_CAN_OVERWRITE:
- return 2;
+ case BCONFIG_CAN_OVERWRITE: ;
+ int old_value = FB_FILE(f)->can_overwrite;
+ if (value >= 0 && value <= 2)
+ FB_FILE(f)->can_overwrite = value;
+ return old_value;
default:
return -1;
}
f->seek = bfd_seek;
f->close = bfd_close;
f->config = bfd_config;
+ F->can_overwrite = 2;
return f;
}
* Sherlock Library -- Fast Buffered Input on Limited File Descriptors
*
* (c) 2003 Martin Mares <mj@ucw.cz>
+ * (c) 2004 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
struct fastbuf fb;
int fd; /* File descriptor */
int limit;
+ int can_overwrite;
};
#define FB_LIMFD(f) ((struct fb_limfd *)(f)->is_fastbuf)
}
static int
-bfl_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+bfl_config(struct fastbuf *f, uns item, int value)
{
switch (item)
{
- case BCONFIG_CAN_OVERWRITE:
- return 2;
+ case BCONFIG_CAN_OVERWRITE: ;
+ int old_value = FB_LIMFD(f)->can_overwrite;
+ if (value >= 0 && value <= 2)
+ FB_LIMFD(f)->can_overwrite = value;
+ return old_value;
default:
return -1;
}
f->refill = bfl_refill;
f->close = bfl_close;
f->config = bfl_config;
+ F->can_overwrite = 2;
return f;
}
* Sherlock Library -- Fast Buffered I/O on Memory Streams
*
* (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ * (c) 2004 Robert Spalek <robert@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
struct fastbuf fb;
struct memstream *stream;
struct msblock *block;
+ int can_overwrite;
};
#define FB_MEM(f) ((struct fb_mem *)(f)->is_fastbuf)
}
static int
-fbmem_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
+fbmem_config(struct fastbuf *f, uns item, int value)
{
switch (item)
{
- case BCONFIG_CAN_OVERWRITE:
- return 1;
+ case BCONFIG_CAN_OVERWRITE: ;
+ int old_value = FB_MEM(f)->can_overwrite;
+ if (value >= 0 && value <= 1)
+ FB_MEM(f)->can_overwrite = value;
+ return old_value;
default:
return -1;
}
f->seek = fbmem_seek;
f->close = fbmem_close;
f->config = fbmem_config;
+ FB_MEM(f)->can_overwrite = 1;
return f;
}