/* * Save the contents of the current * buffer in its associatd file. No nothing * if nothing has changed (this may be a bug, not a * feature). Error if there is no remembered file * name for the buffer. Bound to "C-X C-S". May * get called by "C-Z". */ int filesave(int f, int n) { struct window *wp; int s; if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ return TRUE; if (curbp->b_fname[0] == 0) { /* Must have a name. */ mlwrite("No file name"); return FALSE; } /* complain about truncated files */ if ((curbp->b_flag & BFTRUNC) != 0) { if (mlyesno("Truncated file ... write it out") == FALSE) { mlwrite("(Aborted)"); return FALSE; } } if ((s = writeout(curbp->b_fname)) == TRUE) { curbp->b_flag &= ~BFCHG; wp = wheadp; /* Update mode lines. */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return s; }
/* ARGSUSED */ int filewrite(int f, int n) { int s; char fname[NFILEN], bn[NBUFN]; char *adjfname, *bufp; if (getbufcwd(fname, sizeof(fname)) != TRUE) fname[0] = '\0'; if ((bufp = eread("Write file: ", fname, NFILEN, EFDEF | EFNEW | EFCR | EFFILE)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); adjfname = adjustname(fname, TRUE); if (adjfname == NULL) return (FALSE); /* old attributes are no longer current */ bzero(&curbp->b_fi, sizeof(curbp->b_fi)); if ((s = writeout(curbp, adjfname)) == TRUE) { (void)strlcpy(curbp->b_fname, adjfname, sizeof(curbp->b_fname)); if (getbufcwd(curbp->b_cwd, sizeof(curbp->b_cwd)) != TRUE) (void)strlcpy(curbp->b_cwd, "/", sizeof(curbp->b_cwd)); if (augbname(bn, basename(curbp->b_fname), sizeof(bn)) == FALSE) return (FALSE); free(curbp->b_bname); if ((curbp->b_bname = strdup(bn)) == NULL) return (FALSE); curbp->b_flag &= ~(BFBAK | BFCHG); upmodes(curbp); } return (s); }
/* * Save the contents of the current buffer in its associatd file. No nothing * if nothing has changed (this may be a bug, not a feature). Error if there * is no remembered file name for the buffer. Bound to "C-X C-S". May get * called by "C-Z" */ int filesave (int f, int n) { WINDOW *wp; int s; if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes */ return (TRUE); if (curbp->b_fname[0] == 0) { /* Must have a name */ mlwrite ("No file name"); return (FALSE); } if ((s = writeout (curbp->b_fname)) == TRUE) { curbp->b_flag &= ~BFCHG; wp = wheadp; /* Update mode lines */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return (s); }
virtual int overflow( int ch = EOF ) { if ( ch != EOF ) { char tmp = ch; writeout( &tmp, 1 ); } return 0; }
int main( int argc, char **argv, char **envp) { unsigned long i; char *input, *output; struct arch *archs; unsigned long narchs; progname = argv[0]; input = NULL; output = NULL; archs = NULL; narchs = 0; for(i = 1; i < argc; i++){ if(strcmp(argv[i], "-o") == 0){ if(i + 1 == argc){ error("missing argument(s) to: %s option", argv[i]); usage(); } if(output != NULL){ error("more than one: %s option specified", argv[i]); usage(); } output = argv[i+1]; i++; } else{ if(input != NULL){ error("more than one input file specified (%s and %s)", argv[i], input); usage(); } input = argv[i]; } } if(input == NULL || output == NULL) usage(); breakout(input, &archs, &narchs, FALSE); if(errors) exit(EXIT_FAILURE); checkout(archs, narchs); process(archs, narchs); writeout(archs, narchs, output, 0777, TRUE, FALSE, FALSE); if(errors) return(EXIT_FAILURE); else return(EXIT_SUCCESS); }
/* ARGSUSED */ int filewrite(int f, int n) { struct stat statbuf; int s; char fname[NFILEN], bn[NBUFN], tmp[NFILEN + 25]; char *adjfname, *bufp; FILE *ffp; if (getbufcwd(fname, sizeof(fname)) != TRUE) fname[0] = '\0'; if ((bufp = eread("Write file: ", fname, NFILEN, EFDEF | EFNEW | EFCR | EFFILE)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); adjfname = adjustname(fname, TRUE); if (adjfname == NULL) return (FALSE); /* Check if file exists; write checks done later */ if (stat(adjfname, &statbuf) == 0) { if (S_ISDIR(statbuf.st_mode)) { dobeep(); ewprintf("%s is a directory", adjfname); return (FALSE); } snprintf(tmp, sizeof(tmp), "File `%s' exists; overwrite", adjfname); if ((s = eyorn(tmp)) != TRUE) return (s); } /* old attributes are no longer current */ bzero(&curbp->b_fi, sizeof(curbp->b_fi)); if ((s = writeout(&ffp, curbp, adjfname)) == TRUE) { (void)strlcpy(curbp->b_fname, adjfname, sizeof(curbp->b_fname)); if (getbufcwd(curbp->b_cwd, sizeof(curbp->b_cwd)) != TRUE) (void)strlcpy(curbp->b_cwd, "/", sizeof(curbp->b_cwd)); if (augbname(bn, curbp->b_fname, sizeof(bn)) == FALSE) return (FALSE); free(curbp->b_bname); if ((curbp->b_bname = strdup(bn)) == NULL) return (FALSE); (void)fupdstat(curbp); curbp->b_flag &= ~BFCHG; upmodes(curbp); undo_add_boundary(FFRAND, 1); undo_add_modified(); } return (s); }
static void flush_buffer(AVIOContext *s) { if (s->buf_ptr > s->buffer) { writeout(s, s->buffer, s->buf_ptr - s->buffer); if(s->update_checksum){ s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); s->checksum_ptr= s->buffer; } } s->buf_ptr = s->buffer; }
int trimBed(int argc, char *argv[]) { int help = 0; int n; int i; char *out = 0; int trim1 = 0; int trim2 = 0; while ((n = getopt(argc, argv, "o:r:l:h")) >= 0) { switch(n) { case 'o' : out = optarg; break; case 'l' : trim1 = atoi(optarg); break; case 'r' : trim2 = atoi(optarg); break; case 'h' : help = 1; break; default : errabort("%c : unknown option!", (char)n); break; } if (help) trimHelp(); } if (trim1 == 0 && trim2 == 0) errabort("You must set a trim size!"); if (trim1 < 0 || trim2 < 0) errabort("Trim size must be a postive int!"); n = argc - optind; if (n < 1) errabort("Sucker! Set the bed file(s)!"); regHash_t *rghsh = kh_init(reg); int ret = 0; for (i = 0; i < n; ++i) { bedHand->read(argv[optind+i], rghsh, 0, 0, &ret); } bedHand->merge(rghsh); if (ret) { warnings("the input bed file might not be standard bed format 0-based, please make sure the input files is in same base system" "you can use '1to0' to trans the base systems first"); } inf_t *itmp = bedHand->stat(rghsh); bedHand->trim(rghsh, trim1, trim2); inf_t *inf = bedHand->stat(rghsh); if (out) bedHand->save(out, rghsh); unsigned trim_length = itmp->length - inf->length; writeout("Trimmed %d bp\n" "The length of whole regions is %d bp\n" ,trim_length, inf->length); freemem(itmp); freemem(inf); bedHand->destroy(rghsh, destroy_void); return 1; }
int main(void) { while (moreinput()) { parse(); optimize(); addable(); generate(); peephole(); writeout(); } return 0; }
/* Start a REL item and write out the last one */ void startitem(hword it) { startblock(); if(itemsz){ item[0] = fw(itemtype, itemsz); writeout(); } itemtype = it; itemsz = 0; itemp = 1; relocp = itemp++; }
static void flush_buffer(AVIOContext *s) { s->buf_ptr_max = FFMAX(s->buf_ptr, s->buf_ptr_max); if (s->write_flag && s->buf_ptr_max > s->buffer) { writeout(s, s->buffer, s->buf_ptr_max - s->buffer); if (s->update_checksum) { s->checksum = s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr_max - s->checksum_ptr); s->checksum_ptr = s->buffer; } } s->buf_ptr = s->buf_ptr_max = s->buffer; if (!s->write_flag) s->buf_end = s->buffer; }
int write_image (struct lev_storage_file *E, char *data, crc32_logpos_t *P) { clearin (); assert (E->type == LEV_STORAGE_FILE || (E->type == LEV_STORAGE_HIDE_FILE && !E->size)); const unsigned zero = 0; int l = (E->size + 3) & -4; int padded_zero_bytes = l - E->size; assert (padded_zero_bytes >= 0 && padded_zero_bytes < 4); if (padded_zero_bytes) { assert (!memcmp (data + E->size, &zero, padded_zero_bytes)); } P->crc32_complement = crc32_partial (E, sizeof (*E), P->crc32_complement); P->log_pos += sizeof (*E); P->crc32_complement = crc32_partial (data, l, P->crc32_complement); P->log_pos += l; struct lev_crc32 C; C.type = LEV_CRC32; C.pos = P->log_pos; C.crc32 = ~P->crc32_complement; C.timestamp = last_mtime; P->crc32_complement = crc32_partial (&C, sizeof (C), P->crc32_complement); P->log_pos += sizeof (C); if (writeout (E, sizeof (*E)) < 0 || writeout (data, l) < 0 || writeout (&C, sizeof (C)) < 0 || flushout () < 0) { return -1; } if (test_mode) { char base64url_secret[12]; int r = base64url_encode ((unsigned char *) &E->secret, 8, base64url_secret, 12); assert (!r); printf ("wget -O %d.jpg http://127.0.0.1:%d/v%lld/%x/%s.jpg\n", E->local_id, http_port, volume_id, E->local_id, base64url_secret); } return 0; }
int mergeBed(int argc, char * argv[]) { int help = 0; int n, i; char *out = 0; int add1 = 0, add2 = 0; while ((n = getopt(argc, argv, "o:hr:l:1")) >= 0) { switch(n) { case 'o': out = optarg; break; case 'h': help = 1; break; case 'r': add1 = atoi(optarg); break; case 'l': add2 = atoi(optarg); break; case '1': one_based = TRUE; break; } } if(help) return mergeHelp(); assert(add1 >= 0 && add2 >= 0); n = argc - optind; int ret = 0; regHash_t * reghash; reghash = kh_init(reg); for (i = 0; i < n; ++i) { bedHand->read(argv[optind+i], reghash, add1, add2, &ret); } if (one_based) bedHand->base1to0(reghash); if (!one_based && ret) { warnings("This region might not not a standard bed format." "Please use parameter \"-1\" if your bed file is 1-based!"); } inf_t *itmp = bedHand->stat(reghash); bedHand->merge(reghash); inf_t *inf = bedHand->stat(reghash); inf->region = itmp->total - inf->total; if (out) bedHand->save(out, reghash); writeout("Merged %u regions.\n" "Total regions is %u.\n" "The length of the regions is %u bp.\n", inf->region, inf->total, inf->length); bedHand->destroy(reghash, destroy_void); freemem(itmp); freemem(inf); return 1; }
int main(int argc, char **argv) { struct intel1_ucode_header uh; int datasize, totalsize; void *theupdate; struct intel1_ucode_ext_table *eh; if (argc < 2) errx(1, "need filename"); in = fopen(argv[1], "r"); if (!in) err(2, "could not open \"%s\"", argv[1]); for (;;) { if (getbin(&uh, sizeof(uh)) < 0) break; if (uh.uh_header_ver != 1) errx(3, "wrong file format, last line %d", lc); if (uh.uh_data_size) datasize = uh.uh_data_size; else datasize = 2000; if (uh.uh_total_size) totalsize = uh.uh_total_size; else totalsize = datasize + 48; theupdate = malloc(totalsize); memcpy(theupdate, &uh, 48); if (getbin((char *)theupdate + 48, totalsize - 48) < 0) errx(3, "data format"); if (totalsize != datasize + 48) eh = (void *)((char *)theupdate + 48 + datasize); else eh = NULL; writeout(theupdate, totalsize, eh); free(theupdate); } fclose(in); exit(0); }
/* * Save the contents of the buffer argument into its associated file. Do * nothing if there have been no changes (is this a bug, or a feature?). * Error if there is no remembered file name. If this is the first write * since the read or visit, then a backup copy of the file is made. * Allow user to select whether or not to make backup files by looking at * the value of makebackup. */ int buffsave(struct buffer *bp) { int s; FILE *ffp; /* return, no changes */ if ((bp->b_flag & BFCHG) == 0) { ewprintf("(No changes need to be saved)"); return (TRUE); } /* must have a name */ if (bp->b_fname[0] == '\0') { dobeep(); ewprintf("No file name"); return (FALSE); } /* Ensure file has not been modified elsewhere */ /* We don't use the ignore flag here */ if (fchecktime(bp) != TRUE) { if ((s = eyesno("File has changed on disk since last save. " "Save anyway")) != TRUE) return (s); } if (makebackup && (bp->b_flag & BFBAK)) { s = fbackupfile(bp->b_fname); /* hard error */ if (s == ABORT) return (FALSE); /* softer error */ if (s == FALSE && (s = eyesno("Backup error, save anyway")) != TRUE) return (s); } if ((s = writeout(&ffp, bp, bp->b_fname)) == TRUE) { (void)fupdstat(bp); bp->b_flag &= ~(BFCHG | BFBAK); upmodes(bp); undo_add_boundary(FFRAND, 1); undo_add_modified(); } return (s); }
void avio_write(AVIOContext *s, const unsigned char *buf, int size) { if (s->direct && !s->update_checksum) { avio_flush(s); writeout(s, buf, size); return; } while (size > 0) { int len = FFMIN(s->buf_end - s->buf_ptr, size); memcpy(s->buf_ptr, buf, len); s->buf_ptr += len; if (s->buf_ptr >= s->buf_end) flush_buffer(s); buf += len; size -= len; } }
int diffBed(int argc, char * argv[]) { int help = 0; char *out = 0; int n, i; while ((n = getopt(argc, argv, "o:h")) >= 0) { switch(n) { case 'o': out = optarg; break; case 'h': help = 1; break; default: diffHelp(); } if (help) diffHelp(); } n = argc - optind; if(n < 2) errabort("At least 2 files!"); regHash_t * reghash, * reghash1; reghash = kh_init(reg); reghash1 = kh_init(reg); int ret = 0; bedHand->read(argv[optind], (void *)reghash, 0, 0, &ret); bedHand->merge(reghash); for (i = 1; i < n; ++i) { bedHand->read(argv[optind+i], (void *)reghash1, 0, 0, &ret); } bedHand->merge(reghash1); bedHand->diff(reghash, reghash1); inf_t * inf = bedHand->stat(reghash); if (ret) { warnings("the input bed file might not be standard bed format 0-based, please make sure the input files is in same base system" "you can use '1to0' to trans the base systems first"); } writeout("There are %d bp in the first file but not in others.\n", inf->length); freemem(inf); bedHand->destroy(reghash1, destroy_void); if (out) bedHand->save(out, reghash); bedHand->destroy(reghash, destroy_void); return 1; }
int main(int argc, char **argv) { char *hosts = NULL; FILE *fp; int c; char *me; if ( (me = strchr(argv[0],'/')) ) me++; else me = argv[0]; while((c = getopt(argc, argv, "f:")) > 0 ) { switch(c) { case 'f': hosts=strdup(optarg); break; default: usage(me); exit(0); } } if ( hosts == NULL ) hosts=strdup(HOSTS); read_hosts(hosts); read_command(); c = check_for_update(); if ( c && (fp=fopen(hosts,"w")) ) { writeout(fp); fclose(fp); } free_list(); if ( hosts ) free(hosts); return 0; }
/* * Ask for a file name, and write the contents of the current buffer to that * file. Update the remembered file name and clear the buffer changed flag. * This handling of file names is different from the earlier versions, and is * more compatable with Gosling EMACS than with ITS EMACS. Bound to "C-X C-W". */ int filewrite(int f, int n) { WINDOW *wp; char fname[NFILEN]; int s; if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) return (s); if ((s = writeout(fname)) == TRUE) { strncpy(curbp->b_fname, fname, NFILEN); curbp->b_flag &= ~BFCHG; wp = wheadp; /* Update mode lines */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return (s); }
/* * Ask for a file name, and write the * contents of the current buffer to that file. * Update the remembered file name and clear the * buffer changed flag. This handling of file names * is different from the earlier versions, and * is more compatable with Gosling EMACS than * with ITS EMACS. Bound to "C-X C-W". */ int filewrite(int f, int n) { struct window *wp; int s; char fname[NFILEN]; if (restflag) /* don't allow this command if restricted */ return resterr(); if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) return s; if ((s = writeout(fname)) == TRUE) { strcpy(curbp->b_fname, fname); curbp->b_flag &= ~BFCHG; wp = wheadp; /* Update mode lines. */ while (wp != NULL) { if (wp->w_bufp == curbp) wp->w_flag |= WFMODE; wp = wp->w_wndp; } } return s; }
/* * The seg_hack(1) program changes all segments names to the one specified on * the command line: * seg_hack NEWSEGNAME input -o output */ int main( int argc, char **argv, char **envp) { int i; char *input, *output; struct arch *archs; unsigned long narchs; struct stat stat_buf; progname = argv[0]; input = NULL; output = NULL; archs = NULL; narchs = 0; if(argc < 3){ usage(); return(EXIT_FAILURE); } segname = argv[1]; for(i = 2; i < argc; i++){ if(strcmp(argv[i], "-o") == 0){ if(i + 1 == argc){ error("missing argument(s) to: %s option", argv[i]); usage(); } if(output != NULL){ error("more than one: %s option specified", argv[i]); usage(); } output = argv[i+1]; i++; } else{ if(input != NULL){ error("more than one input file specified (%s and %s)", argv[i], input); usage(); } input = argv[i]; } } if(input == NULL || output == NULL) usage(); breakout(input, &archs, &narchs, FALSE); if(errors) return(EXIT_FAILURE); process(archs, narchs); /* create the output file */ if(stat(input, &stat_buf) == -1) system_error("can't stat input file: %s", input); writeout(archs, narchs, output, stat_buf.st_mode & 0777, TRUE, FALSE, FALSE, NULL); if(errors) return(EXIT_FAILURE); else return(EXIT_SUCCESS); }
virtual ~textout_ostream() { writeout(); }
int save_index (int writing_binlog) { hash_count = get_entry_cnt (); // hash_entry_t **p = zzmalloc (hash_count * sizeof (hash_entry_t *)); char *newidxname = NULL; if (engine_snapshot_replica) { newidxname = get_new_snapshot_name (engine_snapshot_replica, log_cur_pos(), engine_snapshot_replica->replica_prefix); } if (!newidxname || newidxname[0] == '-') { fprintf (stderr, "cannot write index: cannot compute its name\n"); exit (1); } if (log_cur_pos() == jump_log_pos) { fprintf (stderr, "skipping generation of new snapshot %s for position %lld: snapshot for this position already exists\n", newidxname, jump_log_pos); return 0; } if (verbosity > 0) { fprintf (stderr, "creating index %s at log position %lld\n", newidxname, log_cur_pos()); } newidx_fd = open (newidxname, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL, 0660); if (newidx_fd < 0) { fprintf (stderr, "cannot create new index file %s: %m\n", newidxname); exit (1); } index_header header; memset (&header, 0, sizeof (header)); header.magic = PMEMCACHED_INDEX_MAGIC; header.created_at = time (NULL); header.log_pos1 = log_cur_pos (); header.log_timestamp = log_read_until; if (writing_binlog) { relax_write_log_crc32 (); } else { relax_log_crc32 (0); } header.log_pos1_crc32 = ~log_crc32_complement; p = zzmalloc (hash_count * sizeof (hash_entry_t *)); assert (p); int x = (dump_pointers (p, 0, hash_count)); if (x != hash_count) { vkprintf (0, "dump_pointers = %d, hash_count = %d\n", x, hash_count); assert (0); } int p1 = 0; int p2 = 0; int total_elem = 0; while (p1 < hash_count || p2 < index_size) { //fprintf (stderr, "<"); int c = key_cmp(p1, p2); //fprintf (stderr, ">"); if (c == 0) { do_pmemcached_merge (p[p1]->key, p[p1]->key_len); } if (c <= 0) { assert (p1 < hash_count); assert (p[p1]); if (p[p1]->data_len < 0) { total_elem--; } p1++; } if (c >= 0) { p2++; } total_elem++; } header.nrecords = total_elem; writeout (&header, get_index_header_size (&header) );; long long shift = 0;//16*total_elem; p1 = 0; p2 = 0; while (p1 < hash_count || p2 < index_size) { int c = key_cmp(p1, p2); if (c <= 0) { if (p[p1]->data_len >= 0){ writeout_long (shift); shift += 13 + p[p1]->data_len + p[p1]->key_len; } p1++; } if (c >= 0) { if (c > 0) { writeout_long (shift); shift += 13 + index_get_by_idx (p2)->data_len + index_get_by_idx (p2)->key_len; } p2++; } } writeout_long (shift); if (verbosity >= 3) { fprintf (stderr, "writing offsets done\n"); } if (verbosity >= 3) { fprintf (stderr, "writing binary data\n"); } p1 = 0; p2 = 0; while (p1 < hash_count || p2 < index_size) { int c = key_cmp(p1, p2); if (c <= 0) { if (p[p1]->data_len >= 0){ struct hash_entry* entry = p[p1]; vkprintf (4, "Writing to index: key_len = %d, data_len = %d, p1 = %d, p[p1] = %p\n", (int)entry->key_len, entry->data_len, p1, p[p1]); writeout_short (entry->key_len); writeout_short (entry->flags); writeout_int (entry->data_len); writeout_int (entry->exp_time); writeout (entry->key, entry->key_len); writeout (entry->data, entry->data_len); writeout_char (0); } p1++; } if (c >= 0) { if (c > 0) { struct index_entry *entry = index_get_by_idx (p2); writeout (entry, sizeof(struct index_entry) + entry->key_len + entry->data_len); writeout_char (0); } p2++; } } if (verbosity >= 3) { fprintf (stderr, "writing binary data done\n"); } flushout (); assert (fsync (newidx_fd) >= 0); assert (close (newidx_fd) >= 0); if (verbosity >= 3) { fprintf (stderr, "writing index done\n"); } if (rename_temporary_snapshot (newidxname)) { fprintf (stderr, "cannot rename new index file from %s: %m\n", newidxname); unlink (newidxname); exit (1); } print_snapshot_name (newidxname); return 0; }
/* construct a url and print out its elements separated by commas and the whole spec */ nsresult testURL(const char* i_pURL, int32_t urlFactory = URL_FACTORY_DEFAULT) { if (i_pURL) return writeout(i_pURL, urlFactory); if (!gFileIO) return NS_ERROR_FAILURE; FILE *testfile = fopen(gFileIO, "rt"); if (!testfile) { fprintf(stderr, "Cannot open testfile: %s\n", gFileIO); return NS_ERROR_FAILURE; } char temp[512]; int count=0; int failed=0; nsCString prevResult; nsCString tempurl; while (fgets(temp,512,testfile)) { if (*temp == '#' || !*temp) continue; if (0 == count%3) { printf("Testing: %s\n", temp); writeoutto(temp, getter_Copies(prevResult), urlFactory); } else if (1 == count%3) { tempurl.Assign(temp); } else { if (prevResult.IsEmpty()) printf("no results to compare to!\n"); else { int32_t res; printf("Result: %s\n", prevResult.get()); if (urlFactory != URL_FACTORY_DEFAULT) { printf("Expected: %s\n", tempurl.get()); res = PL_strcmp(tempurl.get(), prevResult.get()); } else { printf("Expected: %s\n", temp); res = PL_strcmp(temp, prevResult.get()); } if (res == 0) printf("\tPASSED\n\n"); else { printf("\tFAILED\n\n"); failed++; } } } count++; } if (failed>0) { printf("%d tests FAILED out of %d\n", failed, count/3); return NS_ERROR_FAILURE; } else { printf("All %d tests PASSED.\n", count/3); return NS_OK; } }
virtual ~textout_console() { writeout(); }
/* * The ctf_insert(1) tool has the following usage: * * ctf_insert input -arch arch ctf_file ... -o output * * Where the input is a Mach-O file that is the ctf_file(s) are to be inserted * into and output is the file to be created. */ int main( int argc, char **argv, char **envp) { uint32_t i; char *input, *output, *contents; struct arch *archs; uint32_t narchs; struct stat stat_buf; int fd; progname = argv[0]; input = NULL; output = NULL; archs = NULL; narchs = 0; for(i = 1; i < argc; i++){ if(strcmp(argv[i], "-o") == 0){ if(i + 1 == argc){ error("missing argument to: %s option", argv[i]); usage(); } if(output != NULL){ error("more than one: %s option specified", argv[i]); usage(); } output = argv[i+1]; i++; } else if(strcmp(argv[i], "-arch") == 0){ if(i + 2 == argc){ error("missing argument(s) to: %s option", argv[i]); usage(); } else{ arch_ctfs = reallocate(arch_ctfs, (narch_ctfs + 1) * sizeof(struct arch_ctf)); if(get_arch_from_flag(argv[i+1], &(arch_ctfs[narch_ctfs].arch_flag)) == 0){ error("unknown architecture specification flag: " "%s %s %s", argv[i], argv[i+1], argv[i+2]); arch_usage(); usage(); } if((fd = open(argv[i+2], O_RDONLY, 0)) == -1) system_fatal("can't open file: %s", argv[i+2]); if(fstat(fd, &stat_buf) == -1) system_fatal("can't stat file: %s", argv[i+2]); /* * For some reason mapping files with zero size fails * so it has to be handled specially. */ contents = NULL; if(stat_buf.st_size != 0){ contents = mmap(0, stat_buf.st_size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); if((intptr_t)contents == -1) system_error("can't map file : %s", argv[i+2]); } arch_ctfs[narch_ctfs].filename = argv[i+2]; arch_ctfs[narch_ctfs].contents = contents; arch_ctfs[narch_ctfs].size = stat_buf.st_size; arch_ctfs[narch_ctfs].arch_found = FALSE; narch_ctfs++; i += 2; } } else{ if(input != NULL){ error("more than one input file file: %s specified", input); usage(); } input = argv[i]; } } if(input == NULL || output == NULL || narch_ctfs == 0) usage(); breakout(input, &archs, &narchs, FALSE); if(errors) exit(EXIT_FAILURE); checkout(archs, narchs); process(archs, narchs); for(i = 0; i < narch_ctfs; i++){ if(arch_ctfs[i].arch_found == FALSE) fatal("input file: %s does not contain a matching architecture " "for specified '-arch %s %s' option", input, arch_ctfs[i].arch_flag.name, arch_ctfs[i].filename); } writeout(archs, narchs, output, 0777, TRUE, FALSE, FALSE, FALSE, NULL); if(errors) return(EXIT_FAILURE); else return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { const char *optstr = "d:n:"; const char *outfile; char *local_buf; int c; tnf_uint32_t *magicp; tnf_block_header_t *block_base, *blockp; BLOCK_STATUS *block_stat, *bsp; int block_num; boolean_t any_unread, any_different, retry; tnf_ref32_t *fwzone; int fwzonesize; int i; int fwtries; int block_count; program_name = argv[0]; while ((c = getopt(argc, argv, optstr)) != EOF) { switch (c) { case 'd': dumpfile = optarg; break; case 'n': namelist = optarg; break; case '?': usage(argv, gettext("unrecognized argument")); } } if (optind != argc - 1) { usage(argv, gettext("too many or too few arguments")); } else { outfile = argv[optind]; } if ((dumpfile != NULL) ^ (namelist != NULL)) { usage(argv, gettext("must specify both or neither of the " "-d and -n options")); } output_fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (output_fd < 0) { perror(outfile); exit(1); } if (dumpfile != NULL) dumpfile_init(); else live_kernel_init(); if ((local_buf = malloc(tnf_bufsize)) == NULL) { (void) fprintf(stderr, gettext("tnfxtract memory allocation failure\n")); exit(1); } /* Read header, get block size, check for version mismatch */ read_tnf_header(local_buf); /*LINTED pointer cast may result in improper alignment*/ magicp = (tnf_uint32_t *) local_buf; /*LINTED pointer cast may result in improper alignment*/ tnf_header = (tnf_file_header_t *)(local_buf + sizeof (*magicp)); if (*magicp != TNF_MAGIC) { (void) fprintf(stderr, gettext( "Buffer is not in TNF format.\n")); exit(1); } if (tnf_header->file_version != TNF_FILE_VERSION) { (void) fprintf(stderr, gettext("Version mismatch (tnfxtract: %d; buffer: %d)\n"), TNF_FILE_VERSION, tnf_header->file_version); exit(1); } writeout(local_buf, 0, tnf_header->block_size); /* LINTED pointer cast may result in improper alignment */ block_base = (tnf_block_header_t *) (local_buf + tnf_header->directory_size); block_count = tnf_header->block_count - tnf_header->directory_size / tnf_header->block_size; fwzonesize = tnf_header->directory_size - tnf_header->block_size; block_stat = (BLOCK_STATUS *) calloc(block_count, sizeof (BLOCK_STATUS)); if (block_stat == NULL) { (void) fprintf(stderr, gettext("tnfxtract memory allocation failure\n")); exit(1); } for (bsp = block_stat; bsp != block_stat + block_count; ++bsp) bsp->ever_read = B_FALSE; /* * Make repeated passes until we've read every non-tag block. */ do { any_unread = B_FALSE; bsp = block_stat; block_num = 0; blockp = block_base; while (block_num != block_count) { if (!bsp->ever_read) { if (read_tnf_block(blockp, block_num) != 0) any_unread = B_TRUE; else { bsp->ever_read = B_TRUE; bsp->generation = blockp->generation; bsp->bytes_valid = blockp->bytes_valid; writeout((char *) blockp, /* LINTED cast 64 to 32 bit */ (int)((char *) blockp - local_buf), tnf_header->block_size); } } ++bsp; ++block_num; /* LINTED pointer cast may result in improper alignment */ blockp = (tnf_block_header_t *) ((char *) blockp + tnf_header->block_size); } } while (any_unread); /* * Then read tag blocks only, until we have two consecutive, * consistent reads. */ do { any_different = B_FALSE; bsp = block_stat; block_num = 0; blockp = block_base; while (block_num != block_count) { if (read_tnf_block(blockp, block_num) == 0 && blockp->generation == TNF_TAG_GENERATION_NUM && (bsp->generation != TNF_TAG_GENERATION_NUM || bsp->bytes_valid != blockp->bytes_valid)) { bsp->generation = TNF_TAG_GENERATION_NUM; bsp->bytes_valid = blockp->bytes_valid; writeout((char *) blockp, /* LINTED cast 64bit to 32 bit */ (int)((char *) blockp - local_buf), tnf_header->block_size); any_different = B_TRUE; } ++bsp; ++block_num; /* LINTED pointer cast may result in improper alignment */ blockp = (tnf_block_header_t *) ((char *) blockp + tnf_header->block_size); } } while (any_different); /* * Then read the forwarding pointers. If any are -1: * sleep briefly, then make another pass. */ /*LINTED pointer cast may result in improper alignment*/ fwzone = (tnf_ref32_t *)(local_buf + tnf_header->block_size); read_tnf_fwzone(fwzone, 0, /* LINTED cast from 64-bit integer to 32-bit integer */ (int)(fwzonesize / sizeof (fwzone[0]))); fwtries = 0; while (fwtries != MAXFWTRY) { retry = B_FALSE; for (i = 0; i != fwzonesize / sizeof (fwzone[0]); ++i) { if (fwzone[i] == -1) { read_tnf_fwzone(&fwzone[i], i, 1); if (!retry) { retry = B_TRUE; ++fwtries; } } } if (!retry) break; sleep(2); } if (fwtries == MAXFWTRY) { (void) fprintf(stderr, gettext( "Warning: forwarding pointers may " "be invalid.\n")); } writeout((char *) fwzone, tnf_header->block_size, fwzonesize); return (0); }
/* * The codesign_allocate(1) tool has the following usage: * * codesign_allocate -i oldfile -a arch size ... -o newfile * * Where the oldfile is a Mach-O file that is input for the dynamic linker * and it creates or adds an */ int main( int argc, char **argv, char **envp) { uint32_t i; char *input, *output, *endp; struct arch *archs; uint32_t narchs; progname = argv[0]; input = NULL; output = NULL; archs = NULL; narchs = 0; for(i = 1; i < argc; i++) { if(strcmp(argv[i], "-i") == 0) { if(i + 1 == argc) { error("missing argument to: %s option", argv[i]); usage(); } if(input != NULL) { error("more than one: %s option specified", argv[i]); usage(); } input = argv[i+1]; i++; } else if(strcmp(argv[i], "-o") == 0) { if(i + 1 == argc) { error("missing argument to: %s option", argv[i]); usage(); } if(output != NULL) { error("more than one: %s option specified", argv[i]); usage(); } output = argv[i+1]; i++; } else if(strcmp(argv[i], "-a") == 0) { if(i + 2 == argc) { error("missing argument(s) to: %s option", argv[i]); usage(); } else { arch_signs = reallocate(arch_signs, (narch_signs + 1) * sizeof(struct arch_sign)); if(get_arch_from_flag(argv[i+1], &(arch_signs[narch_signs].arch_flag)) == 0) { error("unknown architecture specification flag: " "%s %s %s", argv[i], argv[i+1], argv[i+2]); arch_usage(); usage(); } arch_signs[narch_signs].datasize = strtoul(argv[i+2], &endp, 0); if(*endp != '\0') fatal("size for '-a %s %s' not a proper number", argv[i+1], argv[i+2]); if((arch_signs[narch_signs].datasize % 16) != 0) fatal("size for '-a %s %s' not a multiple of 16", argv[i+1], argv[i+2]); arch_signs[narch_signs].found = FALSE; narch_signs++; i += 2; } } else if(strcmp(argv[i], "-A") == 0) { if(i + 3 == argc) { error("missing argument(s) to: %s option", argv[i]); usage(); } else { arch_signs = reallocate(arch_signs, (narch_signs + 1) * sizeof(struct arch_sign)); arch_signs[narch_signs].arch_flag.cputype = strtoul(argv[i+1], &endp, 0); if(*endp != '\0') fatal("cputype for '-A %s %s %s' not a proper number", argv[i+1], argv[i+2], argv[i+3]); arch_signs[narch_signs].arch_flag.cpusubtype = strtoul(argv[i+2], &endp, 0); if(*endp != '\0') fatal("cpusubtype for '-A %s %s %s' not a proper " "number", argv[i+1], argv[i+2], argv[i+3]); arch_signs[narch_signs].arch_flag.name = (char *) get_arch_name_from_types( arch_signs[narch_signs].arch_flag.cputype, arch_signs[narch_signs].arch_flag.cpusubtype); arch_signs[narch_signs].datasize = strtoul(argv[i+3], &endp, 0); if(*endp != '\0') fatal("size for '-A %s %s %s' not a proper number", argv[i+1], argv[i+2], argv[i+3]); if((arch_signs[narch_signs].datasize % 16) != 0) fatal("size for '-A %s %s %s' not a multiple of 16", argv[i+1], argv[i+2], argv[i+3]); arch_signs[narch_signs].found = FALSE; narch_signs++; i += 3; } } else { error("unknown flag: %s", argv[i]); usage(); } } if(input == NULL || output == NULL || narch_signs == 0) usage(); breakout(input, &archs, &narchs, FALSE); if(errors) exit(EXIT_FAILURE); checkout(archs, narchs); process(archs, narchs); for(i = 0; i < narch_signs; i++) { if(arch_signs[i].found == FALSE) fatal("input file: %s does not contain a matching architecture " "for specified '-a %s %u' option", input, arch_signs[i].arch_flag.name, arch_signs[i].datasize); } writeout(archs, narchs, output, 0777, TRUE, FALSE, FALSE, NULL); if(errors) return(EXIT_FAILURE); else return(EXIT_SUCCESS); }
/* * filter a buffer through an external DOS program * Bound to ^X # * We use unique temporary file names so that multiple instances of * MicroEMACS don't try to use the same file. */ filter(f, n) { register int s; /* return status from CLI */ register BUFFER *bp; /* pointer to buffer to zot */ char line[NLINE]; /* command line send to shell */ char tmpnam[NFILEN]; /* place to store real file name */ char *tmp; /* ptr to TMP DOS environment variable */ static char filnam1[NSTRING]; static char filnam2[NSTRING]; /* don't allow this command if restricted */ if (restflag) return(resterr()); if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ /* get the filter name and its args */ if ((s=mlreply("#", line, NLINE)) != TRUE) return(s); /* Call mktemp() to get unique filenames in the tmp directory. */ if ((tmp = getenv("TMP")) == NULL) filnam1[0] = filnam2[0] = 0; else { strcpy(filnam1, tmp); strcpy(filnam2, tmp); if (filnam1[strlen(filnam1) - 1] != '\\') { strcat(filnam1, "\\"); strcat(filnam2, "\\"); } } strcat(filnam1,"eXXXXXX"); strcat(filnam2,"eXXXXXX"); mktemp(filnam1); /* setup the proper file names */ bp = curbp; strcpy(tmpnam, bp->b_fname); /* save the original name */ strcpy(bp->b_fname, filnam1); /* set it to our new one */ /* write it out, checking for errors */ if (writeout(filnam1, "w") != TRUE) { mlwrite(TEXT2); /* "[Cannot write filter file]" */ strcpy(bp->b_fname, tmpnam); return(FALSE); } mktemp(filnam2); strcat(line, " <"); /* construct the command line */ strcat(line, filnam1); strcat(line, " >"); strcat(line, filnam2); movecursor(term.t_nrow - 1, 0); TTkclose(); system(line); TTkopen(); sgarbf = TRUE; s = TRUE; /* on failure, escape gracefully */ if (s != TRUE || (readin(filnam2,FALSE) == FALSE)) { mlwrite(TEXT3); /* "[Execution failed]" */ strcpy(bp->b_fname, tmpnam); unlink(filnam1); unlink(filnam2); return(s); } /* reset file name */ strcpy(bp->b_fname, tmpnam); /* restore name */ bp->b_flag |= BFCHG; /* flag it as changed */ /* and get rid of the temporary file */ unlink(filnam1); unlink(filnam2); return(TRUE); }
int main(int argc, char* argv[]) { char buff[2048]; char *t; int i, rv; int partial = 0; struct header *cur_hdr = NULL; char *datefmt = NULL; char *headerlist = NULL; char *fieldname, *next; char create_real_name = 0; #ifdef HAVE_ICONV const char **charsetptr = &Charset; #endif /* process command line arguments: */ if (argc > 1) { i = 1; while (i < argc) { if (!strcmp (argv[i], "-d") && i+1 < argc) { datefmt = argv[++i]; } else if (!strcmp (argv[i], "-x") && i+1 < argc) { headerlist = argv[++i]; #ifdef HAVE_ICONV } else if (!strcmp (argv[i], "-c") && i+1 < argc) { *charsetptr = argv[++i]; #endif } else if (!strcmp (argv[i], "-a")) { create_real_name = 1; } else if (!strcmp (argv[i], "-e")) { print_email_only = 1; } else { fprintf (stderr, "%s: `%s' wrong parameter\n", argv[0], argv[i]); } i++; } } if (!datefmt) datefmt = safe_strdup("%Y-%m-%d %H:%M"); if (headerlist && strlen (headerlist) > 0 ) { fieldname = headerlist; i = 0; while ( i < MAXHDRS-1 && (next = strchr (fieldname, ':'))) { hdr[i].tag = safe_malloc (next - fieldname + 2); strncpy (hdr[i].tag, fieldname, next - fieldname); hdr[i].tag[next - fieldname] = ':'; hdr[i].tag[next - fieldname + 1] = '\0'; hdr[i].taglen = next - fieldname + 1; fieldname = next+1; i++; } if (i < MAXHDRS-1 && *fieldname != '\0') { hdr[i].tag = safe_malloc (strlen (fieldname) + 2); strncpy (hdr[i].tag, fieldname, strlen (fieldname)); hdr[i].tag[strlen (fieldname)] = ':'; hdr[i].tag[strlen (fieldname) + 1] = '\0'; hdr[i].taglen = strlen (fieldname) + 1; i++; } hdr[i].tag = NULL; /* end of hdr list */ } while(fgets(buff, sizeof(buff), stdin)) { if(!partial && *buff == '\n') break; if(cur_hdr && (partial || *buff == ' ' || *buff == '\t')) { size_t nl = cur_hdr->len + strlen(buff); safe_realloc((void **) &cur_hdr->value, nl + 1); strcpy(cur_hdr->value + cur_hdr->len, buff); cur_hdr->len = nl; chop(cur_hdr); } else if(!partial && *buff != ' ' && *buff != '\t') { cur_hdr = NULL; for(i = 0; hdr[i].tag; i++) { if(!strncasecmp(buff, hdr[i].tag, hdr[i].taglen)) { cur_hdr = &hdr[i]; break; } } if(cur_hdr) { safe_free(&cur_hdr->value); cur_hdr->value = safe_strdup(buff + cur_hdr->taglen); cur_hdr->len = strlen(cur_hdr->value); chop(cur_hdr); } } if(!(t = strchr(buff, '\n'))) partial = 1; else partial = 0; } for(rv = 0, i = 0; hdr[i].tag; i++) { if(hdr[i].value) rv = writeout(&hdr[i], datefmt, create_real_name) || rv; } return (rv ? 0 : 1); }