]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-atomic.c
tableprinter: removed some obsolete FIXME, added some comments
[libucw.git] / ucw / fb-atomic.c
index 1b4a07bbd1a38296af15a0d6291d162ca6d86719..a29e758b62283cc2e9a29f96440714d4e515736e 100644 (file)
@@ -7,23 +7,24 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
-#include "ucw/lfs.h"
-#include "ucw/conf.h"
-#include "ucw/trans.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
+#include <ucw/io.h>
+#include <ucw/conf.h>
+#include <ucw/trans.h>
 
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 
-static uns trace;
+static uint trace;
 
 #ifndef TEST
 
 static struct cf_section fbatomic_config = {
   CF_ITEMS {
-    CF_UNS("Trace", &trace)
+    CF_UINT("Trace", &trace),
+    CF_END
   }
 };
 
@@ -34,13 +35,14 @@ static void CONSTRUCTOR fbatomic_init_config(void)
 
 #endif
 
+#define FB_ATOMIC(f) ((struct fb_atomic *)(f))
 #define TRACE(m...) do { if(trace) msg(L_DEBUG, "FB_ATOMIC: " m); } while(0)
 
 struct fb_atomic_file {
   int fd;
   int use_count;
   int record_len;
-  uns locked;
+  uint locked;
   byte name[1];
 };
 
@@ -54,9 +56,9 @@ fbatomic_internal_write(struct fastbuf *f)
       ASSERT(af->record_len < 0 || !(size % af->record_len));
       int res = write(af->fd, f->buffer, size);
       if (res < 0)
-       bthrow(f, "fb.write", "Error writing %s: %m", f->name);
+       bthrow(f, "write", "Error writing %s: %m", f->name);
       if (res != size)
-       bthrow(f, "fb.write", "Unexpected partial write to %s: written only %d bytes of %d", f->name, res, size);
+       bthrow(f, "write", "Unexpected partial write to %s: written only %d bytes of %d", f->name, res, size);
       f->bptr = f->buffer;
     }
 }
@@ -70,13 +72,14 @@ fbatomic_spout(struct fastbuf *f)
   struct fb_atomic *F = FB_ATOMIC(f);
   if (F->af->locked)
     {
-      uns written = f->bptr - f->buffer;
-      uns size = f->bufend - f->buffer + F->slack_size;
+      uint written = f->bptr - f->buffer;
+      uint size = f->bufend - f->buffer + F->slack_size;
       F->slack_size *= 2;
       TRACE("Reallocating buffer for atomic file %s with slack %d", f->name, F->slack_size);
       f->buffer = xrealloc(f->buffer, size);
       f->bufend = f->buffer + size;
       f->bptr = f->buffer + written;
+      f->bstop = f->buffer;
       F->expected_max_bptr = f->bufend - F->slack_size;
     }
   else
@@ -98,7 +101,7 @@ fbatomic_close(struct fastbuf *f)
 }
 
 struct fastbuf *
-fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_len)
+fbatomic_open(const char *name, struct fastbuf *master, uint bufsize, int record_len)
 {
   struct fb_atomic *F = xmalloc_zero(sizeof(*F));
   struct fastbuf *f = &F->fb;
@@ -113,7 +116,7 @@ fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_
     {
       int fd = ucw_open(name, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666);
       if (fd < 0)
-       trans_throw("fb.open", NULL, "Cannot create %s: %m", name);
+       trans_throw("ucw.fb.open", NULL, "Cannot create %s: %m", name);
       af = xmalloc_zero(sizeof(*af) + strlen(name));
       af->fd = fd;
       af->use_count = 1;
@@ -133,7 +136,6 @@ fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_
   f->name = af->name;
   f->spout = fbatomic_spout;
   f->close = fbatomic_close;
-  fb_tie(f);
   return f;
 }