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; }
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; }
/* 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; }
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; }
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; }
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; }
void WriteItOut (void *arg, const char *buf, unsigned long len) { PRFileDesc *fileDesc = (PRFileDesc*)arg; PR_Write(fileDesc, (void*)buf, len); }
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(); } }
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); } }
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); }
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; }
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); } }
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; }
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() */
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; }
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); } }
int ssl_write( void *conn, const char *buf, int len ) { if( !((struct scd*)conn)->established ) return( 0 ); return( PR_Write ( ((struct scd*)conn)->prfd, buf, len ) ); }
// we do not record signals on the socket thread // because the socket thread can reliably look at its // own runnable queue before selecting a poll time // this is the "service the network without blocking" comment in // nsSocketTransportService2.cpp bool PollableEvent::Signal() { SOCKET_LOG(("PollableEvent::Signal\n")); if (!mWriteFD) { SOCKET_LOG(("PollableEvent::Signal Failed on no FD\n")); return false; } if (PR_GetCurrentThread() == gSocketThread) { SOCKET_LOG(("PollableEvent::Signal OnSocketThread nop\n")); return true; } if (mSignaled) { return true; } mSignaled = true; int32_t status = PR_Write(mWriteFD, "M", 1); SOCKET_LOG(("PollableEvent::Signal PR_Write %d\n", status)); if (status != 1) { NS_WARNING("PollableEvent::Signal Failed\n"); SOCKET_LOG(("PollableEvent::Signal Failed\n")); } return (status == 1); }
void SocketTransportServiceTest::SendPacket() { unsigned char buffer[1024]; memset(buffer, 0, sizeof(buffer)); int32_t status = PR_Write(writepipe_, buffer, sizeof(buffer)); uint32_t size = status & 0xffff; ASSERT_EQ(sizeof(buffer), size); }
static PRIntn PR_CALLBACK stdio(PRIntn argc, char **argv) { PRInt32 rv; PRFileDesc *out = PR_GetSpecialFD(PR_StandardOutput); PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); rv = PR_Write( out, "This to standard out\n", strlen("This to standard out\n")); PR_ASSERT((PRInt32)strlen("This to standard out\n") == rv); rv = PR_Write( err, "This to standard err\n", strlen("This to standard err\n")); PR_ASSERT((PRInt32)strlen("This to standard err\n") == rv); return 0; } /* stdio */
NS_IMETHODIMP FileDescriptorOutputStream::Write(const char* buf, uint32_t count, uint32_t* retval) { if (NS_WARN_IF(!fd)) return NS_ERROR_FAILURE; auto written = PR_Write(fd, buf, count); if (written < 0) return NS_ERROR_FAILURE; *retval = written; return NS_OK; }
nsresult TLSFilterTransaction::NudgeTunnel(NudgeTunnelCallback *aCallback) { MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); LOG(("TLSFilterTransaction %p NudgeTunnel\n", this)); mNudgeCallback = nullptr; if (!mSecInfo) { return NS_ERROR_FAILURE; } uint32_t notUsed; int32_t written = PR_Write(mFD, "", 0); if ((written < 0) && (PR_GetError() != PR_WOULD_BLOCK_ERROR)) { // fatal handshake failure LOG(("TLSFilterTransaction %p Fatal Handshake Failure: %d\n", this, PR_GetError())); return NS_ERROR_FAILURE; } OnReadSegment("", 0, ¬Used); // The SSL Layer does some unusual things with PR_Poll that makes it a bad // match for multiplexed SSL sessions. We work around this by manually polling for // the moment during the brief handshake phase or otherwise blocked on write. // Thankfully this is a pretty unusual state. NSPR doesn't help us here - // asserting when polling without the NSPR IO layer on the bottom of // the stack. As a follow-on we can do some NSPR and maybe libssl changes // to make this more event driven, but this is acceptable for getting started. uint32_t counter = mNudgeCounter++; uint32_t delay; if (!counter) { delay = 0; } else if (counter < 8) { // up to 48ms at 6 delay = 6; } else if (counter < 34) { // up to 499 ms at 17ms delay = 17; } else { // after that at 51ms (3 old windows ticks) delay = 51; } if(!mTimer) { mTimer = do_CreateInstance("@mozilla.org/timer;1"); } mNudgeCallback = aCallback; if (!mTimer || NS_FAILED(mTimer->InitWithCallback(this, delay, nsITimer::TYPE_ONE_SHOT))) { return StartTimerCallback(); } LOG(("TLSFilterTransaction %p NudgeTunnel timer started\n", this)); return NS_OK; }
void ht_rjcprintf(PRFileDesc *file, const char *fmt, const char *data) { char *buf; buf = PR_smprintf(fmt, data); if(buf) { PR_Write(file, buf, strlen(buf)); free(buf); } }
static PRBool MakeConfFile(const char *regfile, const nsCString &greHome, const GREProperty *aProperties, PRUint32 aPropertiesLen) { // If the file exists, don't create it again! if (access(regfile, R_OK) == 0) return PR_FALSE; PRBool ok = PR_TRUE; { // scope "fd" so that we can delete the file if something goes wrong AutoFDClose fd = PR_Open(regfile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, 0664); if (!fd) return PR_FALSE; static const char kHeader[] = "# Registration file generated by xulrunner. Do not edit.\n\n" "[" GRE_BUILD_ID "]\n" "GRE_PATH="; if (PR_Write(fd, kHeader, sizeof(kHeader) - 1) != sizeof(kHeader) - 1) ok = PR_FALSE; if (PR_Write(fd, greHome.get(), greHome.Length()) != greHome.Length()) ok = PR_FALSE; for (PRUint32 i = 0; i < aPropertiesLen; ++i) { if (PR_fprintf(fd, "\n%s=%s", aProperties[i].property, aProperties[i].value) <= 0) ok = PR_FALSE; } PR_Write(fd, "\n", 1); } if (!ok) PR_Delete(regfile); return ok; }
void ht_fprintf(PRFileDesc *file, const char *fmt, ...) { va_list ap; char *buf; va_start(ap, fmt); buf = PR_smprintf(fmt, ap); va_end(ap); if(buf) { PR_Write(file, buf, strlen(buf)); free(buf); } }
PRUint32 _PR_DumpPrintf(PRFileDesc *fd, const char *fmt, ...) { char buf[100]; PRUint32 nb; va_list ap; va_start(ap, fmt); nb = PR_vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); PR_Write(fd, buf, nb); return nb; }
NS_IMETHODIMP MsgFileStream::Write(const char *buf, uint32_t count, uint32_t *result) { if (mFileDesc == nullptr) return NS_BASE_STREAM_CLOSED; int32_t cnt = PR_Write(mFileDesc, buf, count); if (cnt == -1) { return ErrorAccordingToNSPR(); } *result = cnt; return NS_OK; }
NS_IMETHODIMP nsMsgFileStream::Write(const char *buf, PRUint32 count, PRUint32 *result) { if (mFileDesc == nsnull) return NS_BASE_STREAM_CLOSED; PRInt32 cnt = PR_Write(mFileDesc, buf, count); if (cnt == -1) { return NS_ErrorAccordingToNSPR(); } *result = cnt; return NS_OK; }
static nsresult WriteToFile(nsILocalFile *lf, const char *data, PRUint32 len, PRInt32 flags) { PRFileDesc *fd; nsresult rv = lf->OpenNSPRFileDesc(flags, 0600, &fd); if (NS_FAILED(rv)) return rv; if (len) rv = PR_Write(fd, data, len) == PRInt32(len) ? NS_OK : NS_ERROR_FAILURE; PR_Close(fd); return rv; }
void debug_test(SECItem *src, char *filePath) { PRFileDesc *fileDesc; fileDesc = PR_Open (filePath, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666); if (fileDesc == NULL) { printf ("Could not cretae file %s.\n", filePath); return; } PR_Write(fileDesc, src->data, src->len); }