~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/local_infile.c

  • Committer: Monty Taylor
  • Date: 2008-09-16 06:40:44 UTC
  • mfrom: (390.1.7 client-split)
  • Revision ID: monty@inaugust.com-20080916064044-vbgmaf36cvm8jufx
Merged in from client-split.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 DRIZZLE AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation.
6
 
 
7
 
   There are special exceptions to the terms and conditions of the GPL as it
8
 
   is applied to this software. View the full text of the exception in file
9
 
   EXCEPTIONS-CLIENT in the directory of this software distribution.
10
 
 
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software
18
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
 
 
20
 
 
21
 
#include <drizzled/global.h>
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
 
22
22
#include "libdrizzle.h"
 
23
#include "libdrizzle_priv.h"
23
24
#include "errmsg.h"
24
25
#include <sys/stat.h>
25
26
#include <signal.h>
26
27
#include <time.h>
 
28
#include <fcntl.h>
 
29
#include <stdio.h>
 
30
 
27
31
#ifdef   HAVE_PWD_H
28
32
#include <pwd.h>
29
33
#endif
51
55
 
52
56
#include <sql_common.h>
53
57
#include "local_infile.h"
54
 
 
55
 
 
 
58
#include <libdrizzle/gettext.h>
 
59
 
 
60
#define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
56
61
 
57
62
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
58
63
{
77
82
  /* copy filename into local memory and allocate read buffer */
78
83
  if (!(buf=malloc(packet_length)))
79
84
  {
80
 
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
 
85
    drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
81
86
    return(1);
82
87
  }
83
88
 
85
90
  if ((*options->local_infile_init)(&li_ptr, net_filename,
86
91
    options->local_infile_userdata))
87
92
  {
88
 
    VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */
 
93
    (void)my_net_write(net,(const unsigned char*) "",0); /* Server needs one packet */
89
94
    net_flush(net);
90
 
    strcpy(net->sqlstate, unknown_sqlstate);
 
95
    strcpy(net->sqlstate, sqlstate_get_unknown());
91
96
    net->last_errno=
92
97
      (*options->local_infile_error)(li_ptr,
93
98
                                     net->last_error,
100
105
    (*options->local_infile_read)(li_ptr, buf,
101
106
          packet_length)) > 0)
102
107
  {
103
 
    if (my_net_write(net, (uchar*) buf, readcount))
 
108
    if (my_net_write(net, (unsigned char*) buf, readcount))
104
109
    {
105
110
      goto err;
106
111
    }
107
112
  }
108
113
 
109
114
  /* Send empty packet to mark end of file */
110
 
  if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
 
115
  if (my_net_write(net, (const unsigned char*) "", 0) || net_flush(net))
111
116
  {
112
 
    set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
 
117
    drizzle_set_error(drizzle, CR_SERVER_LOST, sqlstate_get_unknown());
113
118
    goto err;
114
119
  }
115
120
 
209
214
  int count;
210
215
  default_local_infile_data*data = (default_local_infile_data *) ptr;
211
216
 
212
 
  if ((count= (int) read(data->fd, (uchar *) buf, buf_len)) < 0)
 
217
  if ((count= (int) read(data->fd, (unsigned char *) buf, buf_len)) < 0)
213
218
  {
214
219
    data->error_num= 2; /* the errmsg for not entire file read */
215
220
    snprintf(data->error_msg, sizeof(data->error_msg)-1,