static void pwdfile_search( struct ldop *op, FILE *ofp ) { struct passwd *pw; struct ldentry *entry; int oneentry; oneentry = ( strchr( op->ldop_dn, '@' ) != NULL ); for ( pw = getpwent(); pw != NULL; pw = getpwent()) { if (( entry = pw2entry( op, pw )) != NULL ) { if ( oneentry ) { if ( strcasecmp( op->ldop_dn, entry->lde_dn ) == 0 ) { write_entry( op, entry, ofp ); break; } } else if ( test_filter( op, entry ) == LDAP_COMPARE_TRUE ) { write_entry( op, entry, ofp ); } free_entry( entry ); } } endpwent(); write_result( ofp, LDAP_SUCCESS, NULL, NULL ); }
static void write_normal_file(const char *name, struct archive *archive, struct archive_entry_linkresolver *resolver, const char *owner, const char *group) { char buf[16384]; ssize_t buf_len; struct archive_entry *entry, *sparse_entry; struct stat st; if (lstat(name, &st) == -1) err(2, "lstat failed for file %s", name); entry = archive_entry_new(); archive_entry_set_pathname(entry, name); archive_entry_copy_stat(entry, &st); if (owner != NULL) { uid_t uid; archive_entry_set_uname(entry, owner); if (uid_from_user(owner, &uid) == -1) errx(2, "user %s unknown", owner); archive_entry_set_uid(entry, uid); } else { archive_entry_set_uname(entry, user_from_uid(st.st_uid, 1)); } if (group != NULL) { gid_t gid; archive_entry_set_gname(entry, group); if (gid_from_group(group, &gid) == -1) errx(2, "group %s unknown", group); archive_entry_set_gid(entry, gid); } else { archive_entry_set_gname(entry, group_from_gid(st.st_gid, 1)); } if ((st.st_mode & S_IFMT) == S_IFLNK) { buf_len = readlink(name, buf, sizeof buf); if (buf_len < 0) err(2, "cannot read symlink %s", name); buf[buf_len] = '\0'; archive_entry_set_symlink(entry, buf); } archive_entry_linkify(resolver, &entry, &sparse_entry); if (entry != NULL) write_entry(archive, entry); if (sparse_entry != NULL) write_entry(archive, sparse_entry); }
static int write_archive_entry(const unsigned char *sha1, const char *base, int baselen, const char *filename, unsigned mode, int stage, void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; struct archiver_args *args = c->args; write_archive_entry_fn_t write_entry = c->write_entry; struct git_attr_check check[2]; const char *path_without_prefix; int convert = 0; int err; enum object_type type; unsigned long size; void *buffer; strbuf_reset(&path); strbuf_grow(&path, PATH_MAX); strbuf_add(&path, args->base, args->baselen); strbuf_add(&path, base, baselen); strbuf_addstr(&path, filename); path_without_prefix = path.buf + args->baselen; setup_archive_check(check); if (!git_checkattr(path_without_prefix, ARRAY_SIZE(check), check)) { if (ATTR_TRUE(check[0].value)) return 0; convert = ATTR_TRUE(check[1].value); } if (S_ISDIR(mode) || S_ISGITLINK(mode)) { strbuf_addch(&path, '/'); if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0); if (err) return err; return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); } buffer = sha1_file_to_archive(path_without_prefix, sha1, mode, &type, &size, convert ? args->commit : NULL); if (!buffer) return error("cannot read %s", sha1_to_hex(sha1)); if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); err = write_entry(args, sha1, path.buf, path.len, mode, buffer, size); free(buffer); return err; }
int run() { if (tall_ and wide_) throw std::runtime_error("Only one of the options '-R' and '-C' can be specified at a time."); SMSReader<val_t>::open(*FilterProgram::input_); coord_t nrows = SMSReader<val_t>::rows(); coord_t ncols = SMSReader<val_t>::columns(); if (tall_ and nrows > ncols) transpose_ = false; if (wide_ and ncols > nrows) transpose_ = false; if (transpose_) std::swap(nrows, ncols); SMSWriter<val_t>::open(*FilterProgram::output_, nrows, ncols); read(); for(matrix_t::const_iterator r = m.begin(); r != m.end(); ++r) for(vector_t::const_iterator c = r->second.begin(); c != r->second.end(); ++c) write_entry(r->first, c->first, c->second); SMSWriter<val_t>::close(); SMSReader<val_t>::close(); return 0; };
static BOOL do_export_sites(struct display_globals *dg,char *path,LONG *diskerr) { BPTR cf; struct site_entry *e; struct Node *node,*next; BOOL ok=FALSE; if ((cf = Open(path, MODE_NEWFILE))) { if ((ok=Write(cf,head1,strlen(head1)))) { node = dg->dg_og->og_SiteList->list.lh_Head; while ((next = node->ln_Succ)) { e=(struct site_entry*)((Att_Node *)node)->data; if (!(ok=write_entry(cf,e))) break; node = next; } } Close(cf); } if (!ok) *diskerr=IoErr(); return(ok); }
void command_defragment(FILE * f) { uint64 read_index, write_index, index; read_index = write_index = jump_to_first_word(f); int read_count = 0; int write_count = 0; struct entry_t entry; again: if (write_count < header.actual_words) { index = read_entry(f, &entry, read_index, READ_ENTRY_ALL); if (existent_entry(&entry)) { read_index = index; read_count++; int code = fseek(f, write_index, SEEK_SET); if (0 != code) WTF(); write_entry(f, &entry); write_count++; write_index += entry_size(&entry); goto again; } else { read_index = index; goto again; } } else { header.total_words = header.actual_words; write_header(&header, f); ftruncate(fileno(f), write_index); } }
int remove_words(FILE * f, char * word) { int count = 0; // асимптотика квадратичная :) // TODO: сделать параметр from в find_word, чтобы сделать её линейной. while (1) { uint64 start = find_word(f, word); if (start == 0) { // Если нет слова, и мы его не удаляли return count; } struct entry_t entry; // TODO: дважды read_entry -- плохо read_entry(f, &entry, start, READ_ENTRY_ALL); mark_deleted_entry(&entry); count++; int code = fseek(f, start, SEEK_SET); if (0 != code) WTF(); write_entry(f, &entry); header.actual_words--; write_header(&header, f); } }
oc::result<void> SonyElfFormatWriter::get_entry(File &file, Entry &entry) { OUTCOME_TRYV(m_seg->get_entry(file, entry, m_writer)); auto swentry = m_seg->entry(); // Silently handle cmdline entry if (swentry->type == SONY_ELF_ENTRY_CMDLINE) { entry.clear(); entry.set_size(m_cmdline.size()); auto set_as_fatal = finally([&] { m_writer.set_fatal(); }); OUTCOME_TRYV(write_entry(file, entry)); OUTCOME_TRYV(write_data(file, m_cmdline.data(), m_cmdline.size())); OUTCOME_TRYV(finish_entry(file)); OUTCOME_TRYV(get_entry(file, entry)); set_as_fatal.dismiss(); } return oc::success(); }
int pr_scoreboard_add_entry(void) { unsigned char found_slot = FALSE; if (scoreboard_fd < 0) { errno = EINVAL; return -1; } /* Write-lock the scoreboard file. */ if (wlock_scoreboard() < 0) return -1; /* No interruptions, please. */ pr_signals_block(); /* If the scoreboard is open, the file position is already past the * header. */ while (TRUE) { int res = 0; while ((res = read(scoreboard_fd, &entry, sizeof(entry))) == sizeof(entry)) { /* If this entry's PID is marked as zero, it means this slot can be * reused. */ if (!entry.sce_pid) { entry_lock.l_start = lseek(scoreboard_fd, 0, SEEK_CUR) - sizeof(entry); found_slot = TRUE; break; } } if (res == 0) { entry_lock.l_start = lseek(scoreboard_fd, 0, SEEK_CUR); found_slot = TRUE; } if (found_slot) break; } memset(&entry, '\0', sizeof(entry)); entry.sce_pid = getpid(); entry.sce_uid = geteuid(); entry.sce_gid = getegid(); if (write_entry() < 0) pr_log_pri(PR_LOG_NOTICE, "error writing scoreboard entry: %s", strerror(errno)); pr_signals_unblock(); /* We can unlock the scoreboard now. */ unlock_scoreboard(); return 0; }
static int t3_write_read_check_multiple(void) { int ret = 0; int fd; char write_item[] = "0x44332211, " "0x00000000, " "0xA0000000, " "0xB0000000, " "0xC0000000, " "0x00000000, " "0x00000000, " "0xD0000000, " "0xE0000000, " "0xF0000000 "; char read_item[sizeof(write_item)]; if (!enable_test[3]) return 0; fd = open("/dev/smem_log", O_RDWR); if (fd < 0) { perror("open"); return -1; } ret = ioctl(fd, SMIOC_SETMODE, SMIOC_TEXT); if (ret == -1) { printf("ERROR %s:%i ioctl(SMIOC_BINARY): %s\n", __func__, __LINE__, strerror(errno)); goto free_resources; } ret = write_entry(fd, write_item, sizeof(write_item)); if (ret == -1) goto free_resources; ret = read_entry(fd, read_item, sizeof(read_item)); if (ret == -1) goto free_resources; D("read_item = %.*s\n", sizeof(read_item), read_item); D("write_item = %.*s\n", sizeof(write_item), write_item); ret = is_equal_multiple(read_item, write_item); if (ret == -1) { printf("ERROR:%s:%i\n", __func__, __LINE__-4); goto free_resources; } free_resources: close(fd); return ret; }
MemTranspositionTable<CAPACITY>::MemTranspositionTable() : tab(std::make_unique<TpArray>()) { TranspositionTableBase::Entry e; e.pos = 0; e.result = static_cast<int>(TpResult::NONE); for (size_t i=0; i<CAPACITY; i++) write_entry(i, e); }
static int write_archive_entry(const unsigned char *sha1, const char *base, int baselen, const char *filename, unsigned mode, int stage, void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; struct archiver_args *args = c->args; write_archive_entry_fn_t write_entry = c->write_entry; struct git_attr_check check[2]; const char *path_without_prefix; int err; args->convert = 0; strbuf_reset(&path); strbuf_grow(&path, PATH_MAX); strbuf_add(&path, args->base, args->baselen); strbuf_add(&path, base, baselen); strbuf_addstr(&path, filename); if (S_ISDIR(mode) || S_ISGITLINK(mode)) strbuf_addch(&path, '/'); path_without_prefix = path.buf + args->baselen; setup_archive_check(check); if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) { if (ATTR_TRUE(check[0].value)) return 0; args->convert = ATTR_TRUE(check[1].value); } if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); err = write_entry(args, sha1, path.buf, path.len, mode); if (err) return err; return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); } if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); return write_entry(args, sha1, path.buf, path.len, mode); }
static int write_archive_entry(const struct object_id *oid, const char *base, int baselen, const char *filename, unsigned mode, int stage, void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; struct archiver_args *args = c->args; write_archive_entry_fn_t write_entry = c->write_entry; int err; const char *path_without_prefix; args->convert = 0; strbuf_reset(&path); strbuf_grow(&path, PATH_MAX); strbuf_add(&path, args->base, args->baselen); strbuf_add(&path, base, baselen); strbuf_addstr(&path, filename); if (S_ISDIR(mode) || S_ISGITLINK(mode)) strbuf_addch(&path, '/'); path_without_prefix = path.buf + args->baselen; if (!S_ISDIR(mode)) { const struct attr_check *check; check = get_archive_attrs(args->repo->index, path_without_prefix); if (check_attr_export_ignore(check)) return 0; args->convert = check_attr_export_subst(check); } if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); err = write_entry(args, oid, path.buf, path.len, mode); if (err) return err; return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); } if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); return write_entry(args, oid, path.buf, path.len, mode); }
void csdb_generator::write_dummy_entry() { entry_.desc_ = "No codesets defined"; entry_.loc_name_ = "NONE"; entry_.codeset_id_ = 0; entry_.num_sets_ = 1; entry_.char_sets_[0] = 0; entry_.max_bytes_ = 0; write_entry(); }
static int t2_write_read_check(void) { int ret = 0; int fd; char write_item[] = "0x11223344, " "0x00000000, " "0x10000000, " "0x20000000, " "0x30000000 "; char read_item[sizeof(write_item)]; if (!enable_test[2]) return 0; fd = open("/dev/smem_log", O_RDWR); if (fd < 0) { perror("open"); return -1; } ret = ioctl(fd, SMIOC_SETMODE, SMIOC_TEXT); if (ret == -1) { printf("ERROR %s:%i ioctl(SMIOC_BINARY): %s\n", __func__, __LINE__, strerror(errno)); goto free_resources; } ret = write_entry(fd, write_item, sizeof(write_item)); if (ret == -1) goto free_resources; ret = read_entry(fd, read_item, sizeof(read_item)); if (ret == -1) goto free_resources; ret = is_equal(read_item, write_item); if (ret == -1) { read_item[sizeof(read_item)-1] = '\0'; write_item[sizeof(write_item)-1] = '\0'; printf("ERROR:%s:%i\n", __func__, __LINE__-4); printf("read_item = %s\n", read_item); printf("write_item = %s\n", write_item); goto free_resources; } free_resources: close(fd); return ret; }
static size_t journal_input_callback(void *buf, size_t size, size_t nmemb, void *userp) { Uploader *u = userp; int r; sd_journal *j; size_t filled = 0; ssize_t w; assert(u); assert(nmemb <= SSIZE_MAX / size); check_update_watchdog(u); j = u->journal; while (j && filled < size * nmemb) { if (u->entry_state == ENTRY_DONE) { r = sd_journal_next(j); if (r < 0) { log_error_errno(r, "Failed to move to next entry in journal: %m"); return CURL_READFUNC_ABORT; } else if (r == 0) { if (u->input_event) log_debug("No more entries, waiting for journal."); else { log_info("No more entries, closing journal."); close_journal_input(u); } u->uploading = false; break; } u->entry_state = ENTRY_CURSOR; } w = write_entry((char*)buf + filled, size * nmemb - filled, u); if (w < 0) return CURL_READFUNC_ABORT; filled += w; if (filled == 0) { log_error("Buffer space is too small to write entry."); return CURL_READFUNC_ABORT; } else if (u->entry_state != ENTRY_DONE) /* This means that all available space was used up */ break; log_debug("Entry %zu (%s) has been uploaded.", u->entries_sent, u->current_cursor); } return filled; }
static void write_dir( FILE* of, GMenuTreeDirectory* dir ) { GSList* l; const char* cstr; char* str; fprintf( of, "+%s\n", gmenu_tree_directory_get_menu_id( dir ) ); fprintf( of, "%s\n", gmenu_tree_directory_get_name( dir ) ); cstr = gmenu_tree_directory_get_comment( dir ); fprintf( of, "%s\n", cstr ? cstr : "" ); cstr = gmenu_tree_directory_get_icon( dir ); fprintf( of, "%s\n", cstr ? cstr : "" ); if( gmenu_tree_directory_get_desktop_file_path( dir ) ) { /* get basename of its desktop file. */ str = g_path_get_basename( gmenu_tree_directory_get_desktop_file_path( dir ) ); fprintf( of, "%s\n", str ); g_free( str ); /* get the location of its desktop file. */ str = g_path_get_dirname( gmenu_tree_directory_get_desktop_file_path( dir ) ); fprintf( of, "%d\n", dirname_index( str ) ); g_free( str ); } else { fprintf( of, "\n-1\n" ); } // fprintf( of, "\n" ); /* end of item info */ for( l = gmenu_tree_directory_get_contents(dir); l; l = l->next ) { GMenuTreeItem* item = (GMenuTreeItem*)l->data; GMenuTreeItemType type = gmenu_tree_item_get_type(item); if( type == GMENU_TREE_ITEM_DIRECTORY ) { write_dir( of, (GMenuTreeDirectory*)item ); } else if( type == GMENU_TREE_ITEM_ENTRY ) { write_entry( of, (GMenuTreeEntry*)item ); } else if( type == GMENU_TREE_ITEM_SEPARATOR ) fputs( "-\n", of ); } fputs( "\n", of ); }
int before_block_exec(CPUState *env, TranslationBlock *tb) { uint64_t count = rr_prog_point.guest_instr_count; if (!snipping && count+tb->num_guest_insns > start_count) { sassert((oldlog = fopen(rr_nondet_log->name, "r"))); sassert(fread(&orig_last_prog_point, sizeof(RR_prog_point), 1, oldlog) == 1); printf("Original ending prog point: "); rr_spit_prog_point(orig_last_prog_point); actual_start_count = count; printf("Saving snapshot at instr count %lu...\n", count); do_savevm_rr(get_monitor(), snp_name); printf("Beginning cut-and-paste process at prog point:\n"); rr_spit_prog_point(rr_prog_point); printf("Writing entries to %s...\n", nondet_name); newlog = fopen(nondet_name, "w"); sassert(newlog); // We'll fix this up later. RR_prog_point prog_point = {0, 0, 0}; fwrite(&prog_point, sizeof(RR_prog_point), 1, newlog); fseek(oldlog, ftell(rr_nondet_log->fp), SEEK_SET); RR_log_entry *item = rr_get_queue_head(); while (item != NULL && item->header.prog_point.guest_instr_count < end_count) { write_entry(item); item = item->next; } while (prog_point.guest_instr_count < end_count && !feof(oldlog)) { prog_point = copy_entry(); } if (!feof(oldlog)) { // prog_point is the first one AFTER what we want printf("Reached end of old nondet log.\n"); } else { printf("Past desired ending point for log.\n"); } snipping = true; printf("Continuing with replay.\n"); } if (snipping && !done && count > end_count) { end_snip(); init_timer_alarm(); rr_do_end_replay(0); } return 0; }
bool store_entry(char *path, uint8_t *key, entry *entry) { size_t size = -ENTRY_LEN(0); size += entry_size(entry); size += 1024 - (size % 1024); void *addr = mmfile(path, &size); box *box = addr; if (!addr) return false; write_entry(BOX_DATA(box), entry); encrypt_box(key, box, ENTRY_LEN(size)); return mmsync(path, addr, size); }
int git_checkout_file(const char *ref, const char *path, const char *outputpath) { struct cache_entry *ce; int ret; GIT_HASH sha1; struct tree * root; struct checkout state; struct pathspec pathspec; const char *match[2]; ret = get_sha1(ref, sha1); if(ret) return ret; reprepare_packed_git(); root = parse_tree_indirect(sha1); if(!root) { free_all_pack(); return -1; } ce = xcalloc(1, cache_entry_size(strlen(path))); match[0] = path; match[1] = NULL; init_pathspec(&pathspec, match); pathspec.items[0].use_wildcard = 0; ret = read_tree_recursive(root, "", 0, 0, &pathspec, update_some, ce); free_pathspec(&pathspec); if(ret) { free_all_pack(); free(ce); return ret; } memset(&state, 0, sizeof(state)); state.force = 1; state.refresh_cache = 0; ret = write_entry(ce, outputpath, &state, 0); free_all_pack(); free(ce); return ret; }
// Both pt0 and v_base have to be aligned to the page selected with INITIAL_RESERVE_LVL_OFFSET int init_pt_set(pt_t* pt0, unsigned context_id, void *v_base, pt_t** next_table, size_t* free){ //Store a pointer to a free location for the next table, //and the number of tables that can be created there (assuming we reserve 2 MiB) *next_table = pt0; *free = 1 << (VADDR_LSO + (INITIAL_RESERVE_LVL_OFFSET * PT_INDEX_WIDTH) - quickLog2(sizeof(pt_t))); //Construct L0 table construct_pt(next_table); *free -= 1; // Construct the pt_index for context_id and v_base uint64_t pts_index = calculate_pt_index(context_id, (uint64_t)v_base); //Reserve a 2MiB page at physical location p_base, mapped pt_index //Create new tables where needed, starting at next_table. (a 2MiB page has a 19-bit offset) return write_entry(pt0, pts_index, pt0, 0, next_table, free, 1, 1, 0); }
int git_checkout_file(const char* ref, const char* path, char* outputpath) { struct cache_entry *ce; int ret; struct object_id oid; struct tree * root; struct checkout state; struct pathspec pathspec; const char *matchbuf[1]; ret = get_oid(ref, &oid); if(ret) return ret; reprepare_packed_git(the_repository); root = parse_tree_indirect(&oid); if(!root) { free_all_pack(); return -1; } ce = xcalloc(1, cache_entry_size(strlen(path))); matchbuf[0] = NULL; parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC, PATHSPEC_PREFER_CWD, path, matchbuf); pathspec.items[0].nowildcard_len = pathspec.items[0].len; ret = read_tree_recursive(root, "", 0, 0, &pathspec, update_some, ce); clear_pathspec(&pathspec); if(ret) { free_all_pack(); free(ce); return ret; } memset(&state, 0, sizeof(state)); state.force = 1; state.refresh_cache = 0; ret = write_entry(ce, outputpath, &state, 0); free_all_pack(); free(ce); return ret; }
int pr_scoreboard_del_entry(unsigned char verbose) { if (scoreboard_fd < 0) { errno = EINVAL; return -1; } memset(&entry, '\0', sizeof(entry)); /* Write-lock this entry */ wlock_entry(); if (write_entry() < 0 && verbose) pr_log_pri(PR_LOG_NOTICE, "error deleting scoreboard entry: %s", strerror(errno)); unlock_entry(); return 0; }
static void *thread_fn(void *arg) { char str[ENTRY_STR_LEN]; struct entry *e; time_t logtime; int level, prev_dropped = 0; while (1) { pthread_mutex_lock(&mutex); while (head_ent == tail_ent) { if (done) { pthread_mutex_unlock(&mutex); goto out; } pthread_cond_wait(&cond, &mutex); } e = &ents[tail_ent++]; tail_ent = tail_ent % num_ents; pending_ents--; memcpy(str, e->str, ENTRY_STR_LEN); level = e->level; logtime = e->time; prev_dropped = dropped; dropped = 0; pthread_mutex_unlock(&mutex); if (prev_dropped) { write_dropped(level, &logtime, prev_dropped); prev_dropped = 0; } write_entry(level, &logtime, str); } out: pthread_exit(NULL); }
int csdb_generator::read_from (const char *srcfile) { inf_ = new ifstream(srcfile); char *ptr; while (inf_->good() && !inf_->eof()) { linecounter_++; switch (read_line ()) { case -1: // bogus line fail ("unknown field tag"); break; case 0: // comment or blank line break; case 1: // start entry_.desc_ = 0; entry_.loc_name_ = 0; entry_.codeset_id_ = 0; entry_.num_sets_ = 0; entry_.max_bytes_ = 0; in_entry_ = 1; break; case 2: // end if (entry_.codeset_id_ == 0) fail ("entry missing rgy_value"); if (entry_.num_sets_ == 0) fail ("entry does not include at least one char_value"); if (entry_.max_bytes_ == 0) fail ("entry does not define max_bytes"); write_entry (); delete [] const_cast<char *> (entry_.desc_); delete [] const_cast<char *> (entry_.loc_name_); count_++; in_entry_ = 0; break; case 3: // description if (entry_.desc_ != 0) fail ("duplicate description"); entry_.desc_ = ACE_OS::strdup(line_data_); break; case 4: // loc_name if (entry_.loc_name_ != 0) fail ("duplicate loc_name"); entry_.loc_name_ = ACE_OS::strdup(line_data_); break; case 5: // rgy_value if (entry_.codeset_id_ != 0) fail ("duplicate rgy_value"); entry_.codeset_id_ = ACE_OS::strtoul(line_data_,&ptr,16); if (*ptr != 0 || entry_.codeset_id_ == 0) { char emsg [100]; ACE_OS::sprintf (emsg,"invalid rgy_value, '%s'",line_data_); fail (emsg); } break; case 6: // char_values if (entry_.num_sets_ != 0) fail ("duplicate char_values"); ptr = line_data_; do { if (*ptr == ':') ptr++; ACE_CDR::UShort tmp = static_cast<ACE_CDR::UShort> (ACE_OS::strtoul(ptr,&ptr,16)); if (*ptr != 0 && *ptr != ':') { char *emsg = new char [100]; ACE_OS::sprintf (emsg,"invalid symbol \'%c\' in char_values",*ptr); fail (emsg); } if (entry_.num_sets_ < max_charsets_) entry_.char_sets_[entry_.num_sets_++] = tmp; else entry_.num_sets_++; } while (*ptr == ':'); if (entry_.num_sets_ > max_charsets_) { char *emsg = new char [200]; ACE_OS::sprintf (emsg,"max of %d char_values exceeded.\nIncrease ACE_Codeset_Registry::max_charsets_ to at least %d and rebuild mkcsregdb",max_charsets_,entry_.num_sets_); fail (emsg); } break; case 7: // max_bytes if (entry_.max_bytes_ != 0) fail ("duplicate max_bytes"); entry_.max_bytes_ = static_cast<ACE_CDR::UShort> (ACE_OS::strtol(line_data_,&ptr,10)); if (*ptr != 0) fail ("invalid max_bytes"); break; } } return 0; }
static void make_dist(const char *pkg, const char *suffix, const package_t *plist) { char *archive_name; const char *owner, *group; const plist_t *p; struct archive *archive; struct archive_entry *entry, *sparse_entry; struct archive_entry_linkresolver *resolver; char *initial_cwd; archive = archive_write_new(); archive_write_set_format_pax_restricted(archive); if ((resolver = archive_entry_linkresolver_new()) == NULL) errx(2, "cannot create link resolver"); archive_entry_linkresolver_set_strategy(resolver, archive_format(archive)); if (CompressionType == NULL) { if (strcmp(suffix, "tbz") == 0 || strcmp(suffix, "tar.bz2") == 0) CompressionType = "bzip2"; else if (strcmp(suffix, "tgz") == 0 || strcmp(suffix, "tar.gz") == 0) CompressionType = "gzip"; else CompressionType = "none"; } if (strcmp(CompressionType, "bzip2") == 0) archive_write_set_compression_bzip2(archive); else if (strcmp(CompressionType, "gzip") == 0) archive_write_set_compression_gzip(archive); else if (strcmp(CompressionType, "xz") == 0) archive_write_set_compression_xz(archive); else if (strcmp(CompressionType, "none") == 0) archive_write_set_compression_none(archive); else errx(1, "Unspported compression type for -F: %s", CompressionType); archive_name = xasprintf("%s.%s", pkg, suffix); if (archive_write_open_file(archive, archive_name)) errx(2, "cannot create archive: %s", archive_error_string(archive)); free(archive_name); owner = DefaultOwner; group = DefaultGroup; write_meta_file(contents_file, archive); write_meta_file(comment_file, archive); write_meta_file(desc_file, archive); if (Install) write_meta_file(install_file, archive); if (DeInstall) write_meta_file(deinstall_file, archive); if (Display) write_meta_file(display_file, archive); if (BuildVersion) write_meta_file(build_version_file, archive); if (BuildInfo) write_meta_file(build_info_file, archive); if (SizePkg) write_meta_file(size_pkg_file, archive); if (SizeAll) write_meta_file(size_all_file, archive); if (Preserve) write_meta_file(preserve_file, archive); if (create_views) write_meta_file(views_file, archive); initial_cwd = getcwd(NULL, 0); for (p = plist->head; p; p = p->next) { if (p->type == PLIST_FILE) { write_normal_file(p->name, archive, resolver, owner, group); } else if (p->type == PLIST_CWD) { chdir(p->name); } else if (p->type == PLIST_IGNORE) { p = p->next; } else if (p->type == PLIST_CHOWN) { if (p->name != NULL) owner = p->name; else owner = DefaultOwner; } else if (p->type == PLIST_CHGRP) { if (p->name != NULL) group = p->name; else group = DefaultGroup; } } entry = NULL; archive_entry_linkify(resolver, &entry, &sparse_entry); while (entry != NULL) { write_entry(archive, entry); entry = NULL; archive_entry_linkify(resolver, &entry, &sparse_entry); } archive_entry_linkresolver_free(resolver); if (archive_write_close(archive)) errx(2, "cannot finish archive: %s", archive_error_string(archive)); archive_write_finish(archive); free(initial_cwd); }
/* * Write a single file (or directory or other filesystem object) to * the archive. */ static void write_file(struct bsdtar *bsdtar, struct archive *a, struct archive_entry *entry) { write_entry(bsdtar, a, entry); }
int main() { double a = 6378388.0; double e2 = 0.006722670022; double lon_rad; double lat_rad; GridZone zone; Hemisphere hemi; double E; double N; std::cout << "Tests transformations to/from UTM grid (reproduces Table 2-11 of DMTAM 8358.2)\n\n"; // ---------------------------------------------- // TEST OF FORWARD GOING UTM ELLIPSOID CONVERSION // ---------------------------------------------- // ------ // ID = 1 // ------ dmsStringToRad("+045d00m00.000s",lon_rad); dmsStringToRad("+73d00m00.000s",lat_rad); zone = UTM_ZONE_38; hemi = HEMI_NORTH; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 2 // ------ dmsStringToRad("+102d00m00.000s",lon_rad); dmsStringToRad("+30d00m00.000s",lat_rad); zone = UTM_ZONE_47; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); zone = UTM_ZONE_48; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 3 // ------ dmsStringToRad("-113d54m43.321s",lon_rad); dmsStringToRad("+72d04m32.110",lat_rad); zone = UTM_ZONE_12; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); zone = UTM_ZONE_11; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); std::cout << std::endl; // ----------------------------------------------- // TEST OF BACKWARD GOING UTM ELLIPSOID CONVERSION // ----------------------------------------------- // ------ // ID = 4 // ------ N = 3322824.35; E = 210577.93; grid_to_geographic(a, e2, UTM_ZONE_48, HEMI_NORTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); N = 3322824.08; E = 789411.59; grid_to_geographic(a, e2, UTM_ZONE_47, HEMI_NORTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 5 // ------ N = 1000000.00; E = 200000.00; grid_to_geographic(a, e2, UTM_ZONE_31, HEMI_NORTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); N = 1000491.75; E = 859739.88; grid_to_geographic(a, e2, UTM_ZONE_30, HEMI_NORTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 6 // ------ N = 9000000.00; E = 500000.00; grid_to_geographic(a, e2, UTM_ZONE_43, HEMI_NORTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 7 // ------ N = 4000000.00; E = 700000.00; grid_to_geographic(a, e2, UTM_ZONE_30, HEMI_SOUTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); N = 4000329.42; E = 307758.89; grid_to_geographic(a, e2, UTM_ZONE_31, HEMI_SOUTH, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); std::cout << std::endl; // ---------------------------------------------- // TEST OF FORWARD GOING UPS ELLIPSOID CONVERSION // ---------------------------------------------- std::cout << "Tests transformations to/from UPS grid (reproduces Table 3-7 of DMTAM 8358.2)\n\n"; a = 6378137.0; e2 = 0.006694379990; // ------ // ID = 1 // ------ dmsStringToRad("-132d14m52.761s",lon_rad); dmsStringToRad("+84d17m14.042s",lat_rad); zone = UPS_NORTH; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 2 // ------ dmsStringToRad("+044d00m00.000s",lon_rad); dmsStringToRad("+73d00m00.000s",lat_rad); zone = UPS_NORTH; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 3 // ------ dmsStringToRad("+132d14m52.303s",lon_rad); dmsStringToRad("-87d17m14.400s",lat_rad); zone = UPS_SOUTH; geographic_to_grid(a, e2, lat_rad, lon_rad, &zone, &hemi, &N, &E); write_entry(std::cout, lat_rad, lon_rad, N, E); std::cout << std::endl; // ----------------------------------------------- // TEST OF BACKWARD GOING UPS ELLIPSOID CONVERSION // ----------------------------------------------- // ------ // ID = 4 // ------ N = 2426773.60; E = 1530125.78; grid_to_geographic(a, e2, UPS_NORTH, HEMI_AUTO, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 5 // ------ N = 632668.43; E = 3320416.75; grid_to_geographic(a, e2, UPS_NORTH, HEMI_AUTO, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); // ------ // ID = 6 // ------ N = 1500000.00; E = 2500000.00; grid_to_geographic(a, e2, UPS_SOUTH, HEMI_AUTO, N, E, &lat_rad, &lon_rad); write_entry(std::cout, lat_rad, lon_rad, N, E); }
static void write_dropped(int level, int num) { char str[LOG_STR_LEN]; sprintf(str, "dropped %d entries", num); write_entry(level, str); }
/* We get clever with this function, so that it can be used to update * various entry attributes. */ int pr_scoreboard_update_entry(pid_t pid, ...) { va_list ap; char *tmp = NULL; int entry_tag = 0; if (scoreboard_fd < 0) { errno = EINVAL; return -1; } /* If updating some fields, clear the begin_idle field. */ va_start(ap, pid); while ((entry_tag = va_arg(ap, int)) != 0) { switch (entry_tag) { case PR_SCORE_USER: tmp = va_arg(ap, char *); memset(entry.sce_user, '\0', sizeof(entry.sce_user)); sstrncpy(entry.sce_user, tmp, sizeof(entry.sce_user)); break; case PR_SCORE_CLIENT_ADDR: { pr_netaddr_t *remote_addr = va_arg(ap, pr_netaddr_t *); snprintf(entry.sce_client_addr, sizeof(entry.sce_client_addr), "%s", remote_addr ? pr_netaddr_get_ipstr(remote_addr) : "(unknown)"); entry.sce_client_addr[sizeof(entry.sce_client_addr) - 1] = '\0'; } break; case PR_SCORE_CLIENT_NAME: { char *remote_name = va_arg(ap, char *); snprintf(entry.sce_client_name, sizeof(entry.sce_client_name), "%s", remote_name ? remote_name : "(unknown)"); entry.sce_client_name[sizeof(entry.sce_client_name) - 1] = '\0'; } break; case PR_SCORE_CLASS: tmp = va_arg(ap, char *); memset(entry.sce_class, '\0', sizeof(entry.sce_class)); sstrncpy(entry.sce_class, tmp, sizeof(entry.sce_class)); break; case PR_SCORE_CWD: tmp = va_arg(ap, char *); memset(entry.sce_cwd, '\0', sizeof(entry.sce_cwd)); sstrncpy(entry.sce_cwd, tmp, sizeof(entry.sce_cwd)); break; case PR_SCORE_CMD: { char *cmdstr = NULL; tmp = va_arg(ap, char *); cmdstr = handle_score_str(tmp, ap); memset(entry.sce_cmd, '\0', sizeof(entry.sce_cmd)); sstrncpy(entry.sce_cmd, cmdstr, sizeof(entry.sce_cmd)); tmp = va_arg(ap, void *); } break; case PR_SCORE_CMD_ARG: { char *argstr = NULL; tmp = va_arg(ap, char *); argstr = handle_score_str(tmp, ap); memset(entry.sce_cmd_arg, '\0', sizeof(entry.sce_cmd_arg)); sstrncpy(entry.sce_cmd_arg, argstr, sizeof(entry.sce_cmd_arg)); tmp = va_arg(ap, void *); } break; case PR_SCORE_SERVER_PORT: entry.sce_server_port = va_arg(ap, int); break; case PR_SCORE_SERVER_ADDR: { pr_netaddr_t *server_addr = va_arg(ap, pr_netaddr_t *); int server_port = va_arg(ap, int); snprintf(entry.sce_server_addr, sizeof(entry.sce_server_addr), "%s:%d", server_addr ? pr_netaddr_get_ipstr(server_addr) : "(unknown)", server_port); entry.sce_server_addr[sizeof(entry.sce_server_addr)-1] = '\0'; } break; case PR_SCORE_SERVER_LABEL: tmp = va_arg(ap, char *); memset(entry.sce_server_label, '\0', sizeof(entry.sce_server_label)); sstrncpy(entry.sce_server_label, tmp, sizeof(entry.sce_server_label)); break; case PR_SCORE_BEGIN_IDLE: /* Ignore this */ (void) va_arg(ap, time_t); time(&entry.sce_begin_idle); break; case PR_SCORE_BEGIN_SESSION: /* Ignore this */ (void) va_arg(ap, time_t); time(&entry.sce_begin_session); break; case PR_SCORE_XFER_DONE: entry.sce_xfer_done = va_arg(ap, off_t); break; case PR_SCORE_XFER_SIZE: entry.sce_xfer_size = va_arg(ap, off_t); break; case PR_SCORE_XFER_LEN: entry.sce_xfer_len = va_arg(ap, off_t); break; case PR_SCORE_XFER_ELAPSED: entry.sce_xfer_elapsed = va_arg(ap, unsigned long); break; default: errno = EINVAL; return -1; } } /* Write-lock this entry */ wlock_entry(); if (write_entry() < 0) pr_log_pri(PR_LOG_NOTICE, "error writing scoreboard entry: %s", strerror(errno)); unlock_entry(); return 0; }