summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <mats@romeo.(none)>2006-10-06 15:31:05 +0200
committerunknown <mats@romeo.(none)>2006-10-06 15:31:05 +0200
commit5e81d1301e375fc903466df025d1f9f22a3b0994 (patch)
treebacce208c70954e5ab55bde5d8e31391840ead28 /mysys
parentcc4435ad8fb8037f8e6353655d2342ec25fbd207 (diff)
parentd8be3113351929f12e4277f4306a1428a280d970 (diff)
downloadmariadb-git-5e81d1301e375fc903466df025d1f9f22a3b0994.tar.gz
Merge romeo.(none):/home/bkroot/mysql-5.1-new-rpl
into romeo.(none):/home/bk/b19459-mysql-5.1-new client/mysqlbinlog.cc: Auto merged include/my_sys.h: Auto merged mysys/base64.c: Auto merged sql/log_event.cc: Auto merged sql/log_event.h: Auto merged storage/ndb/src/mgmapi/mgmapi.cpp: Auto merged sql/share/errmsg.txt: SCCS merged
Diffstat (limited to 'mysys')
-rw-r--r--mysys/base64.c65
-rw-r--r--mysys/mf_iocache2.c47
2 files changed, 94 insertions, 18 deletions
diff --git a/mysys/base64.c b/mysys/base64.c
index fb51bdb3a60..363aa2cc739 100644
--- a/mysys/base64.c
+++ b/mysys/base64.c
@@ -125,44 +125,69 @@ pos(unsigned char c)
/*
Decode a base64 string
- Note: We require that dst is pre-allocated to correct size.
- See base64_needed_decoded_length().
-
- RETURN Number of bytes produced in dst or -1 in case of failure
+ SYNOPSIS
+ base64_decode()
+ src Pointer to base64-encoded string
+ len Length of string at 'src'
+ dst Pointer to location where decoded data will be stored
+ end_ptr Pointer to variable that will refer to the character
+ after the end of the encoded data that were decoded. Can
+ be NULL.
+
+ DESCRIPTION
+
+ The base64-encoded data in the range ['src','*end_ptr') will be
+ decoded and stored starting at 'dst'. The decoding will stop
+ after 'len' characters have been read from 'src', or when padding
+ occurs in the base64-encoded data. In either case: if 'end_ptr' is
+ non-null, '*end_ptr' will be set to point to the character after
+ the last read character, even in the presence of error.
+
+ NOTE
+ We require that 'dst' is pre-allocated to correct size.
+
+ SEE ALSO
+ base64_needed_decoded_length().
+
+ RETURN VALUE
+ Number of bytes written at 'dst' or -1 in case of failure
*/
int
-base64_decode(const char *src, size_t size, void *dst)
+base64_decode(const char *const src_base, size_t const len,
+ void *dst, const char **end_ptr)
{
char b[3];
size_t i= 0;
char *dst_base= (char *)dst;
+ char const *src= src_base;
char *d= dst_base;
size_t j;
- while (i < size)
+ while (i < len)
{
unsigned c= 0;
size_t mark= 0;
- SKIP_SPACE(src, i, size);
+ SKIP_SPACE(src, i, len);
c += pos(*src++);
c <<= 6;
i++;
- SKIP_SPACE(src, i, size);
+ SKIP_SPACE(src, i, len);
c += pos(*src++);
c <<= 6;
i++;
- SKIP_SPACE(src, i, size);
+ SKIP_SPACE(src, i, len);
- if (* src != '=')
+ if (*src != '=')
c += pos(*src++);
else
{
- i= size;
+ src += 2; /* There should be two bytes padding */
+ i= len;
mark= 2;
c <<= 6;
goto end;
@@ -170,13 +195,14 @@ base64_decode(const char *src, size_t size, void *dst)
c <<= 6;
i++;
- SKIP_SPACE(src, i, size);
+ SKIP_SPACE(src, i, len);
if (*src != '=')
c += pos(*src++);
else
{
- i= size;
+ src += 1; /* There should be one byte padding */
+ i= len;
mark= 1;
goto end;
}
@@ -191,11 +217,14 @@ base64_decode(const char *src, size_t size, void *dst)
*d++= b[j];
}
- if (i != size)
- {
- return -1;
- }
- return d - dst_base;
+ if (end_ptr != NULL)
+ *end_ptr= src;
+
+ /*
+ The variable 'i' is set to 'len' when padding has been read, so it
+ does not actually reflect the number of bytes read from 'src'.
+ */
+ return i != len ? -1 : d - dst_base;
}
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index f1ea21c2a47..57a06e263a6 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -24,6 +24,53 @@
#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.
+
+ 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 occured
+*/
+int
+my_b_copy_to_file(IO_CACHE *cache, FILE *file)
+{
+ byte buf[IO_SIZE];
+ 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);
+ uint bytes_in_cache= my_b_bytes_in_cache(cache);
+ while (bytes_in_cache > 0) {
+ uint const read_bytes= min(bytes_in_cache, sizeof(buf));
+ DBUG_PRINT("debug", ("Remaining %u bytes - Reading %u bytes",
+ bytes_in_cache, read_bytes));
+ if (my_b_read(cache, buf, read_bytes))
+ DBUG_RETURN(1);
+ if (my_fwrite(file, buf, read_bytes, MYF(MY_WME | MY_NABP)) == (uint) -1)
+ DBUG_RETURN(1);
+ bytes_in_cache -= read_bytes;
+ }
+ DBUG_RETURN(0);
+}
+
my_off_t my_b_append_tell(IO_CACHE* info)
{
/*