void read_master(int fail_on_open_error) { const char *myname = "read_master"; char *path; VSTRING *buf; VSTREAM *fp; const char *err; int entry_count = 0; int line_count = 0; /* * Sanity check. */ if (master_table != 0) msg_panic("%s: master table is already initialized", myname); /* * Get the location of master.cf. */ if (var_config_dir == 0) set_config_dir(); path = concatenate(var_config_dir, "/", MASTER_CONF_FILE, (char *) 0); /* * Initialize the in-memory master table. */ master_table = (PC_MASTER_ENT *) mymalloc(sizeof(*master_table)); /* * Skip blank lines and comment lines. Degrade gracefully if master.cf is * not available, and master.cf is not the primary target. */ if ((fp = vstream_fopen(path, O_RDONLY, 0)) == 0) { if (fail_on_open_error) msg_fatal("open %s: %m", path); msg_warn("open %s: %m", path); } else { buf = vstring_alloc(100); while (readlline(buf, fp, &line_count) != 0) { master_table = (PC_MASTER_ENT *) myrealloc((char *) master_table, (entry_count + 2) * sizeof(*master_table)); if ((err = parse_master_line(master_table + entry_count, STR(buf))) != 0) msg_fatal("file %s: line %d: %s", path, line_count, err); entry_count += 1; } vstream_fclose(fp); vstring_free(buf); } /* * Null-terminate the master table and clean up. */ master_table[entry_count].argv = 0; myfree(path); }
void copyFiles(char* srcFolder, char* destFolder) { char* tmpPath = concatenate(bdoRootFolder,"tmp\\"); moveFiles(srcFolder,tmpPath); systemCopy("*",tmpPath,destFolder); moveFiles(tmpPath,srcFolder); char rdCommand[256]; sprintf(rdCommand, "rd /s /q \"%s\"", tmpPath); system(rdCommand); }
pio_status_t pio_open(struct pio_file_t *plink_file, const char *plink_file_prefix) { int error = 0; int num_samples = 0; int num_loci = 0; char *fam_path = concatenate( plink_file_prefix, ".fam" ); char *bim_path = concatenate( plink_file_prefix, ".bim" ); char *bed_path = concatenate( plink_file_prefix, ".bed" ); pio_status_t status = pio_open_ex( plink_file, fam_path, bim_path, bed_path ); free( fam_path ); free( bim_path ); free( bed_path ); return status; }
PassRefPtr<SVGTransform> SVGTransformList::consolidate() { AffineTransform matrix; if (!concatenate(matrix)) return SVGTransform::create(); RefPtr<SVGTransform> transform = SVGTransform::create(matrix); clear(); return appendItem(transform); }
void dot_unlockfile(const char *path) { char *lock_file; int saved_errno = errno; lock_file = concatenate(path, ".lock", (char *) 0); (void) unlink(lock_file); myfree(lock_file); errno = saved_errno; }
VectorRecord VectorRecord::concatenate( const VectorRecord& inLHS, const VectorRecord& inRHS, MemoryPool* inPool, VectorDataManager* inVDM, hash_type inVectorHash ) { if (!inLHS) return inRHS; if (!inRHS) return inLHS; if (!inLHS.isCanonicallySliced()) return concatenate( inLHS.canonicallySliced(inPool, inVDM, inVectorHash + hash_type(0, 1, 0)), inRHS, inPool, inVDM, inVectorHash ); if (!inRHS.isCanonicallySliced()) return concatenate( inLHS, inRHS.canonicallySliced(inPool, inVDM, inVectorHash + hash_type(0, 2, 0)), inPool, inVDM, inVectorHash ); return VectorRecord( VectorHandle::concatenate( inLHS.mDataPtr, inLHS.mSize, inRHS.mDataPtr, inRHS.mSize, inPool, inVDM, inVectorHash ) ); }
static void smtp_chat_append(SMTP_SESSION *session, const char *direction, const char *data) { char *line; if (session->history == 0) session->history = argv_alloc(10); line = concatenate(direction, data, (char *) 0); argv_add(session->history, line, (char *) 0); myfree(line); }
SVGTransform SVGTransformList::consolidate() { AffineTransform matrix; if (!concatenate(matrix)) return SVGTransform(); SVGTransform transform(matrix); clear(); append(transform); return transform; }
static void pcf_normalize_daemon_args(ARGV *argv) { int field; char *arg; char *cp; char *junk; int extract_field; /* * Normalize options to simplify later processing. */ for (field = PCF_MASTER_MIN_FIELDS; argv->argv[field] != 0; field++) { arg = argv->argv[field]; if (arg[0] != '-' || strcmp(arg, "--") == 0) break; for (cp = arg + 1; *cp; cp++) { if (strchr(pcf_daemon_options_expecting_value, *cp) != 0 && cp > arg + 1) { /* Split "-stuffozz" into "-stuff" and "-ozz". */ junk = concatenate("-", cp, (char *) 0); argv_insert_one(argv, field + 1, junk); myfree(junk); *cp = 0; /* XXX argv_replace_one() */ break; } } if (strchr(pcf_daemon_options_expecting_value, arg[1]) == 0) /* Option requires no value. */ continue; if (arg[2] != 0) { /* Split "-oname=value" into "-o" "name=value". */ argv_insert_one(argv, field + 1, arg + 2); arg[2] = 0; /* XXX argv_replace_one() */ field += 1; extract_field = (argv->argv[field][0] == CHARS_BRACE[0]); } else if (argv->argv[field + 1] != 0) { /* Already in "-o" "name=value" form. */ field += 1; extract_field = (argv->argv[field][0] == CHARS_BRACE[0]); } else extract_field = 0; /* Extract text inside {}, optionally convert to name=value. */ if (extract_field) { pcf_extract_field(argv, field, CHARS_BRACE); if (argv->argv[field - 1][1] == 'o') pcf_normalize_nameval(argv, field); } } /* Normalize non-option arguments. */ for ( /* void */ ; argv->argv[field] != 0; field++) /* Extract text inside {}. */ if (argv->argv[field][0] == CHARS_BRACE[0]) pcf_extract_field(argv, field, CHARS_BRACE); }
void MsDrbg::reseed(biglong& intenal_state, const size_t byte_len, const string& additional_input_string) { unsigned char* entropy_input = get_entropy(byte_len); unsigned char* internal_bytes = nullptr; size_t internal_size = intenal_state.get_raw_bytes(internal_bytes); unsigned char* internal_entropy_bytes = concatenate(internal_bytes, internal_size, entropy_input, byte_len); size_t internal_entropy_size = internal_size + byte_len; delete[] entropy_input; delete[] internal_bytes; unsigned char* internal_entropy_additional_bytes = concatenate(internal_entropy_bytes, internal_entropy_size, additional_input_string.c_str(), additional_input_string.length()); size_t internal_entropy_additional_size = internal_entropy_size + additional_input_string.length(); delete[] internal_entropy_bytes; intenal_state = hash_df_hex(internal_entropy_additional_bytes, internal_entropy_additional_size, byte_len); delete[] internal_entropy_additional_bytes; }
void concatenate(string &s, unordered_set<string> &dict, vector<vector<int> > &match, int cur_index, string cur_s) { for (int i = 0; i < match[cur_index].size(); i++) { int start = match[cur_index][i]; if (start == 0) { r.push_back(s.substr(0, cur_index + 1) + cur_s); } else { concatenate(s, dict, match, start - 1, " " + s.substr(start, cur_index - start + 1) + cur_s); } } }
static DICT *dict_cdbq_open(const char *path, int dict_flags) { DICT_CDBQ *dict_cdbq; struct stat st; char *cdb_path; int fd; cdb_path = concatenate(path, CDB_SUFFIX, (char *) 0); if ((fd = open(cdb_path, O_RDONLY)) < 0) return (dict_surrogate(DICT_TYPE_CDB, path, O_RDONLY, dict_flags, "open database %s: %m", cdb_path)); dict_cdbq = (DICT_CDBQ *) dict_alloc(DICT_TYPE_CDB, cdb_path, sizeof(*dict_cdbq)); #if defined(TINYCDB_VERSION) if (cdb_init(&(dict_cdbq->cdb), fd) != 0) msg_fatal("dict_cdbq_open: unable to init %s: %m", cdb_path); #else cdb_init(&(dict_cdbq->cdb), fd); #endif dict_cdbq->dict.lookup = dict_cdbq_lookup; dict_cdbq->dict.close = dict_cdbq_close; dict_cdbq->dict.stat_fd = fd; if (fstat(fd, &st) < 0) msg_fatal("dict_dbq_open: fstat: %m"); dict_cdbq->dict.mtime = st.st_mtime; dict_cdbq->dict.owner.uid = st.st_uid; dict_cdbq->dict.owner.status = (st.st_uid != 0); close_on_exec(fd, CLOSE_ON_EXEC); /* * Warn if the source file is newer than the indexed file, except when * the source file changed only seconds ago. */ if (stat(path, &st) == 0 && st.st_mtime > dict_cdbq->dict.mtime && st.st_mtime < time((time_t *) 0) - 100) msg_warn("database %s is older than source file %s", cdb_path, path); /* * If undecided about appending a null byte to key and value, choose to * try both in query mode. */ if ((dict_flags & (DICT_FLAG_TRY1NULL | DICT_FLAG_TRY0NULL)) == 0) dict_flags |= DICT_FLAG_TRY0NULL | DICT_FLAG_TRY1NULL; dict_cdbq->dict.flags = dict_flags | DICT_FLAG_FIXED; if (dict_flags & DICT_FLAG_FOLD_FIX) dict_cdbq->dict.fold_buf = vstring_alloc(10); myfree(cdb_path); return (&dict_cdbq->dict); }
SMTP_SESSION *smtp_session_alloc(VSTREAM *stream, SMTP_ITERATOR *iter, time_t start, int flags) { SMTP_SESSION *session; const char *host = STR(iter->host); const char *addr = STR(iter->addr); unsigned port = iter->port; session = (SMTP_SESSION *) mymalloc(sizeof(*session)); session->stream = stream; session->iterator = iter; session->namaddr = concatenate(host, "[", addr, "]", (char *) 0); session->helo = 0; session->port = port; session->features = 0; session->size_limit = 0; session->error_mask = 0; session->buffer = vstring_alloc(100); session->scratch = vstring_alloc(100); session->scratch2 = vstring_alloc(100); smtp_chat_init(session); session->mime_state = 0; if (session->port) { vstring_sprintf(session->buffer, "%s:%d", session->namaddr, ntohs(session->port)); session->namaddrport = mystrdup(STR(session->buffer)); } else session->namaddrport = mystrdup(session->namaddr); session->send_proto_helo = 0; if (flags & SMTP_MISC_FLAG_CONN_STORE) CACHE_THIS_SESSION_UNTIL(start + var_smtp_reuse_time); else DONT_CACHE_THIS_SESSION; session->reuse_count = 0; USE_NEWBORN_SESSION; /* He's not dead Jim! */ #ifdef USE_SASL_AUTH smtp_sasl_connect(session); #endif #ifdef USE_TLS session->tls_context = 0; session->tls_retry_plain = 0; session->tls_nexthop = 0; #endif session->state = 0; debug_peer_check(host, addr); return (session); }
pio_status_t pio_transpose(const char *plink_file_prefix, const char *transposed_file_prefix) { struct pio_file_t plink_file; if( pio_open( &plink_file, plink_file_prefix ) != PIO_OK ) { return PIO_ERROR; } char *bed_path = concatenate( plink_file_prefix, ".bed" ); char *transposed_bed_path = concatenate( transposed_file_prefix, ".bed" ); pio_status_t status = bed_transpose( bed_path, transposed_bed_path, pio_num_loci( &plink_file ), pio_num_samples( &plink_file ) ); if( status == PIO_OK ) { char *fam_path = concatenate( plink_file_prefix, ".fam" ); char *transposed_fam_path = concatenate( transposed_file_prefix, ".fam" ); file_copy( fam_path, transposed_fam_path ); free( fam_path ); free( transposed_fam_path ); char *bim_path = concatenate( plink_file_prefix, ".bim" ); char *transposed_bim_path = concatenate( transposed_file_prefix, ".bim" ); file_copy( bim_path, transposed_bim_path ); free( bim_path ); free( transposed_bim_path ); } pio_close( &plink_file ); free( bed_path ); free( transposed_bed_path ); return status; }
inline void mov_int32(int32 *value, int32 *rvalue, char pop_symbol) { /* integer transfer function */ if(pop_symbol) { /* perform post-evaluation operations*/ switch(pop_symbol) { case '*': *value *= *rvalue; break; case '/': *value /= *rvalue; break; case '+': *value += *rvalue; break; case '-': *value -= *rvalue; break; case '%': *value %= *rvalue; break; case '&': *value &= *rvalue; break; case '|': *value |= *rvalue; break; case '<': *value<<= *rvalue; break; case '>': *value>>= *rvalue; break; case '~': *value = ~*rvalue; break; case '!': *value = factorial(*rvalue); break; case '^': *value = (int32)pow(*value,*rvalue); break; case '=': *value = labs(*rvalue); break; case ':': concatenate(value,*rvalue); break; default: *value = *rvalue; } } else /* there is no post-evaluation operator */
long get_mail_conf_long2(const char *name1, const char *name2, long defval, long min, long max) { long longval; char *name; name = concatenate(name1, name2, (char *) 0); if (convert_mail_conf_long(name, &longval) == 0) set_mail_conf_long(name, longval = defval); check_mail_conf_long(name, longval, min, max); myfree(name); return (longval); }
/* Check whether we have or could make a directory for history files. */ bool have_statedir(void) { struct stat dirstat; const char *xdgdatadir; get_homedir(); if (homedir != NULL) { statedir = concatenate(homedir, "/.nano/"); if (stat(statedir, &dirstat) == 0 && S_ISDIR(dirstat.st_mode)) { poshistname = concatenate(statedir, POSITION_HISTORY); return TRUE; } } free(statedir); xdgdatadir = getenv("XDG_DATA_HOME"); if (homedir == NULL && xdgdatadir == NULL) return FALSE; if (xdgdatadir != NULL) statedir = concatenate(xdgdatadir, "/nano/"); else statedir = concatenate(homedir, "/.local/share/nano/"); if (stat(statedir, &dirstat) == -1) { if (xdgdatadir == NULL) { char *statepath = concatenate(homedir, "/.local"); mkdir(statepath, S_IRWXU | S_IRWXG | S_IRWXO); free(statepath); statepath = concatenate(homedir, "/.local/share"); mkdir(statepath, S_IRWXU); free(statepath); } if (mkdir(statedir, S_IRWXU) == -1) { history_error(N_("Unable to create directory %s: %s\n" "It is required for saving/loading " "search history or cursor positions.\n"), statedir, strerror(errno)); return FALSE; } } else if (!S_ISDIR(dirstat.st_mode)) { history_error(N_("Path %s is not a directory and needs to be.\n" "Nano will be unable to load or save " "search history or cursor positions.\n"), statedir); return FALSE; } poshistname = concatenate(statedir, POSITION_HISTORY); return TRUE; }
static void smtp_chat_append(SMTPD_STATE *state, char *direction) { char *line; if (state->notify_mask == 0) return; if (state->history == 0) state->history = argv_alloc(10); line = concatenate(direction, STR(state->buffer), (char *) 0); argv_add(state->history, line, (char *) 0); myfree(line); }
int get_mail_conf_int2(const char *name1, const char *name2, int defval, int min, int max) { int intval; char *name; name = concatenate(name1, name2, (char *) 0); if (convert_mail_conf_int(name, &intval) == 0) set_mail_conf_int(name, intval = defval); check_mail_conf_int(name, intval, min, max); myfree(name); return (intval); }
int main(void) { ListPtr list1 = createlist('0'); ListPtr list2 = createlist('A'); showlist(list1); showlist(list2); concatenate(list1, list2); showlist(list1); return 0; } /* E0F main */
void pcf_read_parameters(void) { char *path; /* * A direct rip-off of mail_conf_read(). XXX Avoid code duplication by * better code decomposition. */ pcf_set_config_dir(); path = concatenate(var_config_dir, "/", MAIN_CONF_FILE, (char *) 0); if (dict_load_file_xt(CONFIG_DICT, path) == 0) msg_fatal("open %s: %m", path); myfree(path); }
int dot_lockfile(const char *path, VSTRING *why) { char *lock_file; int count; struct stat st; int fd; int status = -1; lock_file = concatenate(path, ".lock", (char *) 0); for (count = 1; /* void */ ; count++) { /* * Attempt to create the lock. This code relies on O_EXCL | O_CREAT * to not follow symlinks. With NFS file systems this operation can * at the same time succeed and fail with errno of EEXIST. */ if ((fd = open(lock_file, O_WRONLY | O_EXCL | O_CREAT, 0)) >= 0) { close(fd); status = 0; break; } if (count >= var_flock_tries) break; /* * We can deal only with "file exists" errors. Any other error means * we better give up trying. */ if (errno != EEXIST) break; /* * Break the lock when it is too old. Give up when we are unable to * remove a stale lock. */ if (stat(lock_file, &st) == 0) if (time((time_t *) 0) > st.st_ctime + var_flock_stale) if (unlink(lock_file) < 0) if (errno != ENOENT) break; rand_sleep(var_flock_delay * MILLION, var_flock_delay * MILLION / 2); } if (status && why) vstring_sprintf(why, "unable to create lock file %s: %m", lock_file); myfree(lock_file); return (status); }
static void smtpd_peer_from_pass_attr(SMTPD_STATE *state) { HTABLE *attr = (HTABLE *) vstream_context(state->client); const char *cp; /* * Extract the client endpoint information from the attribute hash. */ if ((cp = htable_find(attr, MAIL_ATTR_ACT_CLIENT_ADDR)) == 0) msg_fatal("missing client address from proxy"); if (strrchr(cp, ':') != 0) { if (valid_ipv6_hostaddr(cp, DO_GRIPE) == 0) msg_fatal("bad IPv6 client address syntax from proxy: %s", cp); state->addr = mystrdup(cp); state->rfc_addr = concatenate(IPV6_COL, cp, (char *) 0); state->addr_family = AF_INET6; } else { if (valid_ipv4_hostaddr(cp, DO_GRIPE) == 0) msg_fatal("bad IPv4 client address syntax from proxy: %s", cp); state->addr = mystrdup(cp); state->rfc_addr = mystrdup(cp); state->addr_family = AF_INET; } if ((cp = htable_find(attr, MAIL_ATTR_ACT_CLIENT_PORT)) == 0) msg_fatal("missing client port from proxy"); if (valid_hostport(cp, DO_GRIPE) == 0) msg_fatal("bad TCP client port number syntax from proxy: %s", cp); state->port = mystrdup(cp); /* * The Dovecot authentication server needs the server IP address. */ if ((cp = htable_find(attr, MAIL_ATTR_ACT_SERVER_ADDR)) == 0) msg_fatal("missing server address from proxy"); if (valid_hostaddr(cp, DO_GRIPE) == 0) msg_fatal("bad IPv6 server address syntax from proxy: %s", cp); state->dest_addr = mystrdup(cp); if ((cp = htable_find(attr, MAIL_ATTR_ACT_SERVER_PORT)) == 0) msg_fatal("missing server port from proxy"); if (valid_hostport(cp, DO_GRIPE) == 0) msg_fatal("bad TCP server port number syntax from proxy: %s", cp); state->dest_port = mystrdup(cp); /* * Convert the client address from string to binary form. */ smtpd_peer_hostaddr_to_sockaddr(state); }
/** * Write the pid of the current process into the pid file. * pid_file: Path to pid file where pid needs to be written to */ static int write_pid_to_file_as_nm(const char* pid_file, pid_t pid) { uid_t user = geteuid(); gid_t group = getegid(); if (change_effective_user(nm_uid, nm_gid) != 0) { return -1; } char *temp_pid_file = concatenate("%s.tmp", "pid_file_path", 1, pid_file); // create with 700 int pid_fd = open(temp_pid_file, O_WRONLY|O_CREAT|O_EXCL, S_IRWXU); if (pid_fd == -1) { fprintf(LOGFILE, "Can't open file %s as node manager - %s\n", temp_pid_file, strerror(errno)); free(temp_pid_file); return -1; } // write pid to temp file char pid_buf[21]; snprintf(pid_buf, 21, "%d", pid); ssize_t written = write(pid_fd, pid_buf, strlen(pid_buf)); close(pid_fd); if (written == -1) { fprintf(LOGFILE, "Failed to write pid to file %s as node manager - %s\n", temp_pid_file, strerror(errno)); free(temp_pid_file); return -1; } // rename temp file to actual pid file // use rename as atomic if (rename(temp_pid_file, pid_file)) { fprintf(LOGFILE, "Can't move pid file from %s to %s as node manager - %s\n", temp_pid_file, pid_file, strerror(errno)); unlink(temp_pid_file); free(temp_pid_file); return -1; } // Revert back to the calling user. if (change_effective_user(user, group)) { free(temp_pid_file); return -1; } free(temp_pid_file); return 0; }
int get_mail_conf_time2(const char *name1, const char *name2, int defval, int def_unit, int min, int max) { int intval; char *name; name = concatenate(name1, name2, (char *) 0); if (convert_mail_conf_time(name, &intval, def_unit) == 0) set_mail_conf_time_int(name, defval); if (convert_mail_conf_time(name, &intval, def_unit) == 0) msg_panic("get_mail_conf_time2: parameter not found: %s", name); check_mail_conf_time(name, intval, min, max); myfree(name); return (intval); }
/** * Get the job log directory. * Ensures that the result is a realpath and that it is underneath the * tt log root. */ char* get_job_log_directory(const char* jobid) { char* log_dir = get_value(TT_LOG_DIR_KEY); if (log_dir == NULL) { fprintf(LOGFILE, "Log directory %s is not configured.\n", TT_LOG_DIR_KEY); return NULL; } char *result = concatenate("%s/userlogs/%s", "job log dir", 2, log_dir, jobid); if (result == NULL) { fprintf(LOGFILE, "failed to get memory in get_job_log_directory for %s" " and %s\n", log_dir, jobid); } free(log_dir); return result; }
string MsDrbg::hash_df_hex(const unsigned char* seed_material, const size_t seed_material_size, const size_t seedlen) { size_t len = seedlen/20 + (seedlen%20 ? 1 : 0); string result = ""; unsigned char hash[20]; char hexstring[41]; for(size_t counter=1; counter <= len; ++counter) { unsigned char* counter_bytes = get_raw_bytes(counter); size_t counter_size = sizeof(counter); unsigned char* seedlen_bytes = get_raw_bytes(seedlen); size_t seedlen_size = sizeof(seedlen_size); unsigned char* counter_seedlen_bytes = concatenate(counter_bytes, counter_size, seedlen_bytes, seedlen_size); size_t counter_seedlen_size = counter_size + seedlen_size; delete[] counter_bytes; delete[] seedlen_bytes; unsigned char* hash_material = concatenate(counter_seedlen_bytes, counter_seedlen_size, seed_material, seed_material_size); size_t hash_material_size = counter_seedlen_size + seed_material_size; delete[] counter_seedlen_bytes; Sha1::calc(hash_material, static_cast<int>(hash_material_size), hash); Sha1::to_hex_string(hash, hexstring); result += string(hexstring); delete[] hash_material; } return result.substr(0,2*seedlen); }
//rest just returns a pointer to the tail of //the list without the head sequence* sequence::rest(){ // makes a new pointer called s which points to a new // sequence called mySQ sequence* s = new Sequence(mySQ[0]); concatenate(s); sequence* s2 = new Sequence(mySQ[0]); s2->concatenate(s); sequence* s3 = new Sequence; //use this in homework s3->mySQ[0] = mySQ[0]; //something like this }
char *get_mail_conf_str2(const char *name1, const char *name2, const char *defval, int min, int max) { const char *strval; char *name; name = concatenate(name1, name2, (char *) 0); if ((strval = mail_conf_lookup_eval(name)) == 0) { strval = mail_conf_eval(defval); mail_conf_update(name, strval); } check_mail_conf_str(name, strval, min, max); myfree(name); return (mystrdup(strval)); }
int main() { char *article[5] = {"the", "a", "one", "some", "any"}; char *noun[5] = {"boy", "girl", "dog", "town", "car"}; char *verb[5] = {"drove", "jumped", "ran", "walked", "skipped"}; char *preposition[5] = {"to", "from", "over", "under", "on"}; char *holdPtr = article[0]; srand(time(NULL)); concatenate(*article, *noun, *verb, *preposition, holdPtr); return 0; }