2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: StdioStorage.C /main/1 1996/07/29 17:04:42 cde-hp $ */
24 // Copyright (c) 1994, 1995 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "StdioStorage.h"
35 #include "ErrnoMessageArg.h"
38 #include "CodingSystem.h"
40 #include "StdioStorageMessages.h"
52 namespace SP_NAMESPACE {
55 class StdioStorageObject : public StorageObject {
57 StdioStorageObject(FILE *fp, const StringC &filename);
58 ~StdioStorageObject();
59 Boolean read(char *buf, size_t bufSize, Messenger &mgr, size_t &nread);
60 Boolean rewind(Messenger &mgr);
61 size_t getBlockSize() const;
69 void error(Messenger &mgr, const MessageType2 &, int err);
73 String<char> filenameBytes_;
76 StdioStorageManager::StdioStorageManager(const char *type,
77 const UnivCharsetDesc &filenameCharset,
78 const OutputCodingSystem *filenameCodingSystem)
79 : IdStorageManager(filenameCharset),
81 filenameCodingSystem_(filenameCodingSystem)
85 StorageObject *StdioStorageManager::makeStorageObject(const StringC &str,
93 String<char> filenameBytes = filenameCodingSystem_->convertOut(filename);
95 FILE *fp = fopen(filenameBytes.data(), "r");
97 ParentLocationMessenger(mgr).message(StdioStorageMessages::openFailed,
98 StringMessageArg(filename),
99 ErrnoMessageArg(errno));
103 return new StdioStorageObject(fp, filename);
106 const char *StdioStorageManager::type() const
111 StdioStorageObject::StdioStorageObject(FILE *fp, const StringC &filename)
112 : fp_(fp), filename_(filename)
116 StdioStorageObject::~StdioStorageObject()
124 Boolean StdioStorageObject::rewind(Messenger &mgr)
128 if (fseek(fp_, 0L, SEEK_SET) < 0) {
129 error(mgr, StdioStorageMessages::seekFailed, errno);
137 size_t StdioStorageObject::getBlockSize() const
142 Boolean StdioStorageObject::read(char *buf, size_t bufSize, Messenger &mgr,
150 while (n < bufSize) {
154 error(mgr, StdioStorageMessages::readFailed, errno);
168 void StdioStorageObject::error(Messenger &mgr,
169 const MessageType2 &msg,
172 ParentLocationMessenger(mgr).message(msg,
173 StringMessageArg(filename_),
174 ErrnoMessageArg(err));