当前位置: 首页>>代码示例>>C++>>正文


C++ PR_Read函数代码示例

本文整理汇总了C++中PR_Read函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_Read函数的具体用法?C++ PR_Read怎么用?C++ PR_Read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PR_Read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: os2File

NS_IMETHODIMP
nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI)
{
    nsresult rv;

    nsCOMPtr<nsILocalFileOS2> os2File (do_QueryInterface(aFile, &rv));
    if (NS_FAILED(rv))
        return NS_ERROR_NOT_AVAILABLE;

    // see if this file is a WPS UrlObject
    PRBool isUrl;
    rv = os2File->IsFileType(NS_LITERAL_CSTRING("UniformResourceLocator"),
                             &isUrl);
    if (NS_FAILED(rv) || !isUrl)
        return NS_ERROR_NOT_AVAILABLE;

    // if so, open it & get its size
    PRFileDesc *file;
    rv = os2File->OpenNSPRFileDesc(PR_RDONLY, 0, &file);
    if (NS_FAILED(rv))
        return NS_ERROR_NOT_AVAILABLE;

    PRInt64 fileSize;
    os2File->GetFileSize(&fileSize);
    rv = NS_ERROR_NOT_AVAILABLE;

    // get a buffer, read the entire file, then create
    // an nsURI;  we assume the string is already escaped
    char * buffer = (char*)NS_Alloc(fileSize+1);
    if (buffer) {
        PRInt32 cnt = PR_Read(file, buffer, fileSize);
        if (cnt > 0) {
            buffer[cnt] = '\0';
            if (NS_SUCCEEDED(NS_NewURI(aURI, nsDependentCString(buffer))))
                rv = NS_OK;
        }
        NS_Free(buffer);
    }
    PR_Close(file);

    return rv;
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:42,代码来源:nsFileProtocolHandler.cpp

示例2: beginReadingRDFFile

void
beginReadingRDFFile (RDFFile file)
{
	char		*url;
	int		method = 0;

#ifndef MOZILLA_CLIENT

   /* If standalone, we just use  to open the file */
   NET_StreamClass stream;
   PRFileDesc *fd;
   PRFileInfo fi;
   PRBool bSuccess = FALSE;
    
   url = file->url;
   fd = CallPROpenUsingFileURL(url, PR_RDONLY, 0);
   if(fd)
   {
      if(PR_GetOpenFileInfo(fd, &fi) == PR_SUCCESS)
      {
         char* buf = malloc(fi.size);
         if(PR_Read(fd, buf, fi.size))
         {
            stream.data_object = file;
            if(parseNextRDFXMLBlob (&stream, buf, fi.size))
               bSuccess = TRUE;
         }
         free(buf);
      }
      PR_Close(fd);
   }
   if(bSuccess == TRUE)
      rdf_complete(&stream);
#else

	url = file->url;
	if (file->fileType == ES_RT)	method = URL_INDEX_METHOD;
	rdf_GetURL (gRDFMWContext(file->db), method, NULL, file);

#endif
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:41,代码来源:glue.c

示例3: crc32

//---------------------------------------------
// nsZipArchive::CopyItemToDisk
//---------------------------------------------
nsresult
nsZipArchive::CopyItemToDisk(PRUint32 itemSize, PRUint32 itemCrc, PRFileDesc* outFD)
/*
 * This function copies an archive item to disk, to the
 * file specified by outFD. If outFD is zero, the extracted data is
 * not written, only checked for CRC, so this is in effect same as 'Test'.
 */
{
  PRUint32    chunk, pos, crc;
  char buf[ZIP_BUFLEN];

  //-- initialize crc
  crc = crc32(0L, Z_NULL, 0);

  //-- copy chunks until file is done
  for (pos = 0; pos < itemSize; pos += chunk)
  {
    chunk = (itemSize - pos < ZIP_BUFLEN) ? (itemSize - pos) : ZIP_BUFLEN;
    
    if (PR_Read(mFd, buf, chunk) != (READTYPE)chunk)
    {
      //-- unexpected end of data in archive
      return ZIP_ERR_CORRUPT;
    }

    //-- incrementally update crc32
    crc = crc32(crc, (const unsigned char*)buf, chunk);

    if (outFD && PR_Write(outFD, buf, chunk) < (READTYPE)chunk)
    {
      //-- Couldn't write all the data (disk full?)
      return ZIP_ERR_DISK;
    }
  }

  //-- verify crc32
  if (crc != itemCrc)
      return ZIP_ERR_CORRUPT;

  return ZIP_OK;
}
开发者ID:ahadzi,项目名称:celtx,代码行数:44,代码来源:nsZipArchive.cpp

示例4: _MD_MemMap

void * _MD_MemMap(PRFileMap *fmap, PROffset64 offset, PRUint32 len)
{
    PRUint32 rv;
    void *addr;

    /* prevent mappings beyond EOF + remainder of page */
    if (offset + len > fmap->md.maxExtent) {
        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
        return NULL;
    }
    if (PR_Seek64(fmap->fd, offset, PR_SEEK_SET) == -1) {
        return NULL;
    }
    /* try for high memory, fall back to low memory if hi-mem fails */
#if defined(MOZ_OS2_HIGH_MEMORY)
    rv = DosAllocMem(&addr, len, OBJ_ANY | PAG_COMMIT | PAG_READ | PAG_WRITE);
    if (rv)
#endif
    {
        rv = DosAllocMem(&addr, len, PAG_COMMIT | PAG_READ | PAG_WRITE);
        if (rv) {
            PR_SetError(PR_OUT_OF_MEMORY_ERROR, rv);
            return NULL;
        }
    }
    if (PR_Read(fmap->fd, addr, len) == -1) {
        DosFreeMem(addr);
        return NULL;
    }
    /* don't permit writes if readonly */
    if (fmap->prot == PR_PROT_READONLY) {
        rv = DosSetMem(addr, len, PAG_READ);
        if (rv) {
            DosFreeMem(addr);
            PR_SetError(PR_UNKNOWN_ERROR, rv);
            return NULL;
        }
    }
    return addr;
}
开发者ID:ppbao,项目名称:mozilla-os2,代码行数:40,代码来源:os2misc.c

示例5: readInputFile

int
readInputFile(const char * filename, SECItem * result)
{
  PRFileDesc *file /* = PR_OpenFile(input_file, 0) */;
  PRFileInfo info;
  PRStatus s;
  PRInt32 count;
  int retval = -1;

  file = PR_Open(filename, PR_RDONLY, 0);
  if (!file) {
    if (verbose) PR_fprintf(pr_stderr, "Open of file %s failed\n", filename);
    goto loser;
  }

  s = PR_GetOpenFileInfo(file, &info);
  if (s != PR_SUCCESS) {
    if (verbose) PR_fprintf(pr_stderr, "File info operation failed\n");
    goto file_loser;
  }

  result->len = info.size;
  result->data = (unsigned char *)PR_Malloc(result->len);
  if (!result->data) {
    if (verbose) PR_fprintf(pr_stderr, "Allocation of buffer failed\n");
    goto file_loser;
  }

  count = PR_Read(file, result->data, result->len);
  if (count != result->len) {
    if (verbose) PR_fprintf(pr_stderr, "Read failed\n");
    goto file_loser;
  }
  retval = 0;

file_loser:
  PR_Close(file);
loser:
  return retval;
}
开发者ID:MekliCZ,项目名称:positron,代码行数:40,代码来源:sdrtest.c

示例6: NS_ASSERTION

NS_IMETHODIMP
nsTemporaryFileInputStream::ReadSegments(nsWriteSegmentFun writer,
                                         void *            closure,
                                         uint32_t          count,
                                         uint32_t *        result)
{
  NS_ASSERTION(result, "null ptr");
  NS_ASSERTION(mStartPos <= mEndPos, "bad stream state");
  *result = 0;

  if (mClosed) {
    return NS_BASE_STREAM_CLOSED;
  }

  mozilla::MutexAutoLock lock(mFileDescOwner->FileMutex());
  PR_Seek64(mFileDescOwner->mFD, mStartPos, PR_SEEK_SET);

  count = std::min(count, uint32_t(mEndPos - mStartPos));
  uint32_t remainBufCount = count;

  char buf[4096];
  while (remainBufCount > 0) {
    uint32_t bufCount = std::min(remainBufCount, (uint32_t)sizeof(buf));
    int32_t read_result = PR_Read(mFileDescOwner->mFD, buf, bufCount);
    if (read_result < 0) {
      return NS_ErrorAccordingToNSPR();
    }
    uint32_t write_result = 0;
    nsresult rv = writer(this, closure, buf,
                         count - remainBufCount, bufCount, &write_result);
    remainBufCount -= bufCount;
    if (NS_SUCCEEDED(rv)) {
      NS_ASSERTION(write_result <= bufCount,
                   "writer should not write more than we asked it to write");
    }
    mStartPos += bufCount;
  }
  *result = count;
  return NS_OK;
}
开发者ID:Nebelhom,项目名称:mozilla-central,代码行数:40,代码来源:nsTemporaryFileInputStream.cpp

示例7: ssl_read

int ssl_read(void *conn, char *buf, int len)
{
	int st;
	PRErrorCode PR_err;

	if (!((struct scd *)conn)->established) {
		ssl_errno = SSL_NOHANDSHAKE;
		return -1;
	}

	st = PR_Read(((struct scd *)conn)->prfd, buf, len);
	PR_err = PR_GetError();

	ssl_errno = SSL_OK;
	if (PR_err == PR_WOULD_BLOCK_ERROR)
		ssl_errno = SSL_AGAIN;

	if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0)
		len = write(STDERR_FILENO, buf, st);

	return st;
}
开发者ID:MrSam,项目名称:bitlbee,代码行数:22,代码来源:ssl_nss.c

示例8: PR_Read

nsresult
FileLocation::Data::Copy(char* aBuf, uint32_t aLen)
{
  if (mFd) {
    for (uint32_t totalRead = 0; totalRead < aLen;) {
      int32_t read = PR_Read(mFd, aBuf + totalRead,
                             XPCOM_MIN(aLen - totalRead, uint32_t(INT32_MAX)));
      if (read < 0) {
        return NS_ErrorAccordingToNSPR();
      }
      totalRead += read;
    }
    return NS_OK;
  } else if (mItem) {
    nsZipCursor cursor(mItem, mZip, reinterpret_cast<uint8_t*>(aBuf),
                       aLen, true);
    uint32_t readLen;
    cursor.Copy(&readLen);
    return (readLen == aLen) ? NS_OK : NS_ERROR_FILE_CORRUPTED;
  }
  return NS_ERROR_NOT_INITIALIZED;
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:22,代码来源:FileLocation.cpp

示例9: ReadFromFile

static nsresult
ReadFromFile(nsIFile* aPath,
             const nsACString& aFileName,
             nsACString& aOutData,
             int32_t aMaxLength)
{
  nsCOMPtr<nsIFile> path;
  nsresult rv = aPath->Clone(getter_AddRefs(path));
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  rv = path->AppendNative(aFileName);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  PRFileDesc* f = nullptr;
  rv = path->OpenNSPRFileDesc(PR_RDONLY | PR_CREATE_FILE, PR_IRWXU, &f);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  auto size = PR_Seek(f, 0, PR_SEEK_END);
  PR_Seek(f, 0, PR_SEEK_SET);

  if (size > aMaxLength) {
    return NS_ERROR_FAILURE;
  }
  aOutData.SetLength(size);

  auto len = PR_Read(f, aOutData.BeginWriting(), size);
  PR_Close(f);
  if (NS_WARN_IF(len != size)) {
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:39,代码来源:GMPServiceParent.cpp

示例10: PR_Read

NS_IMETHODIMP
nsFileInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aResult)
{
    if (!mFD) {
        *aResult = 0;
        return NS_OK;
    }

    PRInt32 bytesRead = PR_Read(mFD, aBuf, aCount);
    if (bytesRead == -1) {
        return NS_ErrorAccordingToNSPR();
    }
    // Check if we're at the end of file and need to close
    if (mBehaviorFlags & CLOSE_ON_EOF) {
        if (bytesRead == 0) {
            Close();
        }
    }

    *aResult = bytesRead;
    return NS_OK;
}
开发者ID:fortunto2,项目名称:celtx,代码行数:22,代码来源:nsFileStreams.cpp

示例11: ASSERT_ON_THREAD

int NrSocket::read(void* buf, size_t maxlen, size_t *len) {
  ASSERT_ON_THREAD(ststhread_);
  int _status;
  int32_t status;

  if (!connect_invoked_)
    ABORT(R_FAILED);

  status = PR_Read(fd_, buf, maxlen);
  if (status < 0) {
    if (PR_GetError() == PR_WOULD_BLOCK_ERROR)
      ABORT(R_WOULDBLOCK);
    ABORT(R_IO_ERROR);
  }
  if (status == 0)
    ABORT(R_EOD);

  *len = (size_t)status;  // Guaranteed to be > 0
  _status = 0;
abort:
  return(_status);
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:22,代码来源:nr_socket_prsock.cpp

示例12: secu_StdinToItem

SECStatus
secu_StdinToItem(SECItem *dst)
{
    unsigned char buf[1000];
    PRInt32 numBytes;
    PRBool notDone = PR_TRUE;

    dst->len = 0;
    dst->data = NULL;

    while (notDone) {
        numBytes = PR_Read(PR_STDIN, buf, sizeof(buf));

        if (numBytes < 0) {
            return SECFailure;
        }

        if (numBytes == 0)
            break;

        if (dst->data) {
            unsigned char *p = dst->data;
            dst->data = (unsigned char *)PORT_Realloc(p, dst->len + numBytes);
            if (!dst->data) {
                PORT_Free(p);
            }
        } else {
            dst->data = (unsigned char *)PORT_Alloc(numBytes);
        }
        if (!dst->data) {
            return SECFailure;
        }
        PORT_Memcpy(dst->data + dst->len, buf, numBytes);
        dst->len += numBytes;
    }

    return SECSuccess;
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:38,代码来源:basicutil.c

示例13: PR_GetLine

/*
 * replacement for fgets
 * This isn't like the real fgets.  It fills in 's' but strips off any
 * trailing linefeed character(s).  The return value is 0 if it went
 * okay.
 */
int PR_GetLine(PRFileDesc *fd, char *s, unsigned int n)
{
    PRInt32 start, newstart;
    int x;
    char *p;

    /* grab current location in file */
    start = PR_Seek(fd, 0, PR_SEEK_CUR);
    x = PR_Read(fd, s, n-1);
    if (x <= 0) return 1;   /* EOF or other error */
    s[x] = 0;
    p = strchr(s, '\n');
    if (p == NULL) p = strchr(s, '\r');
    if (p == NULL) {
        /* assume there was one anyway */
        return 0;
    }
    *p = 0;
    newstart = start+strlen(s)+1;
    if ((p != s) && (*(p-1) == '\r')) *(p-1) = 0;
    PR_Seek(fd, newstart, PR_SEEK_SET);
    return 0;
}
开发者ID:Firstyear,项目名称:ds,代码行数:29,代码来源:nametable.c

示例14: do_GetService

nsresult
nsEmbedChromeRegistry::ReadChromeRegistry()
{
    nsresult rv;
    nsCOMPtr<nsIProperties> directoryService =
        do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsILocalFile> listFile;
    rv = directoryService->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsILocalFile),
                               getter_AddRefs(listFile));
    if (NS_FAILED(rv)) return rv;

    rv = listFile->AppendRelativeNativePath(NS_LITERAL_CSTRING("installed-chrome.txt"));
    if (NS_FAILED(rv)) return rv;

    PRFileDesc *file;
    rv = listFile->OpenNSPRFileDesc(PR_RDONLY, 0, &file);
    if (NS_FAILED(rv)) return rv;

    PRFileInfo finfo;

    if (PR_GetOpenFileInfo(file, &finfo) == PR_SUCCESS) {
        char *dataBuffer = new char[finfo.size+1];
        if (dataBuffer) {
            PRInt32 bufferSize = PR_Read(file, dataBuffer, finfo.size);
            if (bufferSize > 0) {
                dataBuffer[bufferSize] = '\r';
                rv = ProcessNewChromeBuffer(dataBuffer, bufferSize);
            }
            delete [] dataBuffer;
        }
    }
    PR_Close(file);

    return rv;
}
开发者ID:EdgarChen,项目名称:mozilla-cvs-history,代码行数:37,代码来源:nsEmbedChromeRegistry.cpp

示例15: PR_ASSERT

//---------------------------------------------
// nsZipArchive::SeekToItem
//---------------------------------------------
nsresult  nsZipArchive::SeekToItem(nsZipItem* aItem, PRFileDesc* aFd)
{
  PR_ASSERT (aItem);

  //-- the first time an item is used we need to calculate its offset
  if (!aItem->hasDataOffset)
  {
    //-- read local header to get variable length values and calculate
    //-- the real data offset
    //--
    //-- NOTE: extralen is different in central header and local header
    //--       for archives created using the Unix "zip" utility. To set
    //--       the offset accurately we need the _local_ extralen.
    if (!ZIP_Seek(aFd, aItem->headerOffset, PR_SEEK_SET))
      return ZIP_ERR_CORRUPT;

    ZipLocal   Local;
    if ((PR_Read(aFd, (char*)&Local, ZIPLOCAL_SIZE) != (READTYPE) ZIPLOCAL_SIZE) || 
        (xtolong(Local.signature) != LOCALSIG))
    {
      //-- read error or local header not found
      return ZIP_ERR_CORRUPT;
    }

    aItem->dataOffset = aItem->headerOffset +
                        ZIPLOCAL_SIZE +
                        xtoint(Local.filename_len) +
                        xtoint(Local.extrafield_len);
    aItem->hasDataOffset = PR_TRUE;
  }

  //-- move to start of file in archive
  if (!ZIP_Seek(aFd, aItem->dataOffset, PR_SEEK_SET))
    return  ZIP_ERR_CORRUPT;

  return ZIP_OK;
}
开发者ID:ahadzi,项目名称:celtx,代码行数:40,代码来源:nsZipArchive.cpp


注:本文中的PR_Read函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。