1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
36
** Class implementation for normal and special file I/O (ref: prio.h)
43
RCFileIO::RCFileIO(): RCIO(RCIO::file) { }
45
RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); }
47
PRInt64 RCFileIO::Available()
48
{ return fd->methods->available(fd); }
50
PRStatus RCFileIO::Close()
51
{ PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; }
53
PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); }
55
PRStatus RCFileIO::FileInfo(RCFileInfo* info) const
56
{ return fd->methods->fileInfo64(fd, &info->info); }
58
PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info)
59
{ return PR_GetFileInfo64(name, &info->info); }
61
PRStatus RCFileIO::Fsync()
62
{ return fd->methods->fsync(fd); }
64
PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
66
fd = PR_Open(filename, flags, mode);
67
return (NULL == fd) ? PR_FAILURE : PR_SUCCESS;
68
} /* RCFileIO::Open */
70
PRInt32 RCFileIO::Read(void *buf, PRSize amount)
71
{ return fd->methods->read(fd, buf, amount); }
73
PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
78
case RCFileIO::set: whence = PR_SEEK_SET; break;
79
case RCFileIO::current: whence = PR_SEEK_CUR; break;
80
case RCFileIO::end: whence = PR_SEEK_END; break;
81
default: whence = (PRSeekWhence)-1;
83
return fd->methods->seek64(fd, offset, whence);
84
} /* RCFileIO::Seek */
86
PRInt32 RCFileIO::Write(const void *buf, PRSize amount)
87
{ return fd->methods->write(fd, buf, amount); }
89
PRInt32 RCFileIO::Writev(
90
const PRIOVec *iov, PRSize size, const RCInterval& timeout)
91
{ return fd->methods->writev(fd, iov, size, timeout); }
93
RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
97
RCFileIO* spec = NULL;
101
case RCFileIO::input: which = PR_StandardInput; break;
102
case RCFileIO::output: which = PR_StandardOutput; break;
103
case RCFileIO::error: which = PR_StandardError; break;
104
default: which = (PRSpecialFD)-1;
106
fd = PR_GetSpecialFD(which);
109
spec = new RCFileIO();
110
if (NULL != spec) spec->fd = fd;
113
} /* RCFileIO::GetSpecialFile */
117
** The following methods have been made non-virtual and private. These
118
** default implementations are intended to NEVER be called. They
119
** are not valid for this type of I/O class (normal and special file).
121
PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&)
122
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
124
PRStatus RCFileIO::GetLocalName(RCNetAddr*) const
125
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
127
PRStatus RCFileIO::GetPeerName(RCNetAddr*) const
128
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
130
PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const
131
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
133
PRStatus RCFileIO::Listen(PRIntn)
134
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
136
PRInt16 RCFileIO::Poll(PRInt16, PRInt16*)
137
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; }
139
PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&)
140
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
142
PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&)
143
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
145
PRInt32 RCFileIO::Send(
146
const void*, PRSize, PRIntn, const RCInterval&)
147
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
149
PRInt32 RCFileIO::Sendto(
150
const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&)
151
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
153
RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&)
154
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; }
156
PRStatus RCFileIO::Bind(const RCNetAddr&)
157
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
159
PRInt32 RCFileIO::AcceptRead(
160
RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&)
161
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
163
PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*)
164
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
166
PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow)
167
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
169
PRInt32 RCFileIO::TransmitFile(
170
RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&)
171
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
174
** Class implementation for file information object (ref: prio.h)
177
RCFileInfo::~RCFileInfo() { }
179
RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase()
180
{ info = her.info; } /* RCFileInfo::RCFileInfo */
182
RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); }
184
RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); }
186
RCFileInfo::FileType RCFileInfo::Type() const
188
RCFileInfo::FileType type;
191
case PR_FILE_FILE: type = RCFileInfo::file; break;
192
case PR_FILE_DIRECTORY: type = RCFileInfo::directory; break;
193
default: type = RCFileInfo::other;
196
} /* RCFileInfo::Type */