Replaced std::auto_ptr<> with std::unique_ptr<>
[supertux.git] / external / tinygettext / tinygettext / unix_file_system.cpp
1 //  tinygettext - A gettext replacement that works directly on .po files
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 2
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 #include "unix_file_system.hpp"
19
20 #include <sys/types.h>
21 #include <fstream>
22 #include <dirent.h>
23 #include <stdlib.h>
24 #include <dirent.h>
25 #include <string.h>
26
27 namespace tinygettext {
28
29 UnixFileSystem::UnixFileSystem()
30 {
31 }
32
33 std::vector<std::string>
34 UnixFileSystem::open_directory(const std::string& pathname)
35 {
36   DIR* dir = opendir(pathname.c_str());
37   if (!dir)
38   {
39     // FIXME: error handling
40     return std::vector<std::string>();
41   }
42   else
43   {
44     std::vector<std::string> files;
45
46     struct dirent* dp;
47     while((dp = readdir(dir)) != 0)
48     {
49       files.push_back(dp->d_name);
50     }
51     closedir(dir);
52
53     return files;
54   }
55 }
56   
57 std::auto_ptr<std::istream>
58 UnixFileSystem::open_file(const std::string& filename)
59 {
60   return std::auto_ptr<std::istream>(new std::ifstream(filename.c_str()));
61 }
62
63 } // namespace tinygettext
64
65 /* EOF */