|
1 | | -/* Copyright (C) 2003-2013 Runtime Revolution Ltd. |
2 | | - |
3 | | - This file is part of LiveCode. |
4 | | - |
5 | | - LiveCode is free software; you can redistribute it and/or modify it under |
6 | | - the terms of the GNU General Public License v3 as published by the Free |
7 | | - Software Foundation. |
8 | | - |
9 | | - LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
10 | | - WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | | - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | | - for more details. |
13 | | - |
14 | | - You should have received a copy of the GNU General Public License |
15 | | - along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 1 | +/* -*-c++-*- |
| 2 | +Copyright (C) 2015 Runtime Revolution Ltd. |
| 3 | +
|
| 4 | +This file is part of LiveCode. |
| 5 | +
|
| 6 | +LiveCode is free software; you can redistribute it and/or modify it under |
| 7 | +the terms of the GNU General Public License v3 as published by the Free |
| 8 | +Software Foundation. |
| 9 | +
|
| 10 | +LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | +for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU General Public License |
| 16 | +along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
16 | 17 |
|
17 | 18 | #include <foundation.h> |
18 | 19 | #include <foundation-auto.h> |
|
21 | 22 |
|
22 | 23 | //////////////////////////////////////////////////////////////////////////////// |
23 | 24 |
|
24 | | -extern "C" MC_DLLEXPORT MCStreamRef MCFileExecOpenFileForRead(MCStringRef p_filename) |
25 | | -{ |
26 | | - MCStreamRef t_stream; |
27 | | - if (!MCFileCreateStreamForFile(p_filename, kMCOpenFileModeRead, t_stream)) |
28 | | - return nil; |
29 | | - |
30 | | - return t_stream; |
31 | | -} |
32 | | - |
33 | | -extern "C" MC_DLLEXPORT MCStreamRef MCFileExecOpenFileForWrite(bool p_create, MCStringRef p_filename, MCStreamRef& r_stream) |
34 | | -{ |
35 | | - MCStreamRef t_stream; |
36 | | - if (!MCFileCreateStreamForFile(p_filename, p_create ? kMCOpenFileModeCreate : kMCOpenFileModeWrite, t_stream)) |
37 | | - return nil; |
38 | | - |
39 | | - return t_stream; |
40 | | -} |
41 | | - |
42 | | -extern "C" MC_DLLEXPORT MCStreamRef MCFileExecOpenFileForUpdate(bool p_create, MCStringRef p_filename, MCStreamRef& r_stream) |
| 25 | +extern "C" MC_DLLEXPORT void |
| 26 | +MCFileExecGetContents (MCStringRef p_path, MCDataRef & r_data) |
43 | 27 | { |
44 | | - MCStreamRef t_stream; |
45 | | - if (!MCFileCreateStreamForFile(p_filename, p_create ? kMCOpenFileModeCreate : kMCOpenFileModeUpdate, t_stream)) |
46 | | - return nil; |
47 | | - |
48 | | - return t_stream; |
| 28 | + /* UNCHECKED */ MCFileGetContents (p_path, r_data); |
49 | 29 | } |
50 | 30 |
|
51 | | -extern "C" MC_DLLEXPORT MCDataRef MCFileExecReadFromStream(uindex_t p_amount, MCStreamRef p_stream) |
| 31 | +extern "C" MC_DLLEXPORT void |
| 32 | +MCFileExecSetContents (MCDataRef p_contents, MCStringRef p_path) |
52 | 33 | { |
53 | | - if (!MCStreamIsReadable(p_stream)) |
54 | | - { |
55 | | - MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", MCSTR("stream is not readable"), nil); |
56 | | - return MCValueRetain(kMCEmptyData); |
57 | | - } |
58 | | - |
59 | | - byte_t t_buffer[p_amount]; |
60 | | - |
61 | | - if (!MCStreamRead(p_stream, t_buffer, p_amount)) |
62 | | - { |
63 | | - MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", MCSTR("could not read from stream"), nil); |
64 | | - return MCValueRetain(kMCEmptyData); |
65 | | - } |
66 | | - |
67 | | - MCDataRef t_data; |
68 | | - if (!MCDataCreateWithBytes(t_buffer, p_amount, t_data)) |
69 | | - return MCValueRetain(kMCEmptyData); |
70 | | - |
71 | | - return t_data; |
| 34 | + /* UNCHECKED */ MCFileSetContents (p_path, p_contents); |
72 | 35 | } |
73 | | - |
74 | | - |
0 commit comments