Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 ** Class implementation for normal and special file I/O (ref: prio.h)
8 */
10 #include "rcfileio.h"
12 #include <string.h>
14 RCFileIO::RCFileIO(): RCIO(RCIO::file) { }
16 RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); }
18 PRInt64 RCFileIO::Available()
19 { return fd->methods->available(fd); }
21 PRStatus RCFileIO::Close()
22 { PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; }
24 PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); }
26 PRStatus RCFileIO::FileInfo(RCFileInfo* info) const
27 { return fd->methods->fileInfo64(fd, &info->info); }
29 PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info)
30 { return PR_GetFileInfo64(name, &info->info); }
32 PRStatus RCFileIO::Fsync()
33 { return fd->methods->fsync(fd); }
35 PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
36 {
37 fd = PR_Open(filename, flags, mode);
38 return (NULL == fd) ? PR_FAILURE : PR_SUCCESS;
39 } /* RCFileIO::Open */
41 PRInt32 RCFileIO::Read(void *buf, PRSize amount)
42 { return fd->methods->read(fd, buf, amount); }
44 PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
45 {
46 PRSeekWhence whence;
47 switch (how)
48 {
49 case RCFileIO::set: whence = PR_SEEK_SET; break;
50 case RCFileIO::current: whence = PR_SEEK_CUR; break;
51 case RCFileIO::end: whence = PR_SEEK_END; break;
52 default: whence = (PRSeekWhence)-1;
53 }
54 return fd->methods->seek64(fd, offset, whence);
55 } /* RCFileIO::Seek */
57 PRInt32 RCFileIO::Write(const void *buf, PRSize amount)
58 { return fd->methods->write(fd, buf, amount); }
60 PRInt32 RCFileIO::Writev(
61 const PRIOVec *iov, PRSize size, const RCInterval& timeout)
62 { return fd->methods->writev(fd, iov, size, timeout); }
64 RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
65 {
66 PRFileDesc* fd;
67 PRSpecialFD which;
68 RCFileIO* spec = NULL;
70 switch (special)
71 {
72 case RCFileIO::input: which = PR_StandardInput; break;
73 case RCFileIO::output: which = PR_StandardOutput; break;
74 case RCFileIO::error: which = PR_StandardError; break;
75 default: which = (PRSpecialFD)-1;
76 }
77 fd = PR_GetSpecialFD(which);
78 if (NULL != fd)
79 {
80 spec = new RCFileIO();
81 if (NULL != spec) spec->fd = fd;
82 }
83 return spec;
84 } /* RCFileIO::GetSpecialFile */
87 /*
88 ** The following methods have been made non-virtual and private. These
89 ** default implementations are intended to NEVER be called. They
90 ** are not valid for this type of I/O class (normal and special file).
91 */
92 PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&)
93 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
95 PRStatus RCFileIO::GetLocalName(RCNetAddr*) const
96 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
98 PRStatus RCFileIO::GetPeerName(RCNetAddr*) const
99 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
101 PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const
102 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
104 PRStatus RCFileIO::Listen(PRIntn)
105 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
107 PRInt16 RCFileIO::Poll(PRInt16, PRInt16*)
108 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; }
110 PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&)
111 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
113 PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&)
114 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
116 PRInt32 RCFileIO::Send(
117 const void*, PRSize, PRIntn, const RCInterval&)
118 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
120 PRInt32 RCFileIO::Sendto(
121 const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&)
122 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
124 RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&)
125 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; }
127 PRStatus RCFileIO::Bind(const RCNetAddr&)
128 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
130 PRInt32 RCFileIO::AcceptRead(
131 RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&)
132 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
134 PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*)
135 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
137 PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow)
138 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
140 PRInt32 RCFileIO::TransmitFile(
141 RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&)
142 { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
144 /*
145 ** Class implementation for file information object (ref: prio.h)
146 */
148 RCFileInfo::~RCFileInfo() { }
150 RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase()
151 { info = her.info; } /* RCFileInfo::RCFileInfo */
153 RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); }
155 RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); }
157 RCFileInfo::FileType RCFileInfo::Type() const
158 {
159 RCFileInfo::FileType type;
160 switch (info.type)
161 {
162 case PR_FILE_FILE: type = RCFileInfo::file; break;
163 case PR_FILE_DIRECTORY: type = RCFileInfo::directory; break;
164 default: type = RCFileInfo::other;
165 }
166 return type;
167 } /* RCFileInfo::Type */