summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-02-02 11:40:02 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-02-02 11:40:02 +0200
commit081fd8bfa280635a7e699a17b035032460cb5160 (patch)
treed5ea2c0f31aafe566d749f6dd60f5bc631f60862 /mysys
parent09cea8703f3ec4e4f9e23855a339c9e3d5e84d3b (diff)
parenta193c5720ea461ce82390af3fe9c292581242223 (diff)
downloadmariadb-git-081fd8bfa280635a7e699a17b035032460cb5160.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'mysys')
-rw-r--r--mysys/mf_iocache2.c61
-rw-r--r--mysys/my_malloc.c1
2 files changed, 34 insertions, 28 deletions
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index fa3b6e672d7..f3877331664 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -23,51 +23,56 @@
#include <stdarg.h>
#include <m_ctype.h>
-/*
- Copy contents of an IO_CACHE to a file.
-
- SYNOPSIS
- my_b_copy_to_file()
- cache IO_CACHE to copy from
- file File to copy to
-
- DESCRIPTION
- Copy the contents of the cache to the file. The cache will be
- re-inited to a read cache and will read from the beginning of the
- cache.
-
- If a failure to write fully occurs, the cache is only copied
- partially.
+/**
+ Copy the cache to the file. Copying can be constrained to @c count
+ number of bytes when the parameter is less than SIZE_T_MAX. The
+ cache will be optionally re-inited to a read cache and will read
+ from the beginning of the cache. If a failure to write fully
+ occurs, the cache is only copied partially.
TODO
- Make this function solid by handling partial reads from the cache
- in a correct manner: it should be atomic.
-
- RETURN VALUE
- 0 All OK
- 1 An error occurred
+ Make this function solid by handling partial reads from the cache
+ in a correct manner: it should be atomic.
+
+ @param cache IO_CACHE to copy from
+ @param file File to copy to
+ @param count the copied size or the max of the type
+ when the whole cache is to be copied.
+ @return
+ 0 All OK
+ 1 An error occurred
*/
int
-my_b_copy_to_file(IO_CACHE *cache, FILE *file)
+my_b_copy_to_file(IO_CACHE *cache, FILE *file,
+ size_t count)
{
- size_t bytes_in_cache;
+ size_t curr_write, bytes_in_cache;
DBUG_ENTER("my_b_copy_to_file");
- /* Reinit the cache to read from the beginning of the cache */
- if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
- DBUG_RETURN(1);
bytes_in_cache= my_b_bytes_in_cache(cache);
do
{
- if (my_fwrite(file, cache->read_pos, bytes_in_cache,
+ curr_write= MY_MIN(bytes_in_cache, count);
+ if (my_fwrite(file, cache->read_pos, curr_write,
MYF(MY_WME | MY_NABP)) == (size_t) -1)
DBUG_RETURN(1);
- } while ((bytes_in_cache= my_b_fill(cache)));
+
+ cache->read_pos += curr_write;
+ count -= curr_write;
+ } while (count && (bytes_in_cache= my_b_fill(cache)));
if(cache->error == -1)
DBUG_RETURN(1);
DBUG_RETURN(0);
}
+int my_b_copy_all_to_file(IO_CACHE *cache, FILE *file)
+{
+ DBUG_ENTER("my_b_copy_all_to_file");
+ /* Reinit the cache to read from the beginning of the cache */
+ if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
+ DBUG_RETURN(1);
+ DBUG_RETURN(my_b_copy_to_file(cache, file, SIZE_T_MAX));
+}
my_off_t my_b_append_tell(IO_CACHE* info)
{
diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c
index 719c13a040e..99a15e6f432 100644
--- a/mysys/my_malloc.c
+++ b/mysys/my_malloc.c
@@ -117,6 +117,7 @@ void *my_malloc(size_t size, myf my_flags)
MY_TEST(my_flags & MY_THREAD_SPECIFIC));
update_malloc_size(size + MALLOC_PREFIX_SIZE,
MY_TEST(my_flags & MY_THREAD_SPECIFIC));
+ TRASH_ALLOC(point, size);
DBUG_EXECUTE_IF("simulate_out_of_memory",
{
/* my_free() handles memory accounting */