1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
21
#include <drizzled/function/str/strfunc.h>
22
#include <drizzled/function/str/load_file.h>
23
#include <drizzled/error.h>
24
#include <drizzled/data_home.h>
25
#include <drizzled/session.h>
26
#include "drizzled/internal/my_sys.h"
31
String *Item_load_file::val_str(String *str)
36
struct stat stat_info;
39
if (!(file_name= args[0]->val_str(str)))
42
(void) fn_format(path, file_name->c_ptr(), drizzle_real_data_home, "",
43
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
45
/* Read only allowed from within dir specified by secure_file_priv */
46
if (opt_secure_file_priv &&
47
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
50
if (stat(path, &stat_info))
53
if (!(stat_info.st_mode & S_IROTH))
55
/* my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr()); */
58
if (stat_info.st_size > (long) current_session->variables.max_allowed_packet)
60
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
61
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
62
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
63
func_name(), current_session->variables.max_allowed_packet);
66
if (tmp_value.alloc((size_t)stat_info.st_size))
68
if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0)
70
if (my_read(file, (unsigned char*) tmp_value.ptr(), (size_t)stat_info.st_size, MYF(MY_NABP)))
72
my_close(file, MYF(0));
75
tmp_value.length((size_t)stat_info.st_size);
76
my_close(file, MYF(0));