X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Ffastbuf.h;h=99a9dd47285f04f5adb0c458370ced1c359a2dff;hb=4e2835850dfa4d869e470017d921f4d36293b111;hp=9b0f72510fcc793e571a4da995fafd0348ec3702;hpb=0b7df598070533b746e6162e53f90af764bd8f83;p=libucw.git diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index 9b0f7251..99a9dd47 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -3,6 +3,7 @@ * * (c) 1997--2011 Martin Mares * (c) 2004 Robert Spalek + * (c) 2014 Pavel Charvat * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -73,6 +74,9 @@ #define fbmulti_append ucw_fbmulti_append #define fbmulti_create ucw_fbmulti_create #define fbmulti_remove ucw_fbmulti_remove +#define fbnull_open ucw_fbnull_open +#define fbnull_start ucw_fbnull_start +#define fbnull_test ucw_fbnull_test #define fbpar_cf ucw_fbpar_cf #define fbpar_def ucw_fbpar_def #define fbpool_end ucw_fbpool_end @@ -107,7 +111,7 @@ * ^ ^ ^ ^ * buffer <= bstop (BE pos) <= bptr (FE pos) <= bufend * - * * This schema describes a fastbuf after its initialization or bflush(). + * * This schema describes a fastbuf after its initialization or @bflush(). * * There is no cached data and we are ready for any read or write operation * (well, only if the back-end supports it). * * The interval `[bptr, bufend]` can be used by front-ends @@ -266,7 +270,7 @@ extern struct fb_params fbpar_def; /** The default `fb_params` **/ * Raises `ucw.fb.open` if the file does not exist. **/ struct fastbuf *bopen_file(const char *name, int mode, struct fb_params *params); -struct fastbuf *bopen_file_try(const char *name, int mode, struct fb_params *params); /** Like bopen_file(), but returns NULL on failure. **/ +struct fastbuf *bopen_file_try(const char *name, int mode, struct fb_params *params); /** Like @bopen_file(), but returns NULL on failure. **/ /** * Opens a temporary file. @@ -470,7 +474,7 @@ struct fbpool { /** Structure for fastbufs & mempools. **/ /** * Initialize a new `fbpool`. The structure is allocated by the caller, - * so bclose() should not be called and no resource tying takes place. + * so @bclose() should not be called and no resource tying takes place. **/ void fbpool_init(struct fbpool *fb); /** Initialize a new mempool fastbuf. **/ /** @@ -542,6 +546,25 @@ static inline void fbatomic_commit(struct fastbuf *b) fbatomic_internal_write(b); } +/*** === Null fastbufs ***/ + +/** + * Creates a new "/dev/null"-like fastbuf. + * Any read attempt returns an EOF, any write attempt is silently ignored. + **/ +struct fastbuf *fbnull_open(uns bufsize); + +/** + * Can be used by any back-end to switch it to the null mode. + * You need to provide at least one byte long buffer for writing. + **/ +void fbnull_start(struct fastbuf *b, byte *buf, uns bufsize); + +/** + * Checks whether a fastbuf has been switched to the null mode. + **/ +bool fbnull_test(struct fastbuf *b); + /*** * === Fastbufs atop other fastbufs [[fbmulti]] *