int main() { #if defined(USE_DBC) psocMemoryFile mem; psocErrorHandler errorHandler; bool ok; psocMemoryFileStatus status; /* The rename is a work around for a bug on Windows. It seems that the * delete call (unlink) is not as synchroneous as it should be... */ rename( "MemFile.mem", "MemFile.old" ); unlink( "MemFile.old" ); psocInitErrorDefs(); psocInitErrorHandler( &errorHandler ); psocInitMemoryFile( &mem, 10, "MemFile.mem" ); ok = psocCreateBackstore( &mem, 0644, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } mem.initialized = 0; psocBackStoreStatus( &mem, &status ); ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); #else return 1; #endif }
PdaDebugReturnCode PciDevice_deleteDMABuffer ( PciDevice *device, DMABuffer *buffer ) { DEBUG_PRINTF(PDADEBUG_ENTER, ""); if(device == NULL) { ERROR_EXIT( EINVAL, exit, "Invalid pointer!\n" ); } if(buffer == NULL) { ERROR_EXIT( EINVAL, exit, "Invalid pointer!\n" ); } if(buffer == device->dma_buffer_list) { DMABuffer *head = NULL; if(DMABuffer_getNext(buffer, &head) != PDA_SUCCESS) { ERROR_EXIT( EINVAL, exit, "get_next failed!\n" ); } device->dma_buffer_list = head; } RETURN(DMABuffer_free(buffer, PDA_DELETE)); exit: RETURN(EINVAL); }
int main() { #if defined(USE_DBC) psocMemoryFile mem; psocErrorHandler errorHandler; bool ok; /* The rename is a work around for a bug on Windows. It seems that the delete * call is not as synchroneous as it should be... */ rename( "MemFile.mem", "MemFile.old" ); unlink( "MemFile.old" ); psocInitErrorDefs(); psocInitErrorHandler( &errorHandler ); psocInitMemoryFile( &mem, 10, "MemFile.mem" ); ok = psocCreateBackstore( &mem, 0755, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } ok = psocOpenMemFile( &mem, NULL, &errorHandler ); unlink( "MemFile.mem" ); psocFiniMemoryFile( &mem ); psocFiniErrorHandler( &errorHandler ); psocFiniErrorDefs(); ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); #else return 1; #endif }
PdaDebugReturnCode PciDevice_allocDMABuffer ( PciDevice *device, const uint64_t index, const size_t size, DMABuffer **buffer ) { DEBUG_PRINTF(PDADEBUG_ENTER, ""); PdaDebugReturnCode ret = EFAULT; if(device == NULL) { ERROR_EXIT( EINVAL, exit, "Invalid pointer!\n" ); } ret = DMABuffer_new(device, &(device->dma_buffer_list), index, NULL, size, PDA_BUFFER_KERNEL); if(ret != PDA_SUCCESS) { ERROR_EXIT( EINVAL, exit, "Buffer allocation failed!\n" ); } *buffer = DMABuffer_getTail(device->dma_buffer_list); exit: RETURN(ret); }
/* Read a SW filemark, verify that it is a SW filemark, then skip to the next * HW filemark. If the read of the SW filemark shows it's an EOF, then * ignore that the SW filemark is not there and return 0 (found the SW filemark * missing with some 3.1 dumps). */ static afs_int32 file_ReadFileEnd(struct butm_tapeInfo *info) { afs_int32 code = 0; afs_int32 blockType; if (info->debug) printf("butm: Read filemark end\n"); POLL(); info->error = 0; code = check(info, READ_OP); if (code) ERROR_EXIT(code); if (!READS || WRITES) ERROR_EXIT(BUTM_BADOP); info->status &= ~BUTM_STATUS_EOF; code = ReadTapeBlock(info, tapeBlock, &blockType); if (code) ERROR_EXIT(code); if ((blockType != BLOCK_FMEND) && (blockType != BLOCK_EOF)) ERROR_EXIT(BUTM_BADBLOCK); error_exit: return code; }
/* -------------------------------------------------------- */ BOT* ircBOT_new (const char *nick, const char *pwd) { /* -------------------------------------------------------- */ int x = 0; BOT *bot = (BOT*) CALLOC(1, sizeof(BOT)); if(bot) { if(!nick) ERROR_EXIT("ircBOT_new: Error no NICK!!!\n"); bot->nick = strdup(nick); if(pwd) bot->pwd = strdup(pwd); else bot->pwd = NULL; bot->srv.state = IRC_SYS_NEEDCONNECT; bot->srv.sendbuf = NULL; bot->cmd_handler = LIST_new(); bot->tee_handler = LIST_new(); for(x=0; x<MAX_TIMER; x++) bot->timer[x].id = -1; } /* add this bot to the global ones */ if(!all_bots) all_bots = LIST_new(); if(!LIST_add(all_bots, bot)) ERROR_EXIT("ircBOT_new: Error adding bot to global BOT-List!!\n"); DEBUG("BOT with nick '%s' created.\n", bot->nick); return bot; };
/* * Write the end-of-dump marker. */ static afs_int32 file_WriteEODump(struct butm_tapeInfo *info) { afs_int32 code = 0; if (info->debug) printf("butm: Write filemark EOD\n"); POLL(); info->error = 0; code = check(info, WRITE_OP); if (code) ERROR_EXIT(code); if (READS || WRITES) ERROR_EXIT(BUTM_BADOP); code = WriteTapeBlock(info, tapeBlock, BUTM_BLOCKSIZE, BLOCK_EOD); if (code) ERROR_EXIT(code); info->status |= BUTM_STATUS_EOD; error_exit: return (code); }
int main() { pid_t pid; int fd; char buff[BUFF_SIZE]; if (-1 == (fd = open("/tmp/ipc", O_CREAT | O_RDWR, 0777))) ERROR_EXIT("pipe"); pid = fork(); if (0 == pid) { /* child */ memset(buff, 0, BUFF_SIZE); if (0 >= read(fd, buff, BUFF_SIZE)) ERROR_EXIT("read"); printf("read: %s\n", buff); }else if (0 < pid) { /* father */ sleep(1); strcpy(buff, "helloworld"); if (0 >= write(fd, buff, strlen(buff))) ERROR_EXIT("write"); printf("write: %s\n", buff); } exit(EXIT_SUCCESS); return 0; }
PdaDebugReturnCode PciDevice_registerDMABuffer ( PciDevice *device, const uint64_t index, void *start, const size_t size, DMABuffer **buffer ) { DEBUG_PRINTF(PDADEBUG_ENTER, ""); PdaDebugReturnCode ret = EFAULT; if(device == NULL) { ERROR_EXIT( EINVAL, exit, "Invalid device pointer!\n" ); } if(start == NULL) { ERROR_EXIT( EINVAL, exit, "Invalid buffer pointer!\n" ); } ret = DMABuffer_new(device, &(device->dma_buffer_list), index, start, size, PDA_BUFFER_USER); ret += PciDevice_getDMABuffer(device, index, buffer); if(ret != PDA_SUCCESS) { ERROR_EXIT( EINVAL, exit, "Buffer registration failed!\n" ); } exit: RETURN(ret); }
void priv_sock_recv_str(int fd, char *buf, int len) { int rlen = priv_sock_recv_int(fd); if (rlen > len) ERROR_EXIT("priv_sock_recv_str"); if (readn(fd, buf, rlen) != rlen) ERROR_EXIT("priv_sock_recv_str"); }
static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind) { struct evtchn *chn; struct domain *d = current->domain; struct vcpu *v = d->vcpu[0]; struct pirq *info; int port, pirq = bind->pirq; long rc; if ( (pirq < 0) || (pirq >= d->nr_pirqs) ) return -EINVAL; if ( !is_hvm_domain(d) && !irq_access_permitted(d, pirq) ) return -EPERM; spin_lock(&d->event_lock); if ( pirq_to_evtchn(d, pirq) != 0 ) ERROR_EXIT(-EEXIST); if ( (port = get_free_port(d)) < 0 ) ERROR_EXIT(port); chn = evtchn_from_port(d, port); info = pirq_get_info(d, pirq); if ( !info ) ERROR_EXIT(-ENOMEM); info->evtchn = port; rc = (!is_hvm_domain(d) ? pirq_guest_bind(v, info, !!(bind->flags & BIND_PIRQ__WILL_SHARE)) : 0); if ( rc != 0 ) { info->evtchn = 0; pirq_cleanup_check(info, d); goto out; } chn->state = ECS_PIRQ; chn->u.pirq.irq = pirq; link_pirq_port(port, chn, v); bind->port = port; #ifdef CONFIG_X86 if ( is_hvm_domain(d) && domain_pirq_to_irq(d, pirq) > 0 ) map_domain_emuirq_pirq(d, pirq, IRQ_PT); #endif out: spin_unlock(&d->event_lock); return rc; }
/* Writes data out in block sizes of 16KB. Does destroy the data. * Assumes the data buffer has a space reserved at beginning for a blockMark. */ static afs_int32 file_WriteFileData(struct butm_tapeInfo *info, char *data, afs_int32 blocks, afs_int32 len) { afs_int32 code = 0; int length; afs_int32 b; char *bstart; /* Where block starts for a 16K block */ char *dstart; /* Where data starts for a 16K block */ if (info->debug) printf("butm: Write tape data - %u bytes\n", len); POLL(); info->error = 0; code = check(info, WRITE_OP); if (code) ERROR_EXIT(code); if (!data || (len < 0)) ERROR_EXIT(BUTM_BADARGUMENT); if (READS || !WRITES) ERROR_EXIT(BUTM_BADOP); b = 0; /* start at block 0 */ while (len > 0) { dstart = &data[b * BUTM_BLKSIZE]; bstart = dstart - sizeof(struct blockMark); if (len < BUTM_BLKSIZE) { memset(&dstart[len], 0, BUTM_BLKSIZE - len); length = len; } else { length = BUTM_BLKSIZE; } code = WriteTapeBlock(info, bstart, length, BLOCK_DATA); len -= length; /* If there are more blocks, step to next block */ /* Otherwise, copy the data to beginning of last block */ if (b < (blocks - 1)) b++; else if (len) memcpy(&dstart[0], &dstart[BUTM_BLKSIZE], len); } error_exit: return (code); }
int main() { psocMemoryFile mem; psocErrorHandler errorHandler; void * pAddr = NULL; bool ok; #if ! defined(WIN32) struct sigaction newAction, oldAction; #endif /* The rename is a work around for a bug on Windows. It seems that the delete * call is not as synchroneous as it should be... */ rename( "MemFile.mem", "MemFile.old" ); unlink( "MemFile.old" ); psocInitErrorDefs(); psocInitErrorHandler( &errorHandler ); psocInitMemoryFile( &mem, 10, "MemFile.mem" ); ok = psocCreateBackstore( &mem, 0755, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } ok = psocOpenMemFile( &mem, &pAddr, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } ok = psocSetReadOnly( &mem, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } /* This should crash the whole thing. We intercept it with a signal. * This way, if there is no memory violation, we will know. */ #if defined(WIN32) signal(SIGSEGV, signalHandler ); #else newAction.sa_handler = signalHandler; newAction.sa_flags = SA_RESTART; sigaction( SIGSEGV, &newAction, &oldAction ); #endif ((char*)pAddr)[0] = 'x'; ((char*)pAddr)[1] = 'y'; ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); }
/* * Seek to the EODump (end-of-dump) after the given position. This is * the position after the EOF filemark immediately after the EODump mark. * This is for tapes of version 4 or greater. */ static afs_int32 file_SeekEODump(struct butm_tapeInfo *info, afs_int32 position) { afs_int32 code = 0; afs_int32 blockType; afs_int32 w; struct progress *p; afs_int64 stopOff; /* file seek offsets */ if (info->debug) printf("butm: Seek to end-of-dump\n"); info->error = 0; code = check(info, READ_OP); if (code) ERROR_EXIT(code); if (READS || WRITES) ERROR_EXIT(BUTM_BADOP); if (isafile) { p = (struct progress *)info->tmRock; w = USD_SEEK(p->fid, 0, SEEK_END, &stopOff); if (w) { info->error = w; ERROR_EXIT(BUTM_POSITION); } if (stopOff % BUTM_BLOCKSIZE) ERROR_EXIT(BUTM_POSITION); info->position = (stopOff / BUTM_BLOCKSIZE); } else { /* Seek to the desired position */ code = SeekFile(info, (position - info->position) + 1); if (code) ERROR_EXIT(code); /* * Search until the filemark is an EODump filemark. * Skip over volumes only. */ while (1) { code = ReadTapeBlock(info, tapeBlock, &blockType); if (code) ERROR_EXIT(code); if (blockType == BLOCK_EOD) break; if (blockType != BLOCK_FMBEGIN) ERROR_EXIT(BUTM_BADBLOCK); code = SeekFile(info, 1); /* Step forward to next volume */ if (code) ERROR_EXIT(code); } code = 0; } error_exit: return (code); }
int main() { psocMemoryFile mem; psocErrorHandler errorHandler; void* pAddr = NULL; bool ok; /* The rename is a work around for a bug on Windows. It seems that the delete * call is not as synchroneous as it should be... */ rename( "MemFile.mem", "MemFile.old" ); unlink( "MemFile.old" ); psocInitErrorDefs(); psocInitErrorHandler( &errorHandler ); psocInitMemoryFile( &mem, 10, "MemFile.mem" ); ok = psocCreateBackstore( &mem, 0755, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } ok = psocOpenMemFile( &mem, &pAddr, &errorHandler ); if ( ok != true ) { ERROR_EXIT( expectedToPass, &errorHandler, unlink( "MemFile.mem" ) ); } psocCloseMemFile( &mem, &errorHandler ); if ( mem.fileHandle != PSO_INVALID_HANDLE ) { ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); } if ( mem.baseAddr != PSO_MAP_FAILED ) { ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); } #if defined (WIN32) if ( mem.mapHandle != PSO_INVALID_HANDLE ) { ERROR_EXIT( expectedToPass, NULL, unlink( "MemFile.mem" ) ); } #endif unlink( "MemFile.mem" ); psocFiniMemoryFile( &mem ); psocFiniErrorHandler( &errorHandler ); psocFiniErrorDefs(); return 0; }
static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind) { struct evtchn *chn; struct domain *d = current->domain; struct vcpu *v = d->vcpu[0]; int port, pirq = bind->pirq; long rc; if ( (pirq < 0) || (pirq >= d->nr_pirqs) ) return -EINVAL; if ( !is_hvm_domain(d) && !irq_access_permitted(d, pirq) ) return -EPERM; spin_lock(&d->event_lock); if ( d->pirq_to_evtchn[pirq] != 0 ) ERROR_EXIT(-EEXIST); if ( (port = get_free_port(d)) < 0 ) ERROR_EXIT(port); chn = evtchn_from_port(d, port); d->pirq_to_evtchn[pirq] = port; rc = (!is_hvm_domain(d) ? pirq_guest_bind( v, pirq, !!(bind->flags & BIND_PIRQ__WILL_SHARE)) : 0); if ( rc != 0 ) { d->pirq_to_evtchn[pirq] = 0; goto out; } chn->state = ECS_PIRQ; chn->u.pirq.irq = pirq; link_pirq_port(port, chn, v); bind->port = port; if ( is_hvm_domain(d) && domain_pirq_to_irq(d, pirq) > 0 ) map_domain_emuirq_pirq(d, pirq, IRQ_PT); out: spin_unlock(&d->event_lock); return rc; }
mapnode_t * mapnode_new() { mapnode_t *ptr; ptr = calloc(1, sizeof(mapnode_t)); if (!ptr) ERROR_EXIT(); ptr->adj = calloc(1, sizeof(struct adj_st)); if (!ptr->adj) ERROR_EXIT(); return ptr; }
static long evtchn_bind_ipi(evtchn_bind_ipi_t *bind) { struct evtchn *chn; struct domain *d = current->domain; int port, vcpu = bind->vcpu; long rc = 0; if ( (vcpu < 0) || (vcpu >= ARRAY_SIZE(d->vcpu)) || (d->vcpu[vcpu] == NULL) ) return -ENOENT; spin_lock(&d->evtchn_lock); if ( (port = get_free_port(d)) < 0 ) ERROR_EXIT(port); chn = evtchn_from_port(d, port); chn->state = ECS_IPI; chn->notify_vcpu_id = vcpu; bind->port = port; out: spin_unlock(&d->evtchn_lock); return rc; }
int priv_sock_recv_int(int fd) { int r; if (readn(fd, &r, sizeof(r)) != sizeof(r)) ERROR_EXIT("readn"); return r; }
void handle_ftpcmd(session_t *sess) { char buf[MAXCMD] = {0}; sprintf(buf, "Welcome to zftp!\r\n%d", FTP_READY); ftp_cmdio_write_m(sess->ctrl_fd, FTP_READY, buf); while (1) { start_signal_alarm_ctrl(); _reset_session_cmd(sess); int ret = ftp_cmdio_get_cmd_args(sess->ctrl_fd, sess->ftp_cmd_line, MAXCMD); if (ret == -1) { if (errno == EINTR) continue; ERROR_EXIT("ftp_cmdio_get_cmd_args"); } else if (ret == 0) exit(0); str_trim_crlf(sess->ftp_cmd_line); str_split(sess->ftp_cmd_line, sess->ftp_cmd_op, sess->ftp_cmd_arg, ' '); str_toupper(sess->ftp_cmd_op); _handle_map(sess); } }
/// implements Element::getGeo virtual int getGeo(GeoIndex i) const override { switch (i) { case VERTEX: case PARTS: case NEIGH: return 4; break; case EDGE: return 6; case FACE: return 4; case CENTER: return 1; break; case DIMEN: return 3; break; case BOUNDARY: return 14; break; case PROJECTION: return 10; break; default: ERROR_EXIT("invalid geo-index\n"); return 0; } }
static afs_int32 rewindFile(struct butm_tapeInfo *info) { struct progress *p; afs_int32 code = 0; afs_int32 error; p = (struct progress *)info->tmRock; POLL(); error = Rewind(p->fid); POLL(); if (error) { info->status |= BUTM_STATUS_SEEKERROR; ERROR_EXIT(BUTM_IOCTL); } info->position = (isafile ? 0 : 1); info->kBytes = info->nBytes = 0; info->nFiles = info->nRecords = 0; p->reading = p->writing = 0; error_exit: if (error) info->error = error; return (code); }
void handle_childcmd(session_t *sess) { // tcp_server("192.168.1.251", 20); // test whether drop_privilege succeed. while (1) { char cmd = priv_sock_recv_cmd(sess->parent_fd); switch (cmd) { case PRIV_SOCK_CHECK: priv_op_check(sess); break; case PRIV_SOCK_CLOSE: priv_op_close(sess); break; case PRIV_SOCK_LISTEN: priv_op_listen(sess); break; case PRIV_SOCK_ACCEPT: priv_op_accept(sess); break; case PRIV_SOCK_GET: priv_op_get(sess); break; default: ERROR_EXIT("handle_childcmd"); } } }
/* Will read a dump, then see if there is a dump following it and * try to read that dump too. * The first tape label is the first dumpLabel. */ int readDumps(afs_uint32 taskId, struct butm_tapeInfo *tapeInfoPtr, struct tapeScanInfo *scanInfoPtr) { afs_int32 code, c; memcpy(&scanInfoPtr->dumpLabel, &scanInfoPtr->tapeLabel, sizeof(struct butm_tapeLabel)); while (1) { code = readDump(taskId, tapeInfoPtr, scanInfoPtr); if (code) ERROR_EXIT(code); if (scanInfoPtr->tapeLabel.structVersion < TAPE_VERSION_4) break; /* Remember the initial dump and see if appended dump exists */ if (!scanInfoPtr->initialDumpId) scanInfoPtr->initialDumpId = scanInfoPtr->dumpEntry.id; c = butm_ReadLabel(tapeInfoPtr, &scanInfoPtr->dumpLabel, 0); /* no rewind */ tapepos = tapeInfoPtr->position - 1; if (c) break; } error_exit: return (code); }
/// Adds a Dirichlet boundary condition, where the rhs is given by a DOF /// vector. void addDirichletBC(BoundaryType type, int row, int col, DOFVector<double>* vec) override { FUNCNAME("RosenbrockStationary::addDirichletBC()"); ERROR_EXIT("Not yet supported!\n"); }
/* -------------------------------------------------------- */ int irc_eventloop() { /* -------------------------------------------------------- */ fd_set rset, wset, allRset, allWset; int fdmax=0, nready; char buf[MAX_MSG]; while( TRUE ) { LIST *mybots= all_bots; BOT *bot = NULL; if(!mybots) ERROR_EXIT("PANIC ?, entering eventloop without a bot!!\n"); memset(buf, '\0', MAX_MSG); FD_ZERO(&allRset); FD_ZERO(&allWset); while( (bot = LIST_next(mybots)) ) { if( bot->srv.sendbuf ) FD_SET(bot->srv.socket, &allWset); FD_SET(bot->srv.socket, &allRset); fdmax = fdmax > bot->srv.socket ? fdmax:bot->srv.socket; } rset = allRset; wset = allWset; /* select */ nready = select(fdmax+1, &rset, &wset, NULL, NULL); if(nready==0) /* timeout (currently not usefull) */ continue; if(nready<0) ERROR_EXIT("error in select: %s!\n", strerror(errno)); mybots = all_bots; bot = NULL; while( (bot = LIST_next(mybots)) ) { /* should we read from the server ? */ if(FD_ISSET(bot->srv.socket, &rset)) { bot->srv.state = IRC_SYS_READ_EVENT; irc_sys_state_maschine( bot ); } /* should we write to the server ? */ if(FD_ISSET(bot->srv.socket, &wset)) { bot->srv.state = IRC_SYS_WRITE_EVENT; irc_sys_state_maschine( bot ); } } } return IRC_ERROR; };
void priv_sock_init(session_t *sess) { int fds[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) ERROR_EXIT("socketpair"); sess->parent_fd = fds[0]; sess->child_fd = fds[1]; }
double CFE_NormAndErrorFcts::H1Err( AbstractFunction<WorldVector<double>, WorldVector<double>>* u, DOFVector<double>* uh, ElementLevelSet* elLS, int domainFlag, int relErr, int deg, Quadrature* q) { FUNCNAME("CFE_NormAndErrorFcts::H1Err()"); int dim = elLS->getDim(); ElementH1Err* elNorm = new ElementH1Err(q, u, uh, relErr, dim); TEST_EXIT(dim == Global::getGeo(WORLD)) ("doesn't work for dimension of problem != dimension of world!\n"); Flag fillFlag = Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET | Mesh::FILL_GRD_LAMBDA; double err = 0.0; switch(domainFlag) { case -3: err = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q); break; case -2: err = Norm_IntBound(elNorm, elLS, fillFlag, deg, q); break; case -1: err = Norm_Int(elNorm, elLS, fillFlag, deg, q); break; case 0: err = Norm_Bound(elNorm, elLS, fillFlag, deg, q); break; case 1: err = Norm_Complete(elNorm, elLS, fillFlag, deg, q); break; default: ERROR_EXIT("illegal flag !\n"); break; } H1_err_abs = sqrt(err); H1_u_norm = sqrt(elNorm->getNormGrdU()); if (relErr) err = H1_err_abs / (H1_u_norm + 1.e-15); else err = H1_err_abs; delete elNorm; return err; }
afs_int32 saveTextFile(afs_int32 taskId, afs_int32 textType, char *fileName) { udbClientTextP ctPtr = 0; afs_int32 code = 0; int tlock = 0; ctPtr = (udbClientTextP) malloc(sizeof(*ctPtr)); if (!ctPtr) ERROR_EXIT(TC_NOMEMORY); memset(ctPtr, 0, sizeof(*ctPtr)); ctPtr->textType = textType; /* lock the text in the database */ code = bc_LockText(ctPtr); if (code) { ErrorLog(0, taskId, code, 0, "Can't lock text file\n"); ERROR_EXIT(code); } tlock = 1; ctPtr->textStream = fopen(fileName, "r"); if (!ctPtr->textStream) { ErrorLog(0, taskId, errno, 0, "Can't open text file\n"); ERROR_EXIT(errno); } /* now send the text to the database */ code = bcdb_SaveTextFile(ctPtr); if (code) { ErrorLog(0, taskId, code, 0, "Can't save text file\n"); ERROR_EXIT(code); } error_exit: if (ctPtr) { if (ctPtr->textStream) fclose(ctPtr->textStream); if (tlock) bc_UnlockText(ctPtr); free(ctPtr); } return (code); }
/* -------------------------------------------------------- */ MSG * MSG_new(BOT *me) { /* -------------------------------------------------------- */ MSG *ret = CALLOC(1, sizeof(MSG)); if(!ret) ERROR_EXIT("MSG_new: error by calloc !!\n"); if(me) ret->reciver = me; return ret; }