Bug 1311466 - Part 4: Add a C++ only getFileDescriptor() method to nsIFileMetadata interface. All file stream implementations (nsFileInputStream, nsPartialFileInputStream, nsFileOutputStream, nsAtomicFileOutputStream, nsSafeFileOutputStream and nsFileStream) support nsIFileMetadata interface so the new method is available on all these streams. The returned file descriptor can be used for memory mapping of the underlying file. The new method exposes stream's internal member variable, so it should be used carefully; r=froydnj

This commit is contained in:
Jan Varga 2016-10-25 21:18:52 +02:00
parent 00707ba46a
commit 12b2353123
2 changed files with 28 additions and 0 deletions

View File

@ -167,6 +167,22 @@ nsFileStreamBase::GetLastModified(int64_t* _retval)
return NS_OK;
}
NS_IMETHODIMP
nsFileStreamBase::GetFileDescriptor(PRFileDesc** _retval)
{
nsresult rv = DoPendingOpen();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!mFD) {
return NS_BASE_STREAM_CLOSED;
}
*_retval = mFD;
return NS_OK;
}
nsresult
nsFileStreamBase::Close()
{

View File

@ -8,6 +8,12 @@
interface nsIFile;
%{C++
struct PRFileDesc;
%}
[ptr] native PRFileDescPtr(PRFileDesc);
/**
* An input stream that allows you to read from a file.
*/
@ -222,4 +228,10 @@ interface nsIFileMetadata : nsISupports
* January 1, 1970 Greenwich Mean Time (GMT).
*/
readonly attribute long long lastModified;
/**
* The internal file descriptor. It can be used for memory mapping of the
* underlying file. Please use carefully!
*/
[noscript] PRFileDescPtr getFileDescriptor();
};