Commit a3f113e8 authored by Tomas Gavenciak's avatar Tomas Gavenciak
Browse files

Merge tag '4c74fe3db1f973b2ed24282603b669842a755cf3'

Releasing version 6.5.8

* tag '4c74fe3db1f973b2ed24282603b669842a755cf3': (34 commits)
  Released as 6.5.8.
  bgets_mp(): Rewritten implementation.
  bgets_mp(): Added a non-intuitive warning to documentation.
  Released as 6.5.7.
  Base64: Rewritten base64 encoder and decoder.
  Revert "Unicode: Added reading of 32bit UTF-8 unicode values with protection against buffer overflow."
  CLists, SLists: Extended interface for merging of link lists.
  Unicode: Added reading of 32bit UTF-8 unicode values with protection against buffer overflow.
  Released as 6.5.6
  UCW::Configure: Fixed compatibility with old perl.
  Doc: Added explanation of FB exceptions vs. fb_tie()
  Debian: Updated a comment on CONFIG_UCW_PERL_MODULES
  UCW::Configure::Perl: Split off configuration of Perl paths
  UCW::Configure: Flush STDOUT after logging
  Fastbufs: bclose() on caller-allocated fastbuf is allowed
  Build: "make install" should install also UCW::Configure module.
  Build: Added support for custom PKG_CONFIG_PATH in UCW::Configure::PkgConfig().
  Released as 6.5.4
  Lizard: Fixed a typo in documentation.
  FB Socket: Fixed tracking of written bytes.
  ...
parents 5c31fe9c f2276e0c
......@@ -30,6 +30,7 @@ require UCW::Configure::Paths;
require UCW::Configure::C;
require UCW::Configure::LibUCW;
require UCW::Configure::Doc;
require UCW::Configure::Perl;
Finish();
Log "\nConfigured, run `make' to build everything.\n";
......@@ -15,4 +15,11 @@ UnSet("CONFIG_IMAGES_LIBUNGIF");
Set("CONFIG_IMAGES_LIBGIF");
UnSet("CONFIG_UCW_OBSOLETE_DAEMON_HELPER");
# The basic Perl modules (UCW::Configure etc.) are installed,
# but extensions involving XS code (UCW::FileLock, UCW::Ulimit)
# aren't, because they are seldom used and their installation
# rules used to be incompatible with Debian directory structure.
# They should work now, so feel free to revive them if needed.
UnSet("CONFIG_UCW_PERL_MODULES");
1;
......@@ -20,7 +20,7 @@ Package: libucw-dev
Section: libdevel
Architecture: any
Depends: libucw@UCW_ABI_SUFFIX@ (= @VER@), ${shlibs:Depends}, ${misc:Depends}
Description: LibUCW development files
Description: LibUCW development files, including the build system
Package: libucw-utils
Section: misc
......@@ -28,6 +28,12 @@ Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: LibUCW utilities
Package: libucw-perl
Section: misc
Architecture: any
Depends: libucw@UCW_ABI_SUFFIX@, ${shlib:Depends}, ${misc:Depends}
Description: Companion Perl modules for LibUCW (UCW::CGI, UCW::Config, UCW::Log)
#ifdef CONFIG_DOC
Package: libucw-doc
Section: doc
......
#!/bin/bash
# A script for building of LibUCW packages
# (c) 2013--2014 Pavel Charvat <pchar@ucw.cz>
# (c) 2013--2017 Pavel Charvat <pchar@ucw.cz>
set -e
. debian/pkg-lib
......@@ -16,6 +16,7 @@ Options:
--abi-version=<ver> Custom version number of the LibUCW's ABI (default: defined in ucw/default.cfg)
--gen-script=<script> Custom script to postprocess
--extra-conf=<args> Add extra arguments to the configure script
--no-checkout Expect manually checked out sources to build directory (useful for chrooted building; --version is mandatory)
EOF
exit 1
}
......@@ -69,7 +70,9 @@ while [ -n "$1" ] ; do
;;
--extra-conf=*) CONF="$CONF ${1:13}"
;;
*) usage
--no-checkout) PKG_NO_CHECKOUT=1
;;
*) usage
;;
esac
shift
......@@ -78,7 +81,7 @@ done
pkg-git-version
pkg-git-checkout
echo $TREEVER >$BUILDDIR/UCW_VERSION
echo $VER >$BUILDDIR/UCW_VERSION
pkg-gen-debian
BUILDOPTS=
......
# A library of shell functions for building of Debian packages
# (c) 2008--2009 Martin Mares <mj@ucw.cz>
# (c) 2009--2013 Pavel Charvat <pchar@ucw.cz>
# (c) 2009--2017 Pavel Charvat <pchar@ucw.cz>
# Expects:
# PKG name of the package
# ROOT absolute path to the root of the source tree
# PKGVER custom package version
unset PKG ROOT SRCVER VER
unset PKG ROOT SRCVER VER PKG_NO_CHECKOUT
function pkg-git-version {
TREEVER=`git describe --tags | sed 's/^v//;s/[a-f]$/&-0/'`
TREEHASH=`git rev-parse --verify HEAD`
if [ -z "$PKG_NO_CHECKOUT" ] ; then
TREEVER=`git describe --tags | sed 's/^v//;s/[a-f]$/&-0/'`
TREEHASH=`git rev-parse --verify HEAD`
else
TREEVER=?
TREEHASH=?
fi
VER=${PKGVER:-$TREEVER}
SRCVER=${PKGVER:-$VER}
cat <<EOF
......@@ -29,9 +34,11 @@ EOF
function pkg-git-checkout {
BUILDDIR=debian-tmp/$PKG-$SRCVER
rm -rf debian-tmp
mkdir -p $BUILDDIR
git checkout-index -a --prefix=$BUILDDIR/
if [ -z "$PKG_NO_CHECKOUT" ] ; then
rm -rf debian-tmp
mkdir -p $BUILDDIR
git checkout-index -a --prefix=$BUILDDIR/
fi
}
function pkg-fake-changelog {
......
......@@ -7,7 +7,7 @@
include obj/config.mk
build: build-stamp
build build-arch build-indep: build-stamp
build-stamp:
dh_testdir
......@@ -28,8 +28,9 @@ install: build
dh_clean -k
dh_installdirs
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw$(UCW_ABI_SUFFIX) install-libucw-lib
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw-dev install-libucw-api
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw-dev install-libucw-api install-perl-ucw-configure install-build
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw-utils install-ucw-shell install-ucw-utils
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw-perl install-perl-ucw
ifdef CONFIG_DOC
$(MAKE) DESTDIR=$(CURDIR)/debian/libucw-doc install-libucw-docs install-libucw-man install-libucw-config
install -d -m 755 $(CURDIR)/debian/libucw-doc/usr/share/doc/libucw/examples
......@@ -76,7 +77,7 @@ binary-arch: build install
# dh_strip
dh_compress -Xusr/share/doc/libucw/
dh_fixperms
# dh_perl
dh_perl
# dh_python
dh_makeshlibs -V
dh_installdeb
......@@ -86,4 +87,4 @@ binary-arch: build install
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install
......@@ -2,6 +2,7 @@
* UCW Library -- Base 64 Encoding & Decoding
*
* (c) 2002, Robert Spalek <robert@ucw.cz>
* (c) 2018, Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
......@@ -11,112 +12,116 @@
#include <ucw/lib.h>
#include <ucw/base64.h>
#include <ucw/threads.h>
#include <string.h>
const byte base64_enc_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const byte base64_dec_table[256] = {
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x3e, 0x80, 0x80, 0x80, 0x3f,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x80, 0x80, 0x80, 0x40, 0x80, 0x80,
0x80, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
};
static const byte base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
static const byte base64_pad = '=';
uint
base64_encode(byte *dest, const byte *src, uint len)
uint base64_encode(byte *dest, const byte *src, uint len)
{
const byte *current = src;
uint i = 0;
const byte *ptr = src;
const byte *end = src + len;
byte *out = dest;
while (len > 2) { /* keep going until we have less than 24 bits */
dest[i++] = base64_table[current[0] >> 2];
dest[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
dest[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
dest[i++] = base64_table[current[2] & 0x3f];
/* keep going until we have less than 24 bits */
if (end - ptr >= 3)
for (const byte *x = end - 2; ptr < x; )
{
out[0] = base64_enc_table[ptr[0] >> 2];
out[1] = base64_enc_table[((ptr[0] & 0x03) << 4) + (ptr[1] >> 4)];
out[2] = base64_enc_table[((ptr[1] & 0x0f) << 2) + (ptr[2] >> 6)];
out[3] = base64_enc_table[ptr[2] & 0x3f];
out += 4;
ptr += 3;
}
current += 3;
len -= 3; /* we just handle 3 octets of data */
/* now deal with the tail end of things */
if (ptr != end)
{
out[0] = base64_enc_table[ptr[0] >> 2];
out[3] = BASE64_PADDING;
if (end - ptr >= 2)
{
out[1] = base64_enc_table[((ptr[0] & 0x03) << 4) + (ptr[1] >> 4)];
out[2] = base64_enc_table[(ptr[1] & 0x0f) << 2];
}
/* now deal with the tail end of things */
if (len != 0) {
dest[i++] = base64_table[current[0] >> 2];
if (len > 1) {
dest[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
dest[i++] = base64_table[(current[1] & 0x0f) << 2];
dest[i++] = base64_pad;
}
else {
dest[i++] = base64_table[(current[0] & 0x03) << 4];
dest[i++] = base64_pad;
dest[i++] = base64_pad;
}
else
{
out[1] = base64_enc_table[(ptr[0] & 0x03) << 4];
out[2] = BASE64_PADDING;
}
return i;
out += 4;
}
return out - dest;
}
/* as above, but backwards. :) */
uint
base64_decode(byte *dest, const byte *src, uint len)
uint base64_decode(byte *dest, const byte *src, uint len)
{
const byte *current = src;
uint ch;
uint i = 0, j = 0;
static byte reverse_table[256];
static uint table_built = 0;
if (table_built == 0) {
ucwlib_lock();
for(ch = 0; ch < 256; ch++) {
byte *chp = strchr(base64_table, ch);
if(chp) {
reverse_table[ch] = chp - base64_table;
} else {
reverse_table[ch] = 0xff;
}
}
table_built = 1;
ucwlib_unlock();
const byte *ptr = src;
const byte *end = src + len;
byte *out = dest;
while (1)
{
uint val, ch;
do
{
if (ptr == end || (ch = base64_dec_table[*ptr++]) == BASE64_DEC_PADDING)
goto end;
}
/* run through the whole string, converting as we go */
ch = 0;
while (len > 0) {
len--;
ch = *current++;
if (ch == base64_pad) break;
/* When Base64 gets POSTed, all pluses are interpreted as spaces.
This line changes them back. It's not exactly the Base64 spec,
but it is completely compatible with it (the spec says that
spaces are invalid). This will also save many people considerable
headache. - Turadg Aleahmad <turadg@wise.berkeley.edu>
*/
if (ch == ' ') ch = '+';
ch = reverse_table[ch];
if (ch == 0xff) continue;
switch(i % 4) {
case 0:
dest[j] = ch << 2;
break;
case 1:
dest[j++] |= ch >> 4;
dest[j] = (ch & 0x0f) << 4;
break;
case 2:
dest[j++] |= ch >>2;
dest[j] = (ch & 0x03) << 6;
break;
case 3:
dest[j++] |= ch;
break;
}
i++;
while (ch > BASE64_DEC_PADDING);
val = ch;
do
{
if (ptr == end || (ch = base64_dec_table[*ptr++]) == BASE64_DEC_PADDING)
goto end; // Broken base64 encoding, we only have 6 bits
}
while (ch > BASE64_DEC_PADDING);
val = (val << 6) | ch;
do
{
if (ptr == end || (ch = base64_dec_table[*ptr++]) == BASE64_DEC_PADDING)
{
out[0] = val >> 4;
out += 1;
goto end;
}
}
while (ch > BASE64_DEC_PADDING);
val = (val << 6) | ch;
do
{
if (ptr == end || (ch = base64_dec_table[*ptr++]) == BASE64_DEC_PADDING)
{
out[0] = val >> 10;
out[1] = val >> 2;
out += 2;
goto end;
}
}
return j;
while (ch > BASE64_DEC_PADDING);
val = (val << 6) | ch;
out[0] = val >> 16;
out[1] = val >> 8;
out[2] = val;
out += 3;
}
end:
return out - dest;
}
......@@ -2,6 +2,7 @@
* UCW Library -- Base 64 Encoding & Decoding
*
* (c) 2002, Robert Spalek <robert@ucw.cz>
* (c) 2017, Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
......@@ -10,6 +11,8 @@
#ifdef CONFIG_UCW_CLEAN_ABI
#define base64_decode ucw_base64_decode
#define base64_encode ucw_base64_encode
#define base64_enc_table ucw_base64_enc_table
#define base64_dec_table ucw_base64_dec_table
#endif
/**
......@@ -38,3 +41,22 @@ uint base64_decode(byte *dest, const byte *src, uint len);
#define BASE64_IN_CHUNK 3 /** Size of chunk on the un-encoded side. **/
#define BASE64_OUT_CHUNK 4 /** Size of chunk on the encoded side. **/
/*
* Lookup table for fast encoding.
* For each 6bit value contains corresponding base64 character.
*/
extern const byte base64_enc_table[65];
#define BASE64_PADDING '=' /* Padding character */
/*
* Lookup table for fast decoding:
* -- for valid base64 characters contains their 6bit values
* -- for BASE64_PADDING character contains special value BASE64_DEC_PADDING
* -- for all other characters contains BASE64_DEC_INVALID
*
* Note that BASE64_DEC_INVALID is greater than BASE64_DEC_PADDING
* (can be useful to know for some optimizations).
*/
extern const byte base64_dec_table[256];
#define BASE64_DEC_PADDING 0x40
#define BASE64_DEC_INVALID 0x80
......@@ -2,6 +2,7 @@
* UCW Library -- Circular Linked Lists
*
* (c) 2003--2010 Martin Mares <mj@ucw.cz>
* (c) 2017 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
......@@ -189,6 +190,24 @@ static inline void clist_insert_list_after(clist *what, cnode *after)
}
}
/**
* Merge two lists by inserting the list @what in front of all other nodes in a different list @l.
* The first list is then cleared.
**/
static inline void clist_add_list_head(clist *l, clist *what)
{
clist_insert_list_after(what, &l->head);
}
/**
* Merge two lists by inserting the list @what after all other nodes in a different list @l.
* The first list is then cleared.
**/
static inline void clist_add_list_tail(clist *l, clist *what)
{
clist_insert_list_after(what, l->head.prev);
}
/**
* Move all items from a source list to a destination list. The source list
* becomes empty, the original contents of the destination list are destroyed.
......
......@@ -34,6 +34,10 @@ static void crc32_update_by4(crc32_context *ctx, const byte *buf, uint len)
u32 crc = ctx->state;
u32 term1, term2, *buf32;
// Special case
if (len < 4)
goto small;
// Align start address to a multiple of 4 bytes
init_bytes = ((uintptr_t) buf) & 3;
if (init_bytes)
......@@ -60,6 +64,7 @@ static void crc32_update_by4(crc32_context *ctx, const byte *buf, uint len)
// Process remaining up to 7 bytes
buf = (byte *) buf32;
small:
while (len--)
crc = crc_tableil8_o32[(crc ^ *buf++) & 0x000000FF] ^ (crc >> 8);
......@@ -72,6 +77,10 @@ static void crc32_update_by8(crc32_context *ctx, const byte *buf, uint len)
u32 crc = ctx->state;
u32 term1, term2, *buf32;
// Special case
if (len < 8)
goto small;
// Align start address to a multiple of 8 bytes
init_bytes = ((uintptr_t) buf) & 7;
if (init_bytes)
......@@ -108,6 +117,7 @@ static void crc32_update_by8(crc32_context *ctx, const byte *buf, uint len)
// Process remaining up to 7 bytes
buf = (byte *) buf32;
small:
while (len--)
crc = crc_tableil8_o32[(crc ^ *buf++) & 0x000000FF] ^ (crc >> 8);
......
......@@ -2,8 +2,8 @@
# (c) 2005--2015 Martin Mares <mj@ucw.cz>
# Version of the whole package
Set("UCW_VERSION" => "6.5.1");
Set("UCW_VERSION_CODE" => 6005001);
Set("UCW_VERSION" => "6.5.8");
Set("UCW_VERSION_CODE" => 6005008);
# Name of libraries in packages (libucw$UCW_ABI_SUFFIX.so.0.0, etc.)
Set("UCW_ABI_SUFFIX" => "-6.5");
......
......@@ -82,8 +82,9 @@ ucw/fw-hex.h [[fwhex]]
Exceptions [[fbexc]]
--------------------
All standard back-ends and front-ends raise exceptions on errors. All such
exceptions live in the `ucw.fb` subtree. The following exceptions are defined:
All standard back-ends and front-ends raise exceptions on errors if the fastbuf
is tied to a resource pool by @fb_tie().
All such exceptions live in the `ucw.fb` subtree. The following exceptions are defined:
`ucw.fb.eof`:: Unexpected end of file (e.g., when the @FB_DIE_ON_EOF flag is set)
`ucw.fb.mmap`:: Memory mapping failed (e.g., the `mmap` syscall has failed)
......
......@@ -413,8 +413,7 @@ struct fastbuf *fbmem_clone_read(struct fastbuf *f); /** Given a writing fastbuf
* of the buffer temporarily. In this case, set @can_overwrite as described
* in <<internal,Internals>>. If you do not care, keep @can_overwrite zero.
*
* It is not possible to close this fastbuf. This implies that no tying to
* resources takes place.
* A @bclose() on this fastbuf is allowed and it does nothing.
*/
void fbbuf_init_read(struct fastbuf *f, byte *buffer, uint size, uint can_overwrite);
......@@ -426,8 +425,7 @@ void fbbuf_init_read(struct fastbuf *f, byte *buffer, uint size, uint can_overwr
* Data are written directly into the buffer, so it is not necessary to call @bflush()
* at any moment.
*
* It is not possible to close this fastbuf. This implies that no tying to
* resources takes place.
* A @bclose() on this fastbuf is allowed and it does nothing.
*/
void fbbuf_init_write(struct fastbuf *f, byte *buffer, uint size);
......@@ -473,8 +471,8 @@ struct fbpool { /** Structure for fastbufs & mempools. **/
};
/**
* Initialize a new `fbpool`. The structure is allocated by the caller,
* so @bclose() should not be called and no resource tying takes place.
* Initialize a new `fbpool`. The structure is allocated by the caller.
* Calling @bclose() is optional.
**/
void fbpool_init(struct fbpool *fb); /** Initialize a new mempool fastbuf. **/
/**
......@@ -625,7 +623,8 @@ int bconfig(struct fastbuf *f, uint type, int data); /** Configure a fastbuf. Re
/**
* Close and free fastbuf.
* Can not be used for fastbufs not returned from function (initialized in a parameter, for example the one from `fbbuf_init_read`).
* Some kinds of fastbufs are allocated by the caller (e.g., in @fbbuf_init_read());
* in such cases, @bclose() does not free any memory.
*/
void bclose(struct fastbuf *f);
void bthrow(struct fastbuf *f, const char *id, const char *fmt, ...) FORMAT_CHECK(printf,3,4) NONRET; /** Throw exception on a given fastbuf **/
......
......@@ -47,13 +47,15 @@ fbbuf_init_read(struct fastbuf *f, byte *buf, uint size, uint can_overwrite)
.pos = size,
.refill = fbbuf_refill,
.seek = fbbuf_seek,
.can_overwrite_buffer = can_overwrite };
.can_overwrite_buffer = can_overwrite
};
}
static void
fbbuf_spout(struct fastbuf *f)
{
bthrow(f, "write", "fbbuf: buffer overflow on write");
if (f->bptr >= f->bufend)
bthrow(f, "write", "fbbuf: buffer overflow on write");
}
void
......
......@@ -90,7 +90,7 @@ bopen_fd_internal(int fd, struct fb_params *params, uint mode, const char *name)
params->buffer_size ? : fbpar_def.buffer_size,
params->read_ahead ? : fbpar_def.read_ahead,
params->write_back ? : fbpar_def.write_back);
if (!~mode && !fbdir_cheat && ((int)(mode = fcntl(fd, F_GETFL)) < 0 || fcntl(fd, F_SETFL, mode | O_DIRECT)) < 0)
if (!~mode && !fbdir_cheat && ((int)(mode = fcntl(fd, F_GETFL)) < 0 || fcntl(fd, F_SETFL, mode | O_DIRECT) < 0))
msg(L_WARN, "Cannot set O_DIRECT on fd %d: %m", fd);
return fb;
#endif
......
......@@ -2,6 +2,7 @@
* UCW Library -- Fast Buffered I/O on Sockets with Timeouts
*
* (c) 2008 Martin Mares <mj@ucw.cz>
* (c) 2017 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
......@@ -73,6 +74,7 @@ fbs_spout(struct fastbuf *f)
int l = f->bptr - f->bstop;
f->bptr = f->bstop;
f->pos += l;
char *buf = f->bstop;
while (l)
......
<
......@@ -2,7 +2,7 @@
* UCW Library -- Fast Buffered I/O: Strings
*
* (c) 1997--2006 Martin Mares <mj@ucw.cz>
* (c) 2006 Pavel Charvat <pchar@ucw.cz>
* (c) 2006--2018 Pavel Charvat <pchar@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
......@@ -135,17 +135,11 @@ bgets_mp(struct fastbuf *f, struct mempool *mp)
uint src_len = bdirect_read_prepare(f, &src);
if (!src_len)
return NULL;
#define BLOCK_SIZE (4096 - sizeof(void *))
struct block {
struct block *prev;
byte data[BLOCK_SIZE];
} *blocks = NULL;
uint sum = 0, buf_len = BLOCK_SIZE, cnt;
struct block first_block, *new_block = &first_block;
byte *buf = new_block->data;
byte *buf = mp_start_noalign(mp, 1);
size_t buf_len = mp_avail(mp);
do
{