aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/common.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-12-15 19:39:13 +0200
committerLasse Collin <lasse.collin@tukaani.org>2008-12-15 19:39:13 +0200
commit671a5adf1e844bfdd6fd327016c3c28694493158 (patch)
tree87f8e40cb30f2641b5b211e3bd3bec9ce084c95e /src/liblzma/common/common.c
parentThe LZMA2 decoder fix introduced a bug to LZ decoder, (diff)
downloadxz-671a5adf1e844bfdd6fd327016c3c28694493158.tar.xz
Bunch of liblzma API cleanups and fixes.
Diffstat (limited to '')
-rw-r--r--src/liblzma/common/common.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
index c5f5039d..81f783da 100644
--- a/src/liblzma/common/common.c
+++ b/src/liblzma/common/common.c
@@ -301,5 +301,63 @@ lzma_end(lzma_stream *strm)
extern LZMA_API lzma_check
lzma_get_check(const lzma_stream *strm)
{
+ // Return LZMA_CHECK_NONE if we cannot know the check type.
+ // It's a bug in the application if this happens.
+ if (strm->internal->next.get_check == NULL)
+ return LZMA_CHECK_NONE;
+
return strm->internal->next.get_check(strm->internal->next.coder);
}
+
+
+extern LZMA_API uint64_t
+lzma_memusage(const lzma_stream *strm)
+{
+ uint64_t memusage;
+ uint64_t old_memlimit;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL
+ || strm->internal->next.memconfig(
+ strm->internal->next.coder,
+ &memusage, &old_memlimit, 0) != LZMA_OK)
+ return 0;
+
+ return memusage;
+}
+
+
+extern LZMA_API uint64_t
+lzma_memlimit_get(const lzma_stream *strm)
+{
+ uint64_t old_memlimit;
+ uint64_t memusage;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL
+ || strm->internal->next.memconfig(
+ strm->internal->next.coder,
+ &memusage, &old_memlimit, 0) != LZMA_OK)
+ return 0;
+
+ return old_memlimit;
+}
+
+
+extern LZMA_API lzma_ret
+lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
+{
+ // Dummy variables to simplify memconfig functions
+ uint64_t old_memlimit;
+ uint64_t memusage;
+
+ if (strm == NULL || strm->internal == NULL
+ || strm->internal->next.memconfig == NULL)
+ return LZMA_PROG_ERROR;
+
+ if (new_memlimit != 0 && new_memlimit < LZMA_MEMUSAGE_BASE)
+ return LZMA_MEMLIMIT_ERROR;
+
+ return strm->internal->next.memconfig(strm->internal->next.coder,
+ &memusage, &old_memlimit, new_memlimit);
+}