]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/lizard-safe.c
Xtypes: Documentation
[libucw.git] / ucw / lizard-safe.c
index 06302619587c9bf3c2910747ec9011a3dda645ba..0aa218ddc12b9b206f6ce134f9232d2b3639bec3 100644 (file)
@@ -7,10 +7,10 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/threads.h"
-#include "ucw/sighandler.h"
-#include "ucw/lizard.h"
+#include <ucw/lib.h>
+#include <ucw/threads.h>
+#include <ucw/sighandler.h>
+#include <ucw/lizard.h>
 
 #include <sys/mman.h>
 #include <fcntl.h>
@@ -19,7 +19,7 @@
 #include <errno.h>
 
 struct lizard_buffer {
-  uns len;
+  uint len;
   void *ptr;
 };
 
@@ -43,7 +43,7 @@ lizard_free(struct lizard_buffer *buf)
 }
 
 static void
-lizard_realloc(struct lizard_buffer *buf, uns max_len)
+lizard_realloc(struct lizard_buffer *buf, uint max_len)
   /* max_len needs to be aligned to CPU_PAGE_SIZE */
 {
   if (max_len <= buf->len)
@@ -56,7 +56,7 @@ lizard_realloc(struct lizard_buffer *buf, uns max_len)
   buf->len = max_len;
   buf->ptr = mmap(NULL, buf->len + CPU_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (buf->ptr == MAP_FAILED)
-    die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + CPU_PAGE_SIZE));
+    die("mmap(anonymous, %d bytes): %m", (uint)(buf->len + CPU_PAGE_SIZE));
   if (mprotect(buf->ptr + buf->len, CPU_PAGE_SIZE, PROT_NONE) < 0)
     die("mprotect: %m");
 }
@@ -70,14 +70,9 @@ sigsegv_handler(int signal UNUSED)
 }
 
 byte *
-lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length)
-  /* Decompresses in into buf, sets *ptr to the data, and returns the
-   * uncompressed length.  If an error has occured, -1 is returned and errno is
-   * set.  The buffer buf is automatically reallocated.  SIGSEGV is caught in
-   * case of buffer-overflow.  The function is not re-entrant because of a
-   * static longjmp handler.  */
+lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uint expected_length)
 {
-  uns lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE);      // +3 due to the unaligned access
+  uint lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE);     // +3 due to the unaligned access
   if (lock_offset > buf->len)
     lizard_realloc(buf, lock_offset);
   volatile ucw_sighandler_t old_handler = set_signal_handler(SIGSEGV, sigsegv_handler);