Skip to content

Commit

Permalink
* implemented very simple interface to zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Müller committed Jan 19, 2008
0 parents commit 1d9ee8b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library.dylan
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module: dylan-user
define library zlib
use common-dylan;
use c-ffi;
export zlib;
end library;

define module zlib
use common-dylan;
use c-ffi;
export compress;
end module;
32 changes: 32 additions & 0 deletions main.dylan
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module: zlib
define C-function zlib-compress
parameter destination :: <C-string>;
parameter destination-length :: <C-int*>;
parameter source :: <C-string>;
parameter source-length :: <C-int>;
result return-code :: <C-int>;
c-name: "compress"
end;

define C-function zlib-compress-bound
parameter source-length :: <C-int>;
result return-code :: <C-int>;
c-name: "compressBound"
end;

define function compress (string :: <string>)
=> (compressed-string :: <string>);
let destination-length :: <C-int*> = make(<C-int*>);
destination-length.pointer-value := zlib-compress-bound(size(string));
let result = make(<C-string>, size: destination-length.pointer-value, fill: ' ');
if (zlib-compress(result, destination-length, string, size(string)) ~= 0)
error("zlib compress failed.");
else
result;
end if;
end;
/*
define variable foobar = "foobar";
format-out("%= => %=\n", foobar, compress(foobar));
*/
5 changes: 5 additions & 0 deletions zlib.lid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library: zlib
executable: zlib
c-libraries: -lz
files: library
main

0 comments on commit 1d9ee8b

Please sign in to comment.