Hello.
I'm attempting to write a wrapper around zlib's compress2.
However, I always get a Z_BUF_ERROR as a result...
I guess that I do not correctly create either the destination buffer, or the pointer on the destination size, but I can't find where my mistake is.

Can anyone help me?

Here is my code:

# http://zlib.net/manual.html#Utility
#
# uLong compressBound (uLong sourceLen)
# int compress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
# int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong 
sourceLen)

# return codes
(setq
   Z_OK             0
   Z_STREAM_END     1
   Z_NEED_DICT      2
   Z_ERRNO         -1
   Z_STREAM_ERROR  -2
   Z_DATA_ERROR    -3
   Z_MEM_ERROR     -4
   Z_BUF_ERROR     -5
   Z_VERSION_ERROR -6
   )

# compression levels
(setq
   Z_NO_COMPRESSION        0
   Z_BEST_SPEED            1
   Z_BEST_COMPRESSION      9
   Z_DEFAULT_COMPRESSION  -1
   )

(de ZcompressBound (BufferSize)
   (native
      "/usr/lib/libz.so"     # lib file
      "compressBound"        # function
      'N                     # return value
      BufferSize ) )         # length

(de genCharBuff ("var")
   (cons "var" 'B "var") )


(de Zcompress2 (inBuf level)
   (let inBufSize (length inBuf)
      (let bufSize (ZcompressBound inBufSize)
         (list
            (native
               "/usr/lib/libz.so"                  # lib file
               "compress2"                         # function
               'I                                  # return value (error status)
               '(dest `(genCharBuff bufSize) . 0)  # *dest
               '(destLen (8 . N) . `bufSize)       # *destLen
               inBuf                               # *source
               inBufSize                           # sourceLen
               level )                             # level
            (head destLen dest) )
         )
      )
   )

## : (Zcompress2 "11111111111111111111111111111111" Z_BEST_SPEED)
## -> (-5 (0))


--
Laurent ARTAUD (laurent.art...@free.fr)
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to