Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 215651 Details for
Bug 318031
uncompress() doesn't work
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
test.c
test.c (text/plain), 2.42 KB, created by
Bastien Nocera
on 2007-10-04 10:27:58 UTC
(
hide
)
Description:
test.c
Filename:
MIME Type:
Creator:
Bastien Nocera
Created:
2007-10-04 10:27:58 UTC
Size:
2.42 KB
patch
obsolete
> >/* gcc -Wall -g -o test test.c `pkg-config --libs --cflags glib-2.0` -lz */ > >#include <string.h> >#include <glib.h> >#include <zlib.h> > >/* gzip flag byte */ >#define GZIP_IS_ASCII 0x01 /* file contains text ? */ >#define GZIP_HEADER_CRC 0x02 /* there is a CRC in the header */ >#define GZIP_EXTRA_FIELD 0x04 /* there is an 'extra' field */ >#define GZIP_ORIGINAL_NAME 0x08 /* the original is stored */ >#define GZIP_HAS_COMMENT 0x10 /* There is a comment in the header */ >#define GZIP_HEADER_FLAGS (unsigned)(GZIP_IS_ASCII |GZIP_HEADER_CRC |GZIP_EXTRA_FIELD |GZIP_ORIGINAL_NAME |GZIP_HAS_COMMENT) > >#define GSF_LE_GET_GUINT32(p) \ > (guint32)((((guint8 const *)(p))[0] << 0) | \ > (((guint8 const *)(p))[1] << 8) | \ > (((guint8 const *)(p))[2] << 16) | \ > (((guint8 const *)(p))[3] << 24)) > >static guint32 >check_header (char *data, gsize len) >{ > static guint8 const signature[2] = {0x1f, 0x8b}; > unsigned flags; > > if (len < 2 + 1 + 1 + 6) > return -1; > > /* Check signature */ > if (memcmp (data, signature, sizeof (signature)) != 0) > return -1; > > /* verify flags and compression type */ > flags = data[3]; > if (data[2] != Z_DEFLATED || (flags & ~GZIP_HEADER_FLAGS) != 0) > return TRUE; > > /* Get the uncompressed size */ > /* FIXME, but how? The size read here is modulo 2^32. */ > return GSF_LE_GET_GUINT32 (data + len - 4); >} > >static char * >decompress_gzip (char *data, gsize len) >{ > guint32 retlen; > gulong reallen; > char *ret; > int i, j; > > retlen = check_header (data, len); > if (retlen < 0) > return NULL; > g_message ("retlen %d", retlen); > /* +1 so we can NULL-terminate */ > ret = g_malloc0 (retlen + 1); > reallen = retlen; > if ((i = uncompress ((guchar *) ret, (uLongf *) &reallen, (guchar *) data + j, (uLongf) len - j)) != Z_OK) { > g_message ("uncompress didn't work %d", i); > g_free (ret); > return NULL; > } > > return ret; >} > >int main (int argc, char **argv) >{ >#if 0 > GMappedFile *mapped; > char *uncompressed; > > mapped = g_mapped_file_new (argv[1], FALSE, NULL); > if (!mapped) { > g_warning ("couldn't map %s", argv[1]); > return 1; > } > > uncompressed = decompress_gzip ( > g_mapped_file_get_contents (mapped), > g_mapped_file_get_length (mapped)); >#else > char *contents, *uncompressed; > gsize len; > > if (g_file_get_contents (argv[1], &contents, &len, NULL) == FALSE) { > g_message ("couldn't get contents for %s", argv[1]); > return 1; > } > > uncompressed = decompress_gzip (contents, len); >#endif > g_message ("podcast data: %s", uncompressed); > > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 318031
: 215651