~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/cplus/rcfileio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
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/
 
7
 * 
 
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.
 
12
 * 
 
13
 * The Original Code is the Netscape Portable Runtime (NSPR).
 
14
 * 
 
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
 
18
 * Rights Reserved.
 
19
 * 
 
20
 * Contributor(s):
 
21
 * 
 
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
 
32
 * GPL.
 
33
 */
 
34
 
 
35
/*
 
36
** Class implementation for normal and special file I/O (ref: prio.h)
 
37
*/
 
38
 
 
39
#include "rcfileio.h"
 
40
 
 
41
#include <string.h>
 
42
 
 
43
RCFileIO::RCFileIO(): RCIO(RCIO::file) { }
 
44
 
 
45
RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); }
 
46
 
 
47
PRInt64 RCFileIO::Available()
 
48
    { return fd->methods->available(fd); }
 
49
 
 
50
PRStatus RCFileIO::Close()
 
51
    { PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; }
 
52
 
 
53
PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); }
 
54
 
 
55
PRStatus RCFileIO::FileInfo(RCFileInfo* info) const
 
56
    { return fd->methods->fileInfo64(fd, &info->info); }
 
57
 
 
58
PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info)
 
59
    { return PR_GetFileInfo64(name, &info->info); }
 
60
 
 
61
PRStatus RCFileIO::Fsync()
 
62
    { return fd->methods->fsync(fd); }
 
63
 
 
64
PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
 
65
{
 
66
    fd = PR_Open(filename, flags, mode);
 
67
    return (NULL == fd) ? PR_FAILURE : PR_SUCCESS;
 
68
}  /* RCFileIO::Open */
 
69
 
 
70
PRInt32 RCFileIO::Read(void *buf, PRSize amount)
 
71
    { return fd->methods->read(fd, buf, amount); }
 
72
 
 
73
PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
 
74
{
 
75
    PRSeekWhence whence;
 
76
    switch (how)
 
77
    {
 
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;
 
82
    }
 
83
    return fd->methods->seek64(fd, offset, whence);
 
84
}  /* RCFileIO::Seek */
 
85
 
 
86
PRInt32 RCFileIO::Write(const void *buf, PRSize amount)
 
87
    { return fd->methods->write(fd, buf, amount); }
 
88
 
 
89
PRInt32 RCFileIO::Writev(
 
90
    const PRIOVec *iov, PRSize size, const RCInterval& timeout)
 
91
    { return fd->methods->writev(fd, iov, size, timeout); }
 
92
 
 
93
RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
 
94
{
 
95
    PRFileDesc* fd;
 
96
    PRSpecialFD which;
 
97
    RCFileIO* spec = NULL;
 
98
 
 
99
    switch (special)
 
100
    {
 
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;
 
105
    }
 
106
    fd = PR_GetSpecialFD(which);
 
107
    if (NULL != fd)
 
108
    {
 
109
        spec = new RCFileIO();
 
110
        if (NULL != spec) spec->fd = fd;
 
111
    }
 
112
    return spec;
 
113
}  /* RCFileIO::GetSpecialFile */
 
114
 
 
115
 
 
116
/*
 
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).
 
120
*/
 
121
PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&)
 
122
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
123
 
 
124
PRStatus RCFileIO::GetLocalName(RCNetAddr*) const
 
125
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
126
 
 
127
PRStatus RCFileIO::GetPeerName(RCNetAddr*) const
 
128
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
129
 
 
130
PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const
 
131
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
132
 
 
133
PRStatus RCFileIO::Listen(PRIntn)
 
134
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
135
 
 
136
PRInt16 RCFileIO::Poll(PRInt16, PRInt16*)
 
137
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; }
 
138
 
 
139
PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&)
 
140
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
141
 
 
142
PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&)
 
143
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
144
 
 
145
PRInt32 RCFileIO::Send(
 
146
    const void*, PRSize, PRIntn, const RCInterval&)
 
147
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
148
 
 
149
PRInt32 RCFileIO::Sendto(
 
150
    const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&)
 
151
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
152
 
 
153
RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&)
 
154
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; }
 
155
 
 
156
PRStatus RCFileIO::Bind(const RCNetAddr&)
 
157
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
158
 
 
159
PRInt32 RCFileIO::AcceptRead(
 
160
    RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&)
 
161
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
162
 
 
163
PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*)
 
164
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
165
 
 
166
PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow)
 
167
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
 
168
 
 
169
PRInt32 RCFileIO::TransmitFile(
 
170
    RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&)
 
171
{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
 
172
 
 
173
/*
 
174
** Class implementation for file information object (ref: prio.h)
 
175
*/
 
176
 
 
177
RCFileInfo::~RCFileInfo() { }
 
178
 
 
179
RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase()
 
180
    { info = her.info; }  /* RCFileInfo::RCFileInfo */
 
181
 
 
182
RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); }
 
183
 
 
184
RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); }
 
185
 
 
186
RCFileInfo::FileType RCFileInfo::Type() const
 
187
{
 
188
    RCFileInfo::FileType type;
 
189
    switch (info.type)
 
190
    {
 
191
        case PR_FILE_FILE: type = RCFileInfo::file; break;
 
192
        case PR_FILE_DIRECTORY: type = RCFileInfo::directory; break;
 
193
        default: type = RCFileInfo::other;
 
194
    }
 
195
    return type;
 
196
}  /* RCFileInfo::Type */