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


C++ PR_Write函数代码示例

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


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

示例1: FetchFile

PRStatus FetchFile(PRFileDesc *in, PRFileDesc *out)
{
    char buf[FCOPY_BUFFER_SIZE];
    PRInt32 nBytes;

    while ((nBytes = DrainInputBuffer(buf, sizeof(buf))) > 0) {
	if (PR_Write(out, buf, nBytes) != nBytes) {
            fprintf(stderr, "httpget: cannot write to file\n");
	    return PR_FAILURE;
	}
    }
    if (nBytes < 0) {
	/* Input buffer is empty and end of stream */
	return PR_SUCCESS;
    }
    while ((nBytes = PR_Read(in, buf, sizeof(buf))) > 0) {
	if (PR_Write(out, buf, nBytes) != nBytes) {
	    fprintf(stderr, "httpget: cannot write to file\n");
	    return PR_FAILURE;
        }
    }
    if (nBytes < 0) {
	fprintf(stderr, "httpget: cannot read from socket\n");
	return PR_FAILURE;
    }
    return PR_SUCCESS;
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.external,代码行数:27,代码来源:httpget.c

示例2: MimeMessage_debug_print

static int
MimeMessage_debug_print (MimeObject *obj, PRFileDesc *stream, PRInt32 depth)
{
  MimeMessage *msg = (MimeMessage *) obj;
  char *addr = mime_part_address(obj);
  int i;
  for (i=0; i < depth; i++)
  PR_Write(stream, "  ", 2);
/*
  fprintf(stream, "<%s %s%s 0x%08X>\n",
      obj->clazz->class_name,
      addr ? addr : "???",
      (msg->container.nchildren == 0 ? " (no body)" : ""),
      (PRUint32) msg);
*/
  PR_FREEIF(addr);

#if 0
  if (msg->hdrs)
  {
    char *s;

    depth++;

# define DUMP(HEADER) \
    for (i=0; i < depth; i++)                        \
        PR_Write(stream, "  ", 2);                        \
    s = MimeHeaders_get (msg->hdrs, HEADER, PR_FALSE, PR_TRUE);
/**
    \
    PR_Write(stream, HEADER ": %s\n", s ? s : "");              \
**/

    PR_FREEIF(s)

      DUMP(HEADER_SUBJECT);
      DUMP(HEADER_DATE);
      DUMP(HEADER_FROM);
      DUMP(HEADER_TO);
      /* DUMP(HEADER_CC); */
      DUMP(HEADER_NEWSGROUPS);
      DUMP(HEADER_MESSAGE_ID);
# undef DUMP

    PR_Write(stream, "\n", 1);
  }
#endif

  PR_ASSERT(msg->container.nchildren <= 1);
  if (msg->container.nchildren == 1)
  {
    MimeObject *kid = msg->container.children[0];
    int status = kid->clazz->debug_print (kid, stream, depth+1);
    if (status < 0) return status;
  }
  return 0;
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:57,代码来源:mimemsg.cpp

示例3: nt_save

/* write a nametable out into a file */
int nt_save(NameTable *nt, const char *filename)
{
    PRFileDesc *fd;
    PRUint32 i;

    fd = PR_Open(filename, PR_WRONLY|PR_CREATE_FILE, 0644);
    if (!fd) return 0;

    for (i = 0; i < nt->size; i++) {
	PR_Write(fd, nt->data[i], strlen(nt->data[i]));
	PR_Write(fd, "\n", 1);
    }
    PR_Close(fd);
    return 1;
}
开发者ID:Firstyear,项目名称:ds,代码行数:16,代码来源:nametable.c

示例4: PR_IMPLEMENT

PR_IMPLEMENT(PRUint32) PR_vfprintf(PRFileDesc* fd, const char *fmt, va_list ap)
{
    /* XXX this could be better */
    PRUint32 rv, len;
    char* msg = PR_vsmprintf(fmt, ap);
    len = strlen(msg);
#ifdef XP_OS2
    /*
     * OS/2 really needs a \r for every \n.
     * In the future we should try to use scatter-gather instead of a
     * succession of PR_Write.
     */
    if (isatty(PR_FileDesc2NativeHandle(fd))) {
        PRUint32 last = 0, idx;
        PRInt32 tmp;
        rv = 0;
        for (idx = 0; idx < len+1; idx++) {
            if ((idx - last > 0) && (('\n' == msg[idx]) || (idx == len))) {
                tmp = PR_Write(fd, msg + last, idx - last);
                if (tmp >= 0) {
                    rv += tmp;
                }
                last = idx;
            }
            /*
             * if current character is \n, and
             * previous character isn't \r, and
             * next character isn't \r
             */
            if (('\n' == msg[idx]) &&
                ((0 == idx) || ('\r' != msg[idx-1])) &&
                ('\r' != msg[idx+1])) {
                /* add extra \r */
                tmp = PR_Write(fd, "\r", 1);
                if (tmp >= 0) {
                    rv += tmp;
                }
            }
        }
    } else {
        rv = PR_Write(fd, msg, len);
    }
#else
    rv = PR_Write(fd, msg, len);
#endif
    PR_DELETE(msg);
    return rv;
}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:48,代码来源:prstdio.c

示例5: LOGD

bool
GMPStorageParent::RecvWrite(const nsCString& aRecordName,
                            const InfallibleTArray<uint8_t>& aBytes)
{
  LOGD(("%s::%s: %p record=%s", __CLASS__, __FUNCTION__, this, aRecordName.get()));

  if (mShutdown) {
    return true;
  }
  if (aBytes.Length() > GMP_MAX_RECORD_SIZE) {
    unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr);
    return true;
  }

  PRFileDesc* fd = mFiles.Get(aRecordName);
  if (!fd) {
    unused << SendWriteComplete(aRecordName, GMPGenericErr);
    return true;
  }

  // Write operations overwrite the entire record. So re-open the file
  // in truncate mode, to clear its contents.
  PR_Close(fd);
  mFiles.Remove(aRecordName);
  if (NS_FAILED(OpenStorageFile(aRecordName, mOrigin, Truncate, &fd))) {
    unused << SendWriteComplete(aRecordName, GMPGenericErr);
    return true;
  }
  mFiles.Put(aRecordName, fd);

  int32_t bytesWritten = PR_Write(fd, aBytes.Elements(), aBytes.Length());
  auto res = (bytesWritten == (int32_t)aBytes.Length()) ? GMPNoErr : GMPGenericErr;
  unused << SendWriteComplete(aRecordName, res);
  return true;
}
开发者ID:L2-D2,项目名称:gecko-dev,代码行数:35,代码来源:GMPStorageParent.cpp

示例6: db_put_dn

void
db_put_dn(char *data_dn)
{
    int ret;
	char *db_path = DATABASE;
	char *db_path_bak = DATABASE_BACK;
	PRFileInfo64 info;
	PRFileDesc *prfd;
	PRInt32 data_sz;
	char *data_dnp = NULL;

	if(db_lock == NULL){
		db_lock = PR_NewLock();
	}
	PR_Lock(db_lock);
	/* if db_path is a directory, rename it */
	ret =  PR_GetFileInfo64(db_path, &info);
	if (PR_SUCCESS == ret) {
		if (PR_FILE_DIRECTORY == info.type) {    /* directory */
			ret =  PR_GetFileInfo64(db_path_bak, &info);
			if (PR_SUCCESS == ret) {
				if (PR_FILE_DIRECTORY != info.type) {    /* not a directory */
					PR_Delete(db_path_bak);
				}
			}
			PR_Rename(db_path, db_path_bak);
		}
	}

	/* open a file */
	if ((prfd = PR_Open(db_path, PR_RDWR | PR_CREATE_FILE | PR_APPEND, 0600)) == NULL ) {
		slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
				"db: Could not open file \"%s\" for read/write; %d (%s)\n",
				db_path, PR_GetError(), slapd_pr_strerror(PR_GetError()));
		return;
	}

	data_dnp = slapi_ch_smprintf("%s\n", data_dn);
	data_sz = (PRInt32)strlen(data_dnp);

	ret = PR_Write(prfd, data_dnp, data_sz);
	if (ret == data_sz) {
		slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME,
						"db: %s: key stored.\n", data_dn);
		ret = 0;
	} else  {
		slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
				"db: Failed to store key \"%s\"; %d (%s)\n",
				data_dn, PR_GetError(), slapd_pr_strerror(PR_GetError()));
		ret = 1;
	}
    if(ret) {
		slapi_log_error(SLAPI_LOG_FATAL, DB_PLUGIN_NAME,
						"db: Error detected in db_put_dn \n");
    }
	slapi_ch_free_string(&data_dnp);
	PR_Close(prfd);
	PR_Unlock(db_lock);
	return;
}
开发者ID:ohamada,项目名称:389ds,代码行数:60,代码来源:testdbinterop.c

示例7: lock

void
EncodedBufferCache::AppendBuffer(nsTArray<uint8_t> & aBuf)
{
  MutexAutoLock lock(mMutex);
  mDataSize += aBuf.Length();

  mEncodedBuffers.AppendElement()->SwapElements(aBuf);

  if (!mTempFileEnabled && mDataSize > mMaxMemoryStorage) {
    nsresult rv = NS_OpenAnonymousTemporaryFile(&mFD);
    if (!NS_FAILED(rv)) {
      mTempFileEnabled = true;
    }
  }

  if (mTempFileEnabled) {
    // has created temporary file, write buffer in it
    for (uint32_t i = 0; i < mEncodedBuffers.Length(); i++) {
      int64_t amount = PR_Write(mFD, mEncodedBuffers.ElementAt(i).Elements(), mEncodedBuffers.ElementAt(i).Length());
      if (amount <  mEncodedBuffers.ElementAt(i).Length()) {
        NS_WARNING("Failed to write media cache block!");
      }
    }
    mEncodedBuffers.Clear();
  }

}
开发者ID:ConradIrwin,项目名称:gecko-dev,代码行数:27,代码来源:EncodedBufferCache.cpp

示例8: _PR_DumpThread

void _PR_DumpThread(PRFileDesc *fd, PRThread *thread)
{

#ifndef _PR_GLOBAL_THREADS_ONLY
    _PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x",
                   thread->id, thread, thread->priority, thread->flags);
    switch (thread->state) {
      case _PR_RUNNABLE:
      case _PR_RUNNING:
        break;
      case _PR_LOCK_WAIT:
        _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
        break;
      case _PR_COND_WAIT:
        _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
                       thread->wait.cvar, thread->sleep);
        break;
      case _PR_SUSPENDED:
        _PR_DumpPrintf(fd, " suspended");
        break;
    }
    PR_Write(fd, "\n", 1);
#endif

    /* Now call dump routine */
    if (thread->dump) {
	thread->dump(fd, thread, thread->dumpArg);
    }
}
开发者ID:Akesure,项目名称:jxcore,代码行数:29,代码来源:prdump.c

示例9: dumpCertChain

void
dumpCertChain(CERTCertificate *cert, SECCertUsage usage)
{
    CERTCertificateList *certList;
    unsigned int count = 0;

    certList = CERT_CertChainFromCert(cert, usage, PR_TRUE);
    if (certList == NULL) {
        errWarn("CERT_CertChainFromCert");
        return;
    }

    for(count = 0; count < (unsigned int)certList->len; count++) {
        char certFileName[16];
        PRFileDesc *cfd;

        PR_snprintf(certFileName, sizeof certFileName, "cert.%03d",
                    count);
        cfd = PR_Open(certFileName, PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE, 
                      0664);
        if (!cfd) {
            PR_fprintf(PR_STDOUT,
                       "Error: couldn't save cert der in file '%s'\n",
                       certFileName);
        } else {
            PR_Write(cfd,  certList->certs[count].data,  certList->certs[count].len);
            PR_Close(cfd);
            PR_fprintf(PR_STDOUT, "Cert file %s was created.\n", certFileName);
        }
    }
    CERT_DestroyCertificateList(certList);
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:32,代码来源:vfyutil.c

示例10: MimeExternalBody_debug_print

static int
MimeExternalBody_debug_print (MimeObject *obj, PRFileDesc *stream, PRInt32 depth)
{
  MimeExternalBody *bod = (MimeExternalBody *) obj;
  int i;
  char *ct, *ct2;
  char *addr = mime_part_address(obj);

  if (obj->headers)
  ct = MimeHeaders_get (obj->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
  if (bod->hdrs)
  ct2 = MimeHeaders_get (bod->hdrs, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);

  for (i=0; i < depth; i++)
  PR_Write(stream, "  ", 2);
/***
  fprintf(stream,
      "<%s %s\n"
      "\tcontent-type: %s\n"
      "\tcontent-type: %s\n"
      "\tBody:%s\n\t0x%08X>\n\n",
      obj->clazz->class_name,
      addr ? addr : "???",
      ct ? ct : "<none>",
      ct2 ? ct2 : "<none>",
      bod->body ? bod->body : "<none>",
      (PRUint32) obj);
***/
  PR_FREEIF(addr);
  PR_FREEIF(ct);
  PR_FREEIF(ct2);
  return 0;
}
开发者ID:mikeconley,项目名称:comm-central,代码行数:33,代码来源:mimeebod.cpp

示例11: mWriteFD

PollableEvent::PollableEvent()
  : mWriteFD(nullptr)
  , mReadFD(nullptr)
  , mSignaled(false)
{
  MOZ_COUNT_CTOR(PollableEvent);
  MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
  // create pair of prfiledesc that can be used as a poll()ble
  // signal. on windows use a localhost socket pair, and on
  // unix use a pipe.
#ifdef USEPIPE
  SOCKET_LOG(("PollableEvent() using pipe\n"));
  if (PR_CreatePipe(&mReadFD, &mWriteFD) == PR_SUCCESS) {
    // make the pipe non blocking. NSPR asserts at
    // trying to use SockOpt here
    PROsfd fd = PR_FileDesc2NativeHandle(mReadFD);
    int flags = fcntl(fd, F_GETFL, 0);
    (void)fcntl(fd, F_SETFL, flags | O_NONBLOCK);
    fd = PR_FileDesc2NativeHandle(mWriteFD);
    flags = fcntl(fd, F_GETFL, 0);
    (void)fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  } else {
    mReadFD = nullptr;
    mWriteFD = nullptr;
    SOCKET_LOG(("PollableEvent() pipe failed\n"));
  }
#else
  SOCKET_LOG(("PollableEvent() using socket pair\n"));
  PRFileDesc *fd[2];
  LazyInitSocket();
  if (NewTCPSocketPair(fd)) {
    mReadFD = fd[0];
    mWriteFD = fd[1];

    // compatibility with LSPs such as McAfee that assume a NSPR
    // layer for read ala the nspr Pollable Event - Bug 698882. This layer is a nop.
    PRFileDesc *topLayer =
      PR_CreateIOLayerStub(sPollableEventLayerIdentity,
                           sPollableEventLayerMethodsPtr);
    if (topLayer) {
      if (PR_PushIOLayer(fd[0], PR_TOP_IO_LAYER, topLayer) == PR_FAILURE) {
        topLayer->dtor(topLayer);
      } else {
        SOCKET_LOG(("PollableEvent() nspr layer ok\n"));
        mReadFD = topLayer;
      }
    }

  } else {
    SOCKET_LOG(("PollableEvent() socketpair failed\n"));
  }
#endif

  if (mReadFD && mWriteFD) {
    // prime the system to deal with races invovled in [dc]tor cycle
    SOCKET_LOG(("PollableEvent() ctor ok\n"));
    mSignaled = true;
    PR_Write(mWriteFD, "I", 1);
  }
}
开发者ID:MekliCZ,项目名称:positron,代码行数:60,代码来源:PollableEvent.cpp

示例12: MOZ_MTLOG

int TransportLayerPrsock::SendPacket(const unsigned char *data, size_t len) {
  MOZ_MTLOG(PR_LOG_DEBUG, LAYER_INFO << "SendPacket(" << len << ")");
  if (state_ != TS_OPEN) {
    MOZ_MTLOG(PR_LOG_DEBUG, LAYER_INFO << "Can't send packet on closed interface");
    return TE_INTERNAL;
  }

  int32_t status;
  status = PR_Write(fd_, data, len);
  if (status >= 0) {
    MOZ_MTLOG(PR_LOG_DEBUG, LAYER_INFO << "Wrote " << len << " bytes");
    return status;
  }

  PRErrorCode err = PR_GetError();
  if (err == PR_WOULD_BLOCK_ERROR) {
    MOZ_MTLOG(PR_LOG_DEBUG, LAYER_INFO << "Write blocked");
    return TE_WOULDBLOCK;
  }


  MOZ_MTLOG(PR_LOG_DEBUG, LAYER_INFO << "Write error; channel closed");
  SetState(TS_ERROR);
  return TE_ERROR;
}
开发者ID:RickEyre,项目名称:mozilla-central,代码行数:25,代码来源:transportlayerprsock.cpp

示例13: AcceptThread

static void AcceptThread(void *arg)
{
    PRIntn bytesRead;
    char dataBuf[ACCEPT_READ_BUFSIZE];
    PRFileDesc  *arSock;
    PRNetAddr   *arAddr;

    bytesRead = PR_AcceptRead( listenSock, 
        &arSock,
        &arAddr,
        dataBuf,
        ACCEPT_READ_DATASIZE,
        PR_SecondsToInterval(1));

    if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR )
        if ( debug ) printf("AcceptRead timed out\n");
    else
        if ( debug ) printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());

    while( state != AllDone )  {
        PR_Lock( ml );
        while( state != RunAcceptRead )
            PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
        if ( ++iCounter >= jitter )
            state = AllDone;
        else
            state = RunJitter;
        if ( verbose ) printf(".");
        PR_NotifyCondVar( cv );
        PR_Unlock( ml );
        PR_Write( file1, ".", 1 );
    }

    return;
} /* end AcceptThread() */
开发者ID:bringhurst,项目名称:vbox,代码行数:35,代码来源:ntioto.c

示例14: WriteToFile

static nsresult
WriteToFile(nsIFile* aPath,
            const nsCString& aFileName,
            const nsCString& aData)
{
  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_WRONLY | PR_CREATE_FILE, PR_IRWXU, &f);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  int32_t len = PR_Write(f, aData.get(), aData.Length());
  PR_Close(f);
  if (NS_WARN_IF(len < 0 || (size_t)len != aData.Length())) {
    return NS_ERROR_FAILURE;
  }

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

示例15: clientThreadFunc

static void PR_CALLBACK
clientThreadFunc(void *arg)
{
    PRUintn port = (PRUintn) arg;
    PRFileDesc *sock;
    PRNetAddr addr;
    char buf[128];
    int i;
    PRStatus sts;
    PRInt32 n;

    addr.inet.family = PR_AF_INET;
    addr.inet.port = PR_htons((PRUint16)port);
    addr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
    memset(buf, 0, sizeof(buf));
    PR_snprintf(buf, sizeof(buf), "%hu", port);

    for (i = 0; i < NUM_ITERATIONS; i++) {
	sock = PR_NewTCPSocket();
	PR_ASSERT(sock != NULL);
	
    sts = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
	PR_ASSERT(sts == PR_SUCCESS);

	n = PR_Write(sock, buf, sizeof(buf));
	PR_ASSERT(n >= 0);

	sts = PR_Close(sock);
	PR_ASSERT(sts == PR_SUCCESS);
    }
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.external,代码行数:31,代码来源:poll_nm.c


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