diff options
| author | H. Peter Anvin <hpa@zytor.com> | 2008-02-29 11:57:36 -0800 |
|---|---|---|
| committer | H. Peter Anvin <hpa@zytor.com> | 2008-02-29 11:57:36 -0800 |
| commit | a7504c1fc6c3f90d30197bf0ecfa23880a375697 (patch) | |
| tree | e71e3a60e48de143f90499602edb639c8dd82bdb /com32/lib/syslinux/loadfile.c | |
| parent | b89d1480c656a4f4642cb84ed18d9214faca1308 (diff) | |
| download | syslinux-a7504c1fc6c3f90d30197bf0ecfa23880a375697.tar.gz | |
Generic framework for reading compressed files using standard I/O
Add zopen(), zfopen(), and zloadfile() to transparently open and
uncompress a gzip file (adding support for other formats is quite
trivial.
Once a file handle or file pointer is received, it can be treated like
any other one (fstat will report it as a socket, since the length is
unknown.)
Diffstat (limited to 'com32/lib/syslinux/loadfile.c')
| -rw-r--r-- | com32/lib/syslinux/loadfile.c | 90 |
1 files changed, 20 insertions, 70 deletions
diff --git a/com32/lib/syslinux/loadfile.c b/com32/lib/syslinux/loadfile.c index f5479dab..42a1fd61 100644 --- a/com32/lib/syslinux/loadfile.c +++ b/com32/lib/syslinux/loadfile.c @@ -2,11 +2,26 @@ * * Copyright 2005-2008 H. Peter Anvin - All Rights Reserved * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * ----------------------------------------------------------------------- */ @@ -41,68 +56,3 @@ int loadfile(const char *filename, void **ptr, size_t *len) return rv; } - -int floadfile(FILE *f, void **ptr, size_t *len, const void *prefix, - size_t prefix_len) -{ - struct stat st; - void *data, *dp; - size_t alen, clen, rlen, xlen; - - clen = alen = 0; - data = NULL; - - if ( fstat(fileno(f), &st) ) - goto err; - - if (!S_ISREG(st.st_mode)) { - /* Not a regular file, we can't assume we know the file size */ - if (prefix_len) { - clen = alen = prefix_len; - data = malloc(prefix_len); - if (!data) - goto err; - - memcpy(data, prefix, prefix_len); - } - - do { - alen += INCREMENTAL_CHUNK; - dp = realloc(data, alen); - if (!dp) - goto err; - data = dp; - - rlen = fread((char *)data+clen, 1, alen-clen, f); - clen += rlen; - } while (clen == alen); - - *len = clen; - xlen = (clen + LOADFILE_ZERO_PAD-1) & ~(LOADFILE_ZERO_PAD-1); - dp = realloc(data, xlen); - if (dp) - data = dp; - *ptr = data; - } else { - *len = clen = st.st_size + prefix_len - ftell(f); - xlen = (clen + LOADFILE_ZERO_PAD-1) & ~(LOADFILE_ZERO_PAD-1); - - *ptr = data = malloc(xlen); - if ( !data ) - return -1; - - memcpy(data, prefix, prefix_len); - - if ( (off_t)fread((char *)data+prefix_len, 1, clen-prefix_len, f) - != clen-prefix_len ) - goto err; - } - - memset((char *)data + clen, 0, xlen-clen); - return 0; - - err: - if (data) - free(data); - return -1; -} |
