示例#1
0
PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
{
    PRFileInfo64 info;

    /* assert on PR_PROT_READWRITE which modifies the underlying file */
    PR_ASSERT(fmap->prot == PR_PROT_READONLY ||
              fmap->prot == PR_PROT_WRITECOPY);
    if (fmap->prot != PR_PROT_READONLY &&
        fmap->prot != PR_PROT_WRITECOPY) {
        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
        return PR_FAILURE;
    }
    if (PR_GetOpenFileInfo64(fmap->fd, &info) == PR_FAILURE) {
        return PR_FAILURE;
    }
    /* reject zero-byte mappings & zero-byte files */
    if (!size || !info.size) {
        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
        return PR_FAILURE;
    }
    /* file size rounded up to the next page boundary */
    fmap->md.maxExtent = (info.size + 0xfff) & ~(0xfff);

    return PR_SUCCESS;
}
示例#2
0
nsresult
FileLocation::Data::GetSize(uint32_t *result)
{
  if (mFd) {
    PRFileInfo64 fileInfo;
    if (PR_SUCCESS != PR_GetOpenFileInfo64(mFd, &fileInfo))
      return NS_ErrorAccordingToNSPR();

    if (fileInfo.size > int64_t(PR_UINT32_MAX))
      return NS_ERROR_FILE_TOO_BIG;

    *result = fileInfo.size;
    return NS_OK;
  } else if (mItem) {
    *result = mItem->RealSize();
    return NS_OK;
  }
  return NS_ERROR_NOT_INITIALIZED;
}
示例#3
0
文件: uxshm.c 项目: edrikL/gears
extern PRFileMap * _md_ImportFileMapFromString(
    const char *fmstring
)
{
    PRStatus    rc;
    PRInt32     osfd;
    PRIntn      prot; /* really: a PRFileMapProtect */
    PRFileDesc  *fd;
    PRFileMap   *fm = NULL; /* default return value */
    PRFileInfo64 info;

    PR_sscanf( fmstring, "%ld:%d", &osfd, &prot );

    /* import the os file descriptor */
    fd = PR_ImportFile( osfd );
    if ( NULL == fd ) {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
        goto Finished;
    }

    rc = PR_GetOpenFileInfo64( fd, &info );
    if ( PR_FAILURE == rc )  {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));    
        goto Finished;
    }

    fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot );
    if ( NULL == fm ) {
        PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
            ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));    
    }

Finished:
    return(fm);
} /* end _md_ImportFileMapFromString() */