int select_article(struct evbuffer *buf, select_result_t *result, const select_spec_t *spec) { select_part_func sfunc; switch (spec->type) { case SELECT_TYPE_HEAD: sfunc = select_article_head; break; case SELECT_TYPE_TAIL: sfunc = select_article_tail; break; case SELECT_TYPE_PART: sfunc = select_article_part; break; default: return SELECT_EARG; } struct stat st; int ret; if ((ret = answer_file(buf, spec->filename, &st, spec->cachekey, spec->cachekey_len, spec->offset, spec->maxlen)) < 0) return ret; int sel_offset, sel_size; int len = evbuffer_get_length(buf); const char *data = (const char *) evbuffer_pullup(buf, -1); if (sfunc(data, len, &sel_offset, &sel_size, NULL) != 0 || evbuffer_slice(buf, sel_offset, sel_size) != 0) return SELECT_EUNKNOWN; if (result != NULL) { snprintf(result->cachekey, sizeof(result->cachekey), "%d-%d", (int)st.st_dev, (int)st.st_ino); result->size = st.st_size; result->sel_offset = sel_offset; result->sel_size = sel_size; } return SELECT_OK; }
int main() { //# Variable Decleration for Additions # int a = 0, b = 0, r = 0; /*# Variable Declerations for Pointers # unsigned int addr = (unsigned int) &r; //The unary operator '&' brings up address int *paddr = &r; //Make a pointer, shown by the '*', that contains the address to r # Removed as no longer needed #*/ //# Additional tfunc Declerations # //# Standard output via pass/cast # cout << "Enter two integers seperated by a space." << endl; cin >> a >> b; r = sfunc(a,b); //Casting cout << "\nThe result via passing it into a function is " << r << endl; //# Removed - was there as test # //cout << "\nThe address of this is 0x" << hex << addr << endl; //cout << "\nShowing the contents via a pointer " << *paddr << endl; //# Output via pointer method # cout << "Enter two integers seperated by a space." << endl; cin >> a >> b; tfunc(&a,&b,&r); //pass the address of a, b and r into tfunc - r so it knows where to put the result. cout << "\nThe result via pointing function is " << r << endl; //No need to cast as the result from tfunc is already in r return 0; }
int Bit2Check(Node *bit) { int i,j; double prod; double rho_p; rho_p = bit->p/(1.0-bit->p); for(j=0; j < bit->max_edge; j++){ prod=1.0; for(i=0; i<bit->max_edge; i++){ if( i == j ) continue; prod = checkmult(prod, sfunc(bit->edges[i]->d_nu)); //prod *= sfunc(bit->edges[i]->d_nu); } //bit->edges[j]->d_mu = sfunc(rho_p*prod); bit->edges[j]->d_mu = sfunc(checkmult(rho_p, prod)); } return(-1); }
double CalcNewEstimate(Node * bit){ int i; double prod = 1.0; for(i=0; i < bit->max_edge; i++){ //prod *= sfunc(bit->edges[i]->d_nu); prod = checkmult(prod, sfunc(bit->edges[i]->d_nu)); } //prod *= bit->p/(1.0-bit->p); prod = checkmult(prod, bit->p/(1.0-bit->p)); bit->u_l_hat=prod; return (bit->u_l_hat); }
RetVal LFUObjectApplyOp(LFUObject *l, LFUObjectThreadState *th_state, RetVal (*sfunc)(Object, ArgVal, int), ArgVal arg, int pid) { RetVal old_val = arg, new_val; reset_backoff(&th_state->backoff); do { old_val = l->val; // val is volatile new_val = sfunc(old_val, arg, pid); if (CAS64(&l->val, old_val, new_val) == true) break; else backoff_delay(&th_state->backoff); } while(true); return old_val; }
/*ARGSUSED1*/ void key(unsigned char key, int x, int y) { switch(key) { case 'a': afunc(); break; case 'b': bfunc(); break; case 'h': help(); break; case 's': sfunc(); break; case 't': tfunc(); break; case '4': fourfunc(); break; case '\033': exit(EXIT_SUCCESS); break; default: break; } glutPostRedisplay(); }
int func() { int fd, ret; fd = open("file.txt", O_RDWR); ret = close(fd); umask(0); fd = open("file.txt", O_RDWR); // @violation INCORRECT_PERMISSION ret = close(fd); sfunc(); // @violation INCORRECT_PERMISSION umask(077); return 0; }
SimdFunctionArg::SimdFunctionArg (const std::string &name, const FunctionCallPtr &func, const DataTypePtr &type, bool varying, SimdReg *reg) : FunctionArg (name, func, type, varying), _reg (reg), _defaultReg (0) { // Find the register associated with the parameter default value string staticName = func->name() + "$" + name; SimdFunctionCallPtr sfunc(func); SymbolInfoPtr info = sfunc->symbols().lookupSymbol( staticName ); if( info ) { _defaultReg = &SimdDataAddrPtr(info->addr())->reg(*sfunc->xContext()); } }
void KviApplication::setupFinish() { if(!g_pSetupLibrary) { qDebug("Oops! Lost the setup library?"); return; } void (*sfunc)() = (void (*)())g_pSetupLibrary->resolve("setup_finish"); if(!sfunc) { KviMessageBox::warning(__tr2qs("Oops! It looks like you have a broken distribution.\n" "The setup module does not export the \"setup_finish\" function.\n" "Trying to continue anyway...")); } sfunc(); g_pSetupLibrary->unload(); delete g_pSetupLibrary; g_pSetupLibrary = nullptr; }
void SemanticEval::declareFunction(Funcao& f) { //checa redeclaracao if(evalVariableRedeclaration(SymbolTable::GlobalScope, f.id)) { return; } Symbol sfunc(SymbolTable::GlobalScope, f.id->getText(), f.id->getLine(), true, f.return_type.primitiveType(), f.return_type.dimensions()); list< pair<int, list<RefPortugolAST> > >::iterator it = f.prim_params.begin(); for(it = f.prim_params.begin(); it != f.prim_params.end(); ++it) { sfunc.param.add((*(*it).second.begin())->getText(), (*it).first); declareVars((*it)); } list< pair< pair<int, list<int> >, list<RefPortugolAST> > >::iterator mit; for(mit = f.mt_params.begin(); mit != f.mt_params.end(); ++mit) { sfunc.param.add((*(*mit).second.begin())->getText(),(*mit).first); declareVars((*mit)); } stable.insertSymbol(sfunc, SymbolTable::GlobalScope); }
static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata ) { int c; int i; int end; const char *func = "params.c:Section() -"; i = 0; /* <i> is the offset of the next free byte in bufr[] and */ end = 0; /* <end> is the current "end of string" offset. In most */ /* cases these will be the same, but if the last */ /* character written to bufr[] is a space, then <end> */ /* will be one less than <i>. */ /* Find the end of the section. We must use mb functions for this. */ if (!FindSectionEnd(InFile)) { DEBUG(0, ("%s No terminating ']' character in section.\n", func) ); return False; } c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ /* past initial white space. */ while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ if( i > (buf->length - 2) ) { uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR(buf->data, buf->length+BUFR_INC ); if(!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; } buf->data = tb; buf->length += BUFR_INC; } /* Handle a single character other than section end. */ switch( c ) { case '\n': /* Got newline before closing ']'. */ i = Continuation( buf->data, i ); /* Check for line continuation. */ if( i < 0 ) { buf->data[end] = '\0'; DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data )); return False; } end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Continue with next line. */ break; default: /* All else are a valid name chars. */ if(isspace( c )) { /* One space per whitespace region. */ buf->data[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else { buf->data[i++] = c; end = i; c = mygetc( InFile ); } } if (AtSectionEnd(InFile)) { /* Got to the closing bracket. */ buf->data[end] = '\0'; if( 0 == end ) { /* Don't allow an empty name. */ DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return False; } if( !sfunc((char *)buf->data, userdata) ) /* Got a valid name. Deal with it. */ return False; EatComment( InFile ); /* Finish off the line. */ return True; } } /* We arrive here if we've met the EOF before the closing bracket. */ DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data )); return False; }
int show(void) { char *p; void (*cfunc)(int); void (*sfunc)(int); void (*bfunc)(int); struct natstr *natp; int tlev; char buf[1024]; int rlev; again: p = getstarg(player->argp[1], "Show what ('?' to list options)? ", buf); if (!p || !*p) return RET_SYN; if (*p == '?') { pr("bridge, item, land, news, nuke, plane, sect, ship, product, tower, updates\n"); goto again; } natp = getnatp(player->cnum); rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]); if (!player->argp[3]) { tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); if (player->god) tlev = 1000; } else { tlev = (int)atoi(player->argp[3]); if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god) tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); } if (player->god) rlev = 1000; switch (*p) { case 'b': show_bridge(99999); return RET_OK; case 't': show_tower(99999); return RET_OK; case 'i': show_item(99999); return RET_OK; case 'n': if (*(p + 1) == 'e') { show_news(99999); return RET_OK; } if (drnuke_const > MIN_DRNUKE_CONST) tlev = ((rlev / drnuke_const) > tlev ? tlev : (rlev / drnuke_const)); bfunc = show_nuke_build; cfunc = show_nuke_capab; sfunc = show_nuke_stats; break; case 'l': bfunc = show_land_build; sfunc = show_land_stats; cfunc = show_land_capab; break; case 'p': if (p[1] == 'r') { show_product(99999); return RET_OK; } bfunc = show_plane_build; sfunc = show_plane_stats; cfunc = show_plane_capab; break; case 's': if (*(p + 1) == 'e') { bfunc = show_sect_build; sfunc = show_sect_stats; cfunc = show_sect_capab; } else { bfunc = show_ship_build; sfunc = show_ship_stats; cfunc = show_ship_capab; } break; case 'u': show_updates(player->argp[2] ? atoi(player->argp[2]) : 8); return RET_OK; default: return RET_SYN; } p = getstarg(player->argp[2], "Build, stats, or capability data (b,s,c)? ", buf); if (!p || !*p) return RET_SYN; pr("Printing for tech level '%d'\n", tlev); if (*p == 'B' || *p == 'b') bfunc(tlev); else if (*p == 'C' || *p == 'c') cfunc(tlev); else if (*p == 'S' || *p == 's') sfunc(tlev); else return RET_SYN; return RET_OK; }
ssize_t _WS_send(int sendf, int sockfd, const void *buf, size_t len, int flags) { int rawlen, enclen, rlen, over, left, clen, retlen, dbufsize; int sockflags; char * target; int i; static void * (*sfunc)(), * (*sfunc2)(); if (!sfunc) sfunc = (void *(*)()) dlsym(RTLD_NEXT, "send"); if (!sfunc2) sfunc2 = (void *(*)()) dlsym(RTLD_NEXT, "write"); if ((_WS_sockfd == 0) || (_WS_sockfd != sockfd)) { // Not our file descriptor, just pass through if (sendf) { return (ssize_t) sfunc(sockfd, buf, len, flags); } else { return (ssize_t) sfunc2(sockfd, buf, len); } } DEBUG("_WS_send(%d, _, %d) called\n", sockfd, len); sockflags = fcntl(sockfd, F_GETFL, 0); dbufsize = (_WS_bufsize * 3)/4 - 2; if (len > dbufsize) { RET_ERROR(ENOMEM, "send of %d bytes is larger than send buffer\n", len); } // base64 encode and add frame markers rawlen = 0; _WS_sbuf[rawlen++] = '\x00'; enclen = b64_ntop(buf, len, _WS_sbuf+rawlen, _WS_bufsize-rawlen); if (enclen < 0) { RET_ERROR(EPROTO, "Base64 encoding error\n"); } rawlen += enclen; _WS_sbuf[rawlen++] = '\xff'; rlen = (int) sfunc(sockfd, _WS_sbuf, rawlen, flags); if (rlen <= 0) { return rlen; } else if (rlen < rawlen) { // Spin until we can send a whole base64 chunck and frame end over = (rlen - 1) % 4; left = (4 - over) % 4 + 1; // left to send DEBUG("_WS_send: rlen: %d (over: %d, left: %d), rawlen: %d\n", rlen, over, left, rawlen); rlen += left; _WS_sbuf[rlen-1] = '\xff'; i = 0; do { i++; clen = (int) sfunc(sockfd, _WS_sbuf + rlen - left, left, flags); if (clen > 0) { left -= clen; } else if (clen == 0) { MSG("_WS_send: got clen %d\n", clen); } else if (!(sockflags & O_NONBLOCK)) { MSG("_WS_send: clen %d\n", clen); return clen; } if (i > 1000000) { MSG("Could not send final part of frame\n"); } } while (left > 0); DEBUG("_WS_send: spins until finished %d\n", i); } /* * Report back the number of original characters sent, * not the raw number sent */ // Adjust for framing retlen = rlen - 2; // Adjust for base64 padding if (_WS_sbuf[rlen-1] == '=') { retlen --; } if (_WS_sbuf[rlen-2] == '=') { retlen --; } // Adjust for base64 encoding retlen = (retlen*3)/4; /* DEBUG("*** send "); for (i = 0; i < retlen; i++) { DEBUG("%u,", (unsigned char) ((char *)buf)[i]); } DEBUG(" as '%s' (%d)\n", _WS_sbuf+1, rlen); */ return (ssize_t) retlen; }
static int Section (FILE * fp, int (*sfunc) (char *)) { int p; p = eatWhitespace (fp); /* ** we've already got the '['. scan past initial ** white space */ char section[SECTION_LENGTH]; int section_length = 0; char section_finished = 0; while (!section_finished) { switch (p) { case ']' : { if (section_length == 0) { fprintf(stderr, "Empty section length\n"); return -1; break; } if (section_length == SECTION_LENGTH) { fprintf(stderr, "Section name too long\n"); return -1; } // Terminate the string section[section_length] = '\0'; section_length++; section_finished = 1; break; } case ' ' : case '\t' : { fprintf(stderr, "Unexpected whitespace in section name\n"); return -1; break; } case EOF : { fprintf(stderr, "Unexpected end of file\n"); return -1; break; } case '\n': { fprintf(stderr, "Unexpected end of file\n"); return -1; break; } default: { while (p != ']' && p != '\n' && p != ' ' && p != '\t' && p != EOF) { if (section_length == SECTION_LENGTH) { fprintf(stderr, "Section name too long\n"); } section[section_length] = p; section_length++; p = getc(fp); } // Maybe this is the end of name if (p == ' ' || p == '\t') { p = eatWhitespace(fp); } } } } /* fprintf(stderr, "[MCFG] Section -> '%s'\n", section); fprintf(stderr, "[MCFG] \n"); */ return sfunc(section); }
int gfunc (int y) { sfunc (y); }
static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) /* ------------------------------------------------------------------------ ** * Scan a section name, and pass the name to function sfunc(). * * Input: InFile - Input source. * sfunc - Pointer to the function to be called if the section * name is successfully read. * * Output: True if the section name was read and True was returned from * <sfunc>. False if <sfunc> failed or if a lexical error was * encountered. * * ------------------------------------------------------------------------ ** */ { int c; int i; int end; char *func = "params.c:Section() -"; i = 0; /* <i> is the offset of the next free byte in bufr[] and */ end = 0; /* <end> is the current "end of string" offset. In most */ /* cases these will be the same, but if the last */ /* character written to bufr[] is a space, then <end> */ /* will be one less than <i>. */ c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ /* past initial white space. */ while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ if( i > (bSize - 2) ) { bSize += BUFR_INC; bufr = Realloc( bufr, bSize ); if( NULL == bufr ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } } /* Handle a single character. */ switch( c ) { case ']': /* Found the closing bracket. */ bufr[end] = '\0'; if( 0 == end ) /* Don't allow an empty name. */ { DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return( False ); } if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */ return( False ); (void)EatComment( InFile ); /* Finish off the line. */ return( True ); case '\n': /* Got newline before closing ']'. */ i = Continuation( bufr, i ); /* Check for line continuation. */ if( i < 0 ) { bufr[end] = '\0'; DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, bufr )); return( False ); } end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); c = mygetc( InFile ); /* Continue with next line. */ break; default: /* All else are a valid name chars. */ if( isspace( c ) ) /* One space per whitespace region. */ { bufr[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else /* All others copy verbatim. */ { bufr[i++] = c; end = i; c = mygetc( InFile ); } } } /* We arrive here if we've met the EOF before the closing bracket. */ DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr )); return( False ); } /* Section */
void KviApplication::setupBegin() { //We must do the setup...ask the user.. QString szSetupLib; #ifdef KVIRC_MODULES_DIR szSetupLib = KVIRC_MODULES_DIR; #else getGlobalKvircDirectory(szSetupLib, KviApplication::Modules); #endif KviQString::ensureLastCharIs(szSetupLib, KVI_PATH_SEPARATOR_CHAR); #if defined(COMPILE_ON_WINDOWS) szSetupLib.append("kvisetup.dll"); #elif defined(COMPILE_ON_MINGW) szSetupLib.append("libkvisetup.dll"); #else szSetupLib.append("libkvisetup.so"); #endif g_pSetupLibrary = new QLibrary(szSetupLib); if(!g_pSetupLibrary->load()) { KviMessageBox::warning(__tr2qs("Oops! It looks like I can't load modules on this system.\n" "I have been looking for the %s library but I haven't been able to load it\n" "due to the following error: \"%s\"\nAborting."), szSetupLib.toUtf8().data(), g_pSetupLibrary->errorString().toUtf8().data()); #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } bool (*sfunc)() = (bool (*)())g_pSetupLibrary->resolve("setup_begin"); if(!sfunc) { KviMessageBox::warning(__tr2qs("Oops! It looks like you have a broken distribution.\n" "The setup module does not export the \"setup_begin\" function.\n" "Aborting!")); #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } bool bRet = sfunc(); if(!bRet) { #if defined(COMPILE_ON_WINDOWS) ExitProcess(-1); #elif defined(COMPILE_ON_MINGW) ExitProcess(1); #else ::exit(-1); #endif } }