nsprpub/pr/src/cplus/rcfileio.cpp

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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

mercurial