45 #include <freetds/tds.h>
46 #include <freetds/iconv.h>
47 #include <freetds/stream.h>
50 #if ENABLE_EXTRA_CHECKS
51 # define TEMP_INIT(s) const size_t temp_size = s; char* temp = tds_new(char, temp_size)
52 # define TEMP_FREE free(temp);
53 # define TEMP_SIZE temp_size
55 # define TEMP_INIT(s) char temp[s]
57 # define TEMP_SIZE sizeof(temp)
88 memset(suppress, 0,
sizeof(char_conv->
suppress));
89 for (ib = temp; ostream->
buf_len; ib = temp + bufleft) {
98 len = istream->
read(istream, (
char*) ib, TEMP_SIZE - bufleft);
101 if (
len == 0 && bufleft == 0) {
116 ol =
tds_iconv(
tds, char_conv, direction, (
const char **) &ib, &bufleft, &ob, &ol);
124 if ((
size_t) -1 == ol) {
126 if (conv_errno == E2BIG && ostream->
buf_len && bufleft &&
len)
128 if (conv_errno !=
EILSEQ) {
130 "Gave up converting %u bytes due to error %d.\n",
131 (
unsigned int) bufleft, errno);
138 if (conv_errno == EINVAL &&
tds)
140 if (conv_errno == E2BIG &&
tds)
220 assert(len <= stream->buf_len);
246 #if TDS_ADDITIONAL_SPACE < 4
273 memcpy(ptr, s->
buffer, cp);
289 stream->
buffer = (
const char *) ptr;
332 wanted = s->
size + (s->
size < 4096 ? 1024 : s->
size / 8u);
356 const size_t initial_size = 1024;
360 if (allocated < initial_size) {
363 allocated = initial_size;
#define TDS_ADDITIONAL_SPACE
TDSRET tds_copy_stream(TDSSOCKET *tds, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream to another \tds.
TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM *stream, void **ptr, size_t allocated)
Initialize a dynamic output stream.
TDSRET tds_convert_stream(TDSSOCKET *tds, TDSICONV *char_conv, TDS_ICONV_DIRECTION direction, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream converting characters \tds.
void tds_staticout_stream_init(TDSSTATICOUTSTREAM *stream, void *ptr, size_t len)
Initialize an output stream for write into a static allocated buffer.
void tds_dataout_stream_init(TDSDATAOUTSTREAM *stream, TDSSOCKET *tds)
Initialize a data output stream.
void tds_staticin_stream_init(TDSSTATICINSTREAM *stream, const void *ptr, size_t len)
Initialize an input stream for read from a static allocated buffer.
void tds_datain_stream_init(TDSDATAINSTREAM *stream, TDSSOCKET *tds, size_t wire_size)
Initialize a data input stream.
static int tds_datain_stream_read(TDSINSTREAM *stream, void *ptr, size_t len)
Reads data from network for input stream.
static int tds_staticout_stream_write(TDSOUTSTREAM *stream, size_t len)
Writes data to a static allocated buffer.
static int tds_staticin_stream_read(TDSINSTREAM *stream, void *ptr, size_t len)
Reads data from a static allocated buffer.
static int tds_dynamic_stream_write(TDSOUTSTREAM *stream, size_t len)
Writes data to a dynamic allocated buffer.
static int tds_dataout_stream_write(TDSOUTSTREAM *stream, size_t len)
Writes data to network for output stream.
input stream to read data from tds protocol
size_t wire_size
bytes still to read
output stream to write data to tds protocol
output stream to write data to a dynamic buffer
void ** buf
where is stored the pointer
size_t size
size of data inside buffer
size_t allocated
currently allocated buffer
define a stream of data used for output
int(* write)(struct tds_output_stream *stream, size_t len)
write len bytes from buffer, return <0 if error or len
char * buffer
write buffer.
Information for a server connection.
unsigned out_pos
current position in out_buf
unsigned char * out_buf
Output buffer.
unsigned int out_buf_max
Maximum size of packet pointed by out_buf.
input stream to read data from a static buffer
output stream to write data to a static buffer.
TDS_ERRNO_MESSAGE_FLAGS suppress