]> mj.ucw.cz Git - libucw.git/commitdiff
Fastbufs: More exceptions
authorMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:29:58 +0000 (15:29 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:29:58 +0000 (15:29 +0200)
ucw/doc/fastbuf.txt
ucw/fastbuf.h
ucw/fb-mmap.c
ucw/ff-string.c

index 1578e7607fcfc6603a9d48fb0b8df66d04feda5a..13590a5dd431101a97ae3baec0b3947f6f8915c2 100644 (file)
@@ -80,4 +80,5 @@ exceptions live in the `ucw.fb` subtree. The following exceptions are defined:
 `ucw.fb.read`:: Read error (e.g., the `read` syscall has failed or the stream is write-only)
 `ucw.fb.seek`:: Seek error (e.g., file not seekable, or a seek behind EOF)
 `ucw.fb.tmp`:: Creation of temporary file failed
+`ucw.fb.toolong`:: Object (typically a line) is too long
 `ucw.fb.write`:: Write error (e.g., the `write` syscall has failed or the stream is read-only)
index 990375242953d087a36062a8fbbb13bc4d0ac654..aa6c493177c920b2ab1dabe885c4236ed1f7e89c 100644 (file)
@@ -153,7 +153,7 @@ enum fb_flags {
 };
 
 /** Tie a fastbuf to a resource in the current resource pool. Returns the pointer to the same fastbuf. **/
-struct fastbuf *fb_tie(struct fastbuf *b);
+struct fastbuf *fb_tie(struct fastbuf *b);     /* Tie fastbuf to a resource if there is an active pool */
 
 /***
  * === Fastbuf on files [[fbparam]]
@@ -197,7 +197,7 @@ extern struct fb_params fbpar_def;  /** The default `fb_params` **/
  * Use @params to select the fastbuf back-end and its parameters or
  * pass NULL if you are fine with defaults.
  *
- * Dies if the file does not exist.
+ * 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. **/
@@ -355,7 +355,7 @@ void fbbuf_init_read(struct fastbuf *f, byte *buffer, uns size, uns can_overwrit
 /**
  * Creates a write-only fastbuf which writes into a provided memory buffer.
  * The fastbuf structure is allocated by the caller and pointed to by @f.
- * An attempt to write behind the end of the buffer dies.
+ * An attempt to write behind the end of the buffer causes the `ucw.fb.write` exception.
  *
  * Data are written directly into the buffer, so it is not necessary to call @bflush()
  * at any moment.
@@ -578,7 +578,7 @@ static inline uns bread(struct fastbuf *f, void *b, uns l)
 /**
  * Reads exactly @l bytes of data into @b.
  * If at the end of file, it returns 0.
- * If there are data, but less than @l, it dies.
+ * If there are data, but less than @l, it raises `ucw.fb.eof`.
  */
 static inline uns breadb(struct fastbuf *f, void *b, uns l)
 {
@@ -607,7 +607,7 @@ static inline void bwrite(struct fastbuf *f, const void *b, uns l) /** Writes bu
 /**
  * Reads a line into @b and strips trailing `\n`.
  * Returns pointer to the terminating 0 or NULL on `EOF`.
- * Dies if the line is longer than @l.
+ * Raises `ucw.fb.toolong` if the line is longer than @l.
  **/
 char *bgets(struct fastbuf *f, char *b, uns l);
 char *bgets0(struct fastbuf *f, char *b, uns l);       /** The same as @bgets(), but for 0-terminated strings. **/
@@ -621,7 +621,7 @@ struct mempool;
 struct bb_t;
 /**
  * Read a string, strip the trailing `\n` and store it into growing buffer @b.
- * Dies if the line is longer than @limit.
+ * Raises `ucw.fb.toolong` if the line is longer than @limit.
  **/
 uns bgets_bb(struct fastbuf *f, struct bb_t *b, uns limit);
 /**
index fa0f03e03232bf6fa0b734e767278a967eb44e9f..8f9f0bb28b7d59ac4605d9552d3093012e809a7c 100644 (file)
@@ -182,7 +182,7 @@ bfmmopen_internal(int fd, const char *name, uns mode)
   F->fd = fd;
   F->file_extend = F->file_size = ucw_seek(fd, 0, SEEK_END);
   if (F->file_size < 0)
-    die("seek(%s): %m", name);
+    bthrow(f, "open", "fb-mmap: Cannot detect size of %s -- is it seekable?", name);
   if (mode & O_APPEND)
     f->pos = F->file_size;
   F->mode = mode;
index 366092bf7568a90193bf0f55e097ecfc5dcacbec..e3cb33da86270d3a2af1bdcf9e88c67d3faf745a 100644 (file)
@@ -35,7 +35,7 @@ bgets(struct fastbuf *f, char *b, uns l)
          *b++ = v;
        }
       if (unlikely(cnt == l))
-        die("%s: Line too long", f->name);
+        bthrow(f, "toolong", "%s: Line too long", f->name);
       l -= cnt;
       bdirect_read_commit(f, src);
       src_len = bdirect_read_prepare(f, &src);
@@ -114,7 +114,7 @@ bgets_bb(struct fastbuf *f, struct bb_t *bb, uns limit)
       if (cnt == buf_len)
         {
          if (unlikely(len == limit))
-            die("%s: Line too long", f->name);
+            bthrow(f, "toolong", "%s: Line too long", f->name);
          bb_do_grow(bb, len + 1);
          buf = bb->ptr + len;
          buf_len = MIN(bb->len, limit) - len;
@@ -212,7 +212,7 @@ bgets0(struct fastbuf *f, char *b, uns l)
          b++;
        }
       if (unlikely(cnt == l))
-        die("%s: Line too long", f->name);
+        bthrow(f, "toolong", "%s: Line too long", f->name);
       l -= cnt;
       bdirect_read_commit(f, src);
       src_len = bdirect_read_prepare(f, &src);