1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rcfileio.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** Class implementation for normal and special file I/O (ref: prio.h) 1.11 +*/ 1.12 + 1.13 +#include "rcfileio.h" 1.14 + 1.15 +#include <string.h> 1.16 + 1.17 +RCFileIO::RCFileIO(): RCIO(RCIO::file) { } 1.18 + 1.19 +RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); } 1.20 + 1.21 +PRInt64 RCFileIO::Available() 1.22 + { return fd->methods->available(fd); } 1.23 + 1.24 +PRStatus RCFileIO::Close() 1.25 + { PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; } 1.26 + 1.27 +PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); } 1.28 + 1.29 +PRStatus RCFileIO::FileInfo(RCFileInfo* info) const 1.30 + { return fd->methods->fileInfo64(fd, &info->info); } 1.31 + 1.32 +PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info) 1.33 + { return PR_GetFileInfo64(name, &info->info); } 1.34 + 1.35 +PRStatus RCFileIO::Fsync() 1.36 + { return fd->methods->fsync(fd); } 1.37 + 1.38 +PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode) 1.39 +{ 1.40 + fd = PR_Open(filename, flags, mode); 1.41 + return (NULL == fd) ? PR_FAILURE : PR_SUCCESS; 1.42 +} /* RCFileIO::Open */ 1.43 + 1.44 +PRInt32 RCFileIO::Read(void *buf, PRSize amount) 1.45 + { return fd->methods->read(fd, buf, amount); } 1.46 + 1.47 +PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how) 1.48 +{ 1.49 + PRSeekWhence whence; 1.50 + switch (how) 1.51 + { 1.52 + case RCFileIO::set: whence = PR_SEEK_SET; break; 1.53 + case RCFileIO::current: whence = PR_SEEK_CUR; break; 1.54 + case RCFileIO::end: whence = PR_SEEK_END; break; 1.55 + default: whence = (PRSeekWhence)-1; 1.56 + } 1.57 + return fd->methods->seek64(fd, offset, whence); 1.58 +} /* RCFileIO::Seek */ 1.59 + 1.60 +PRInt32 RCFileIO::Write(const void *buf, PRSize amount) 1.61 + { return fd->methods->write(fd, buf, amount); } 1.62 + 1.63 +PRInt32 RCFileIO::Writev( 1.64 + const PRIOVec *iov, PRSize size, const RCInterval& timeout) 1.65 + { return fd->methods->writev(fd, iov, size, timeout); } 1.66 + 1.67 +RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special) 1.68 +{ 1.69 + PRFileDesc* fd; 1.70 + PRSpecialFD which; 1.71 + RCFileIO* spec = NULL; 1.72 + 1.73 + switch (special) 1.74 + { 1.75 + case RCFileIO::input: which = PR_StandardInput; break; 1.76 + case RCFileIO::output: which = PR_StandardOutput; break; 1.77 + case RCFileIO::error: which = PR_StandardError; break; 1.78 + default: which = (PRSpecialFD)-1; 1.79 + } 1.80 + fd = PR_GetSpecialFD(which); 1.81 + if (NULL != fd) 1.82 + { 1.83 + spec = new RCFileIO(); 1.84 + if (NULL != spec) spec->fd = fd; 1.85 + } 1.86 + return spec; 1.87 +} /* RCFileIO::GetSpecialFile */ 1.88 + 1.89 + 1.90 +/* 1.91 +** The following methods have been made non-virtual and private. These 1.92 +** default implementations are intended to NEVER be called. They 1.93 +** are not valid for this type of I/O class (normal and special file). 1.94 +*/ 1.95 +PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&) 1.96 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.97 + 1.98 +PRStatus RCFileIO::GetLocalName(RCNetAddr*) const 1.99 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.100 + 1.101 +PRStatus RCFileIO::GetPeerName(RCNetAddr*) const 1.102 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.103 + 1.104 +PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const 1.105 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.106 + 1.107 +PRStatus RCFileIO::Listen(PRIntn) 1.108 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.109 + 1.110 +PRInt16 RCFileIO::Poll(PRInt16, PRInt16*) 1.111 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; } 1.112 + 1.113 +PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&) 1.114 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.115 + 1.116 +PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&) 1.117 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.118 + 1.119 +PRInt32 RCFileIO::Send( 1.120 + const void*, PRSize, PRIntn, const RCInterval&) 1.121 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.122 + 1.123 +PRInt32 RCFileIO::Sendto( 1.124 + const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&) 1.125 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.126 + 1.127 +RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&) 1.128 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; } 1.129 + 1.130 +PRStatus RCFileIO::Bind(const RCNetAddr&) 1.131 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.132 + 1.133 +PRInt32 RCFileIO::AcceptRead( 1.134 + RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&) 1.135 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.136 + 1.137 +PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*) 1.138 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.139 + 1.140 +PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow) 1.141 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; } 1.142 + 1.143 +PRInt32 RCFileIO::TransmitFile( 1.144 + RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&) 1.145 +{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } 1.146 + 1.147 +/* 1.148 +** Class implementation for file information object (ref: prio.h) 1.149 +*/ 1.150 + 1.151 +RCFileInfo::~RCFileInfo() { } 1.152 + 1.153 +RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase() 1.154 + { info = her.info; } /* RCFileInfo::RCFileInfo */ 1.155 + 1.156 +RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); } 1.157 + 1.158 +RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); } 1.159 + 1.160 +RCFileInfo::FileType RCFileInfo::Type() const 1.161 +{ 1.162 + RCFileInfo::FileType type; 1.163 + switch (info.type) 1.164 + { 1.165 + case PR_FILE_FILE: type = RCFileInfo::file; break; 1.166 + case PR_FILE_DIRECTORY: type = RCFileInfo::directory; break; 1.167 + default: type = RCFileInfo::other; 1.168 + } 1.169 + return type; 1.170 +} /* RCFileInfo::Type */