| 1 |
/* gtkmm example Copyright (C) 2002 gtkmm development team |
| 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; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <giomm.h> |
| 18 |
#include <iostream> |
| 19 |
#include <cstring> |
| 20 |
|
| 21 |
|
| 22 |
int main(int /* argc */, char** /* argv */) |
| 23 |
{ |
| 24 |
Gio::init(); |
| 25 |
|
| 26 |
try |
| 27 |
{ |
| 28 |
auto file = Gio::File::create_for_path("/etc/fstab"); |
| 29 |
if(!file) |
| 30 |
std::cerr << "Gio::File::create_for_path() returned an empty RefPtr." << std::endl; |
| 31 |
|
| 32 |
auto stream = file->read(); |
| 33 |
if(!stream) |
| 34 |
std::cerr << "Gio::File::read() returned an empty RefPtr." << std::endl; |
| 35 |
|
| 36 |
gchar buffer[1000]; //TODO: This is unpleasant. |
| 37 |
memset(buffer, 0, 1000); |
| 38 |
const gsize bytes_read = stream->read(buffer, 1000); |
| 39 |
|
| 40 |
if(bytes_read) |
| 41 |
std::cout << "File contents read: " << buffer << std::endl; |
| 42 |
else |
| 43 |
std::cerr << "Gio::InputStream::read() read 0 bytes." << std::endl; |
| 44 |
|
| 45 |
} |
| 46 |
catch(const Glib::Error& ex) |
| 47 |
{ |
| 48 |
std::cerr << "Exception caught: " << ex.what() << std::endl; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
return 0; |
| 53 |
} |
| 54 |
|