aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llfile.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llfile.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcommon/llfile.h')
-rw-r--r--linden/indra/llcommon/llfile.h170
1 files changed, 170 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llfile.h b/linden/indra/llcommon/llfile.h
new file mode 100644
index 0000000..554308f
--- /dev/null
+++ b/linden/indra/llcommon/llfile.h
@@ -0,0 +1,170 @@
1/**
2 * @file llfile.h
3 * @author Michael Schlachter
4 * @date 2006-03-23
5 * @brief Declaration of cross-platform POSIX file buffer and c++
6 * stream classes.
7 *
8 * Copyright (c) 2006-2007, Linden Research, Inc.
9 *
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 */
30
31#ifndef LL_LLFILE_H
32#define LL_LLFILE_H
33
34/**
35 * This class provides a cross platform interface to the filesystem.
36 * Attempts to mostly mirror the POSIX style IO functions.
37 */
38
39#include <string>
40#include <stdio.h>
41#include <sys/stat.h>
42#include <fstream>
43#include "stdtypes.h"
44
45typedef FILE LLFILE;
46
47#ifdef LL_WINDOWS
48#define USE_LLFILESTREAMS 1
49#else
50#define USE_LLFILESTREAMS 0
51#endif
52
53
54#if LL_WINDOWS
55// windows version of stat function and stat data structure are called _stat
56typedef struct _stat llstat;
57#else
58typedef struct stat llstat;
59#endif
60
61class LLFile
62{
63public:
64 // All these functions take UTF8 path/filenames.
65 static LLFILE* fopen(const char* filename,const char* accessmode); /* Flawfinder: ignore */
66 static LLFILE* _fsopen(const char* filename,const char* accessmode,int sharingFlag);
67
68 // perms is a permissions mask like 0777 or 0700. In most cases it will
69 // be overridden by the user's umask. It is ignored on Windows.
70 static int mkdir(const char* filename, int perms = 0700);
71
72 static int remove(const char* filename);
73 static int rename(const char* filename,const char* newname);
74 static int stat(const char* filename,llstat* file_status);
75 static LLFILE * _Fiopen(const char *filename, std::ios::openmode mode,int); // protection currently unused
76};
77
78
79#if USE_LLFILESTREAMS
80
81class llifstream : public std::basic_istream < char , std::char_traits < char > >
82{
83 // input stream associated with a C stream
84public:
85 typedef std::basic_ifstream<char,std::char_traits < char > > _Myt;
86 typedef std::basic_filebuf<char,std::char_traits< char > > _Myfb;
87 typedef std::basic_ios<char,std::char_traits< char > > _Myios;
88
89 llifstream()
90 : std::basic_istream<char,std::char_traits< char > >(NULL,true),_Filebuffer(NULL)
91 { // construct unopened
92 }
93
94 explicit llifstream(const char *_Filename,
95 ios_base::openmode _Mode = ios_base::in,
96 int _Prot = (int)ios_base::_Openprot);
97
98 explicit llifstream(_Filet *_File)
99 : std::basic_istream<char,std::char_traits< char > >(NULL,true),
100 _Filebuffer(new _Myfb(_File))
101 { // construct with specified C stream
102 }
103 virtual ~llifstream();
104
105 _Myfb *rdbuf() const
106 { // return pointer to file buffer
107 return _Filebuffer;
108 }
109 bool is_open() const;
110 void open(const char *_Filename,
111 ios_base::openmode _Mode = ios_base::in,
112 int _Prot = (int)ios_base::_Openprot); /* Flawfinder: ignore */
113 void close();
114
115private:
116 _Myfb* _Filebuffer; // the file buffer
117};
118
119
120class llofstream : public std::basic_ostream< char , std::char_traits < char > >
121{
122public:
123 typedef std::basic_ostream< char , std::char_traits < char > > _Myt;
124 typedef std::basic_filebuf< char , std::char_traits < char > > _Myfb;
125 typedef std::basic_ios<char,std::char_traits < char > > _Myios;
126
127 llofstream()
128 : std::basic_ostream<char,std::char_traits < char > >(NULL,true),_Filebuffer(NULL)
129 { // construct unopened
130 }
131
132 explicit llofstream(const char *_Filename,
133 std::ios_base::openmode _Mode = ios_base::out,
134 int _Prot = (int)std::ios_base::_Openprot);
135
136
137 explicit llofstream(_Filet *_File)
138 : std::basic_ostream<char,std::char_traits < char > >(NULL,true),
139 _Filebuffer(new _Myfb(_File))//_File)
140 { // construct with specified C stream
141 }
142
143 virtual ~llofstream();
144
145 _Myfb *rdbuf() const
146 { // return pointer to file buffer
147 return _Filebuffer;
148 }
149
150 bool is_open() const;
151
152 void open(const char *_Filename,ios_base::openmode _Mode = ios_base::out,int _Prot = (int)ios_base::_Openprot); /* Flawfinder: ignore */
153
154 void close();
155
156private:
157 _Myfb *_Filebuffer; // the file buffer
158};
159
160
161
162#else
163//Use standard file streams on non windows platforms
164#define llifstream std::ifstream
165#define llofstream std::ofstream
166
167#endif
168
169
170#endif // not LL_LLFILE_H