int sys_malloc(int wantreturn, userptr_t retval, int nargs, primitive_val* args){ if (nargs != 1){ say(BAD_SYSCALL_ARGS, "malloc called with wrong number of arguments"); return 0; } //FIXME: strictly speaking, malloc is called with a size_t, not an int //so the following is wrong if (args[0].type != PS_INT){ say(BAD_SYSCALL_ARGS, "malloc called with non-int argument"); return 0; } if (!args[0].valid){ say(DUBIOUS_SYSCALL_INVOCATION, "argument to malloc appears invalid - unknown amount of memory allocated"); } REPTYPE(PS_INT) bytes = USERDATA_PART(args[0].value, PS_INT); if (!wantreturn){ sayf(DUBIOUS_SYSCALL_INVOCATION, "return value of malloc ignored - memory leak of %d bytes", (int)bytes); return 1;//this is OK, but stupid }else if (bytes < 0){ say(BAD_SYSCALL_ARGS, "malloc called with negative argument"); return 0; }else{ sayf(DEBUG, "mallocing %d bytes", bytes); primitive_val newmem; newmem.valid = 1; USERDATA_PART(newmem.value,PT_PTR) = pointer_to_blob(blob_alloc(bytes,0,NULL),0); newmem.type = PT_PTR; return pointer_assign(retval, newmem); } }
bool MProject::tryOpenTargetFile( long version, bool try_checkout, MComponent* comp ) { WObjectFile ot( version ); if( !ot.open( comp->filename(), OStyleWriteB ) ) { if( _checkout && try_checkout ) { if( sayf( SayInfo, SayOkCancel, "Target file '%s' is read-only. checkout? ", (const char*)comp->filename() ) == RetOk ) { if( (_RCSCli->*_checkout)( &(comp->filename()), _filename, comp->filename() ) ) { return( tryOpenTargetFile( version, false, comp ) ); } } } sayf( SayWarning, SayOk, "IDE Error: Unable to write target file '%s'", (const char*)comp->filename() ); return( false ); } else { _recursing = true; ot.writeObject( _targetIdent ); ot.writeObject( this ); ot.writeObject( comp ); _recursing = false; ot.close(); return( true ); } }
/* do the real job: * - select next file to play * - consider options */ int do_play_playlist(playlist_t *pl){ reader_data data; mpc_reader * mpc123_general_reader; int ret=0; int current=0; /* we play pl->files[current] */ if(options.random){ srand(time(NULL)); /* in case we want to use rand() */ current=rand() % pl->n_elems; /* first item to be played */ } /* main playing loop */ while(1){ if(!pl->files[current]) return 1; sayf(1, "Playing Musepack audio stream from \"%s\"...\n", pl->files[current]); data.length=0; data.curr_pos=0; if( (reader_choose_and_prepare(pl->files[current], &mpc123_general_reader, &data)) == 0){ /* play it ;) */ ret=do_play_stream(mpc123_general_reader, &data); debugf("Stream play returned [%d] %s", ret, ret ? " !!" : ""); /* clean up (close fds, etc..) */ do_cleanup_stream(mpc123_general_reader, &data); }else{ sayf(0, "Error choosing method for stream: \"%s\"\n", pl->files[current]); } /* couldn't play the stream; it's likely * we won't be able to play the next either */ if(ret) break; /* no more stuff to play? break; */ debugf("random=%d, pl->files[%d+1]=\"%s\", willstop=%d", options.random, current, pl->files[current+1], mpc123_flag_isset(MPC123_FL_STOP)); if((!options.random && !pl->files[current+1]) || mpc123_flag_isset(MPC123_FL_STOP) ) break; /* select next playlist element */ if(options.random){ current=rand() % pl->n_elems; }else{ current++; } } return 0; }
static xapi say(narrator * const N) { enter; // says the string : 40 41 42 43 44 sayf("%d", 40); says(" 41"); sayw(" 42", 3); sayf(" %d", 43); sayf(" %d", 4); sayc('4'); finally : coda; }
static int login_init_connection(struct clientinfo* clntinfo) { int ss, cs = clntinfo->clientsocket; int ret, err; if ((ret = login_mayconnect(clntinfo)) < 0) { /* the error is logged and say()ed */ return ret; } /* connect */ ss = openportname(clntinfo->destination, /* dest name */ clntinfo->destinationport, /* dest port */ /* source address */ config_get_addroption("controlserveraddress", INADDR_ANY), (struct portrangestruct*) 0); /* source port */ if (ss < 0) { err = errno; sayf(cs, "500 "ERR_STR_P2, clntinfo->destination, clntinfo->destinationport, strerror(err)); jlog(5, ERR_STR_P2, clntinfo->destination, clntinfo->destinationport, strerror(err)); return CMD_ERROR; } /* connected */ clntinfo->serversocket = ss; return CMD_HANDLED; }
int sys_putint(int wantreturn, userptr_t retval, int nargs, primitive_val* args){ if (wantreturn){ say(BAD_SYSCALL_ARGS, "putint does not return a value"); return 0; } if (nargs != 1 || args[0].type != PS_INT){ say(BAD_SYSCALL_ARGS, "putint passed bad args"); return 0; } if (!args[0].valid){ say(DUBIOUS_SYSCALL_INVOCATION, "puting passed possibly undefined value"); return 0; } sayf(USER_OUTPUT, "User output: %d", USERDATA_PART(args[0].value, PS_INT)); return 1; }
static void usage(const char *name){ version(); sayf(0, "\nUsage: %s [options] [file1 [file2 [..]]]\n\n" "Options supported:\n" " --verbose or -v Increase verbosity\n" " --quiet or -q Quiet mode (no title or boilerplate)\n" " --gain N or -g N Set gain (audio volume) to N (0-100)\n" " -o dt Set output devicetype to dt\n" " --audiodevice N or -a N Use N for audio-out\n" " --au N or -u N Use au file N for output\n" " --cdr N or -c N Use raw file N for output\n" " --wav N or -w N Use wave file N for output\n" " --list N or -@ N Use playlist N as list of Musepack files\n" " --random or -Z Play files randomly until interrupted\n" " --shuffle or -z Shuffle list of files before playing\n" " --help or -h Print this help screen\n" " --version or -V Print mpc123 version string\n", name); }
/* populate array from argv[optind], n elements */ int populate_playlist_from_argv(playlist_t * pl, char ** argv, int optind, int n){ int i=0; int sl=0; debugf("before black magic: argv[0]=\"%s\", optind=%d, n=%d", argv[0], optind, n); /* black magic */ argv=&argv[optind]; debugf("after black magic: argv[0]=\"%s\", optind=%d, n=%d", argv[0], optind, n); /* allocate main array (n elements + NULL) */ pl->files=(char **)malloc(sizeof(char*) * n+1); /* scramble playlist */ if(options.shuffle && !options.random){ i = shuffle(pl->files, n, argv); debug("shuffle done"); } else { /* otherwise just allocate and strcpy each element */ for(i=0; i<n; i++){ debugf("element \"%s\" ", argv[i]); sl=strlen(argv[i]); pl->files[i]=(char*)malloc(sl+1); strncpy(pl->files[i], argv[i], sl+1); debugf(" \"%s\"", pl->files[i]); } } pl->files[i]=NULL; /* insert info about playlist length */ pl->n_elems=i; sayf(2, "Playlist has %d elements\n", pl->n_elems); return 0; }
int handle_login(struct clientinfo* clntinfo) { struct cmdhandlerstruct *cmdhandler; char *buffer = 0; int ss, cs; int i, expected; int protoviolations = 0; conn_info.lcs = &lcs; conn_info.clntinfo = clntinfo; ss = clntinfo->serversocket; cs = clntinfo->clientsocket; if (clntinfo->transparent == TRANSPARENT_YES /* we are connected */ && config_compare_option("logintime", "connect")) { if (config_get_ioption("loginstyle", 0) != 0) { jlog(5, "A login at the connection time only works with loginstyle == 0, setting loginstyle = 0"); config_option_list_delete("loginstyle"); config_option_list_add("loginstyle", "0"); } } cmdhandler = &login_auth_funcs [ config_get_ioption("loginstyle", 0) ][0]; expected = QUITFUNC + 1; /* skip reset and quit function */ while (1) { if (timeout) { jlog(2, "Timeout in %s line %d\n", __FILE__ ,__LINE__); return -1; } if (buffer) { free(buffer); buffer = 0; } buffer = readline(cs); lcs.cmd = (char*) 0; if (buffer) { lcs.cmd = buffer; free(lcs.method); i = 0; lcs.method = quotstrtok(lcs.cmd, WHITESPACES, &i); if (buffer[0] == '\0') { /* empty line. Prevent logging of the * command */ free(buffer); buffer = 0; continue; } /* log the command */ log_cmd(&lcs); free(lcs.method); lcs.method = (char*) 0; lcs.respcode = 0; lcs.transferred = 0; } if (!buffer) { if (timeout) { jlog(2, "Timeout in %s line %d\n", __FILE__ ,__LINE__); err_time_readline(cs); } else { err_readline(cs); } return -1; } jlog(8, "Expecting %s", cmdhandler[expected].cmd); if (my_strcasestr(buffer, "PASS") == (char*) 0) { jlog(8, "Got: %s", buffer); } else { jlog(8, "Got the password"); } /* check for QUIT */ if (checkbegin(buffer, "QUIT")) { int ret = (cmdhandler[QUITFUNC].func) (buffer, &conn_info); ret = (cmdhandler[RESETFUNC].func) (buffer, &conn_info); free(buffer); /* return 1 to prevent the proxy from entering * handle_cmds */ return 1; } if (cmdhandler[expected].cmd && checkbegin(buffer, cmdhandler[expected].cmd)) { int ret = (cmdhandler[expected].func) (buffer, &conn_info); memset(buffer, 0, strlen(buffer)); protoviolations = 0; switch (ret) { case CMD_DONE: /* we're done - logged in */ /* CMD_DONE is returned if the USER * command got a 230 response back * */ break; case CMD_HANDLED: /* expecting the next */ expected++; break; case CMD_ERROR: /* reset counter, skip reset and * quit function */ ret = (cmdhandler[RESETFUNC].func) (buffer, &conn_info); expected = QUITFUNC + 1; /* errors are handled by the * command handler functions * */ break; case CMD_ABORT: return -1; break; } /* found and called proper function */ } else { protoviolations++; if (protoviolations >= config_get_ioption("loginprotocolviolations", 10)){ /* like ABORT */ sayf(clntinfo->clientsocket, "500 Too many consequent protocol " "violations - Closing connection\r\n"); return -1; } sayf(clntinfo->clientsocket, "530 Login incorrect. Expected %scommand\r\n", cmdhandler[expected].cmd); /* reset counter, skip reset and quit function */ (cmdhandler[RESETFUNC].func) (buffer, &conn_info); expected = QUITFUNC + 1; } if (clntinfo->login.stage == LOGIN_ST_FULL) { /* we are done */ free(buffer); buffer = (char*) 0; return 0; } } /* lcs.host and lcs.user are freed at the termination of the * programm */ }