629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
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
|
|
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 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
21 |
#include <drizzled/function/str/strfunc.h> |
22 |
#include <drizzled/function/str/load_file.h> |
|
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
23 |
#include <drizzled/error.h> |
24 |
#include <drizzled/data_home.h> |
|
25 |
#include <drizzled/session.h> |
|
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
26 |
#include "drizzled/internal/my_sys.h" |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
27 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
28 |
#include <fcntl.h> |
29 |
#include <sys/stat.h> |
|
30 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
31 |
namespace drizzled |
32 |
{
|
|
33 |
||
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
34 |
String *Item_load_file::val_str(String *str) |
35 |
{
|
|
36 |
assert(fixed == 1); |
|
37 |
String *file_name; |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
38 |
int file; |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
39 |
struct stat stat_info; |
40 |
char path[FN_REFLEN]; |
|
41 |
||
42 |
if (!(file_name= args[0]->val_str(str))) |
|
43 |
goto err; |
|
44 |
||
1300.5.3
by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're |
45 |
(void) internal::fn_format(path, file_name->c_ptr(), data_home_real, "", |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
46 |
MY_RELATIVE_PATH | MY_UNPACK_FILENAME); |
47 |
||
48 |
/* Read only allowed from within dir specified by secure_file_priv */
|
|
49 |
if (opt_secure_file_priv && |
|
50 |
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv))) |
|
51 |
goto err; |
|
52 |
||
53 |
if (stat(path, &stat_info)) |
|
54 |
goto err; |
|
55 |
||
56 |
if (!(stat_info.st_mode & S_IROTH)) |
|
57 |
{
|
|
58 |
/* my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr()); */
|
|
59 |
goto err; |
|
60 |
}
|
|
1633.4.6
by Brian Aker
More current_session issues. |
61 |
if (stat_info.st_size > (long) session.variables.max_allowed_packet) |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
62 |
{
|
1633.4.6
by Brian Aker
More current_session issues. |
63 |
push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN, |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
64 |
ER_WARN_ALLOWED_PACKET_OVERFLOWED, |
65 |
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), |
|
1633.4.6
by Brian Aker
More current_session issues. |
66 |
func_name(), session.variables.max_allowed_packet); |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
67 |
goto err; |
68 |
}
|
|
892.2.2
by Monty Taylor
More solaris warnings. |
69 |
if (tmp_value.alloc((size_t)stat_info.st_size)) |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
70 |
goto err; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
71 |
if ((file = internal::my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0) |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
72 |
goto err; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
73 |
if (internal::my_read(file, (unsigned char*) tmp_value.ptr(), (size_t)stat_info.st_size, MYF(MY_NABP))) |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
74 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
75 |
internal::my_close(file, MYF(0)); |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
76 |
goto err; |
77 |
}
|
|
892.2.2
by Monty Taylor
More solaris warnings. |
78 |
tmp_value.length((size_t)stat_info.st_size); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
79 |
internal::my_close(file, MYF(0)); |
629.6.5
by Lee
clean up remaining functions in strfunc, move to functions/str directory |
80 |
null_value = 0; |
81 |
return(&tmp_value); |
|
82 |
||
83 |
err: |
|
84 |
null_value = 1; |
|
85 |
return(0); |
|
86 |
}
|
|
87 |
||
88 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
89 |
} /* namespace drizzled */ |