~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/local_infile.c

  • Committer: Brian Aker
  • Date: 2008-08-10 16:57:26 UTC
  • Revision ID: brian@tangent.org-20080810165726-mc1660l11a5vkv69
libdrizzle has ulong removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include "libdrizzle.h"
23
 
#include "libdrizzle_priv.h"
 
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>
 
22
#include <mysys/my_sys.h>
 
23
#include "my_time.h"
 
24
#include <mysys/mysys_err.h>
 
25
#include <mystrings/m_string.h>
 
26
#include <mystrings/m_ctype.h>
 
27
#include "drizzle.h"
24
28
#include "errmsg.h"
 
29
#include <vio/violite.h>
25
30
#include <sys/stat.h>
26
31
#include <signal.h>
27
32
#include <time.h>
28
 
#include <fcntl.h>
29
 
#include <stdio.h>
30
 
 
31
33
#ifdef   HAVE_PWD_H
32
34
#include <pwd.h>
33
35
#endif
54
56
#endif
55
57
 
56
58
#include <sql_common.h>
57
 
#include "local_infile.h"
58
 
#include <libdrizzle/gettext.h>
 
59
#include "client_settings.h"
59
60
 
60
 
#define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
61
61
 
62
62
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
63
63
{
64
64
  bool result= true;
65
 
  uint32_t packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
 
65
  uint packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
66
66
  NET *net= &drizzle->net;
67
67
  int readcount;
68
68
  void *li_ptr;          /* pass state to local_infile functions */
82
82
  /* copy filename into local memory and allocate read buffer */
83
83
  if (!(buf=malloc(packet_length)))
84
84
  {
85
 
    drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
 
85
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
86
86
    return(1);
87
87
  }
88
88
 
90
90
  if ((*options->local_infile_init)(&li_ptr, net_filename,
91
91
    options->local_infile_userdata))
92
92
  {
93
 
    (void)my_net_write(net,(const unsigned char*) "",0); /* Server needs one packet */
 
93
    VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */
94
94
    net_flush(net);
95
 
    strcpy(net->sqlstate, sqlstate_get_unknown());
 
95
    strcpy(net->sqlstate, unknown_sqlstate);
96
96
    net->last_errno=
97
97
      (*options->local_infile_error)(li_ptr,
98
98
                                     net->last_error,
105
105
    (*options->local_infile_read)(li_ptr, buf,
106
106
          packet_length)) > 0)
107
107
  {
108
 
    if (my_net_write(net, (unsigned char*) buf, readcount))
 
108
    if (my_net_write(net, (uchar*) buf, readcount))
109
109
    {
110
110
      goto err;
111
111
    }
112
112
  }
113
113
 
114
114
  /* Send empty packet to mark end of file */
115
 
  if (my_net_write(net, (const unsigned char*) "", 0) || net_flush(net))
 
115
  if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
116
116
  {
117
 
    drizzle_set_error(drizzle, CR_SERVER_LOST, sqlstate_get_unknown());
 
117
    set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
118
118
    goto err;
119
119
  }
120
120
 
183
183
  data->error_num=    0;
184
184
  data->filename= filename;
185
185
 
186
 
  if ((data->fd = open(tmp_name, O_RDONLY)) < 0)
 
186
  fn_format(tmp_name, filename, "", "", MY_UNPACK_FILENAME);
 
187
  if ((data->fd = my_open(tmp_name, O_RDONLY, MYF(0))) < 0)
187
188
  {
188
 
    data->error_num= errno;
 
189
    data->error_num= my_errno;
189
190
    snprintf(data->error_msg, sizeof(data->error_msg)-1,
190
 
             _("File '%s' not found (Errcode: %d)"), tmp_name, data->error_num);
 
191
             EE(EE_FILENOTFOUND), tmp_name, data->error_num);
191
192
    return 1;
192
193
  }
193
194
  return 0; /* ok */
209
210
    < 0    Error
210
211
*/
211
212
 
212
 
static int default_local_infile_read(void *ptr, char *buf, uint32_t buf_len)
 
213
static int default_local_infile_read(void *ptr, char *buf, uint buf_len)
213
214
{
214
215
  int count;
215
216
  default_local_infile_data*data = (default_local_infile_data *) ptr;
216
217
 
217
 
  if ((count= (int) read(data->fd, (unsigned char *) buf, buf_len)) < 0)
 
218
  if ((count= (int) my_read(data->fd, (uchar *) buf, buf_len, MYF(0))) < 0)
218
219
  {
219
 
    data->error_num= 2; /* the errmsg for not entire file read */
 
220
    data->error_num= EE_READ; /* the errmsg for not entire file read */
220
221
    snprintf(data->error_msg, sizeof(data->error_msg)-1,
221
 
             _("Error reading file '%s' (Errcode: %d)"),
222
 
             data->filename, errno);
 
222
             EE(EE_READ),
 
223
             data->filename, my_errno);
223
224
  }
224
225
  return count;
225
226
}
242
243
  if (data)          /* If not error on open */
243
244
  {
244
245
    if (data->fd >= 0)
245
 
      close(data->fd);
 
246
      my_close(data->fd, MYF(MY_WME));
246
247
    free(ptr);
247
248
  }
248
249
}
263
264
*/
264
265
 
265
266
static int
266
 
default_local_infile_error(void *ptr, char *error_msg, uint32_t error_msg_len)
 
267
default_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
267
268
{
268
269
  default_local_infile_data *data = (default_local_infile_data *) ptr;
269
270
  if (data)          /* If not error on open */
281
282
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
282
283
                               int (*local_infile_init)(void **, const char *,
283
284
                               void *),
284
 
                               int (*local_infile_read)(void *, char *, uint32_t),
 
285
                               int (*local_infile_read)(void *, char *, uint),
285
286
                               void (*local_infile_end)(void *),
286
 
                               int (*local_infile_error)(void *, char *, uint32_t),
 
287
                               int (*local_infile_error)(void *, char *, uint),
287
288
                               void *userdata)
288
289
{
289
290
  drizzle->options.local_infile_init=  local_infile_init;