Esempio n. 1
0
extern void
artHeader_write(artHeader_t header, const char *headerFileName)
{
	assert(header != NULL);
	assert(headerFileName != NULL);

	FILE     *f;
	int      blocksize;
	endian_t systemEndianess = endian_getSystemEndianess();

	f         = xfopen(headerFileName, "wb");
	blocksize = ARTHEADER_HEADERSTRING_LENGTH + 121 * sizeof(float);
	if (header->fileEndianess != systemEndianess) {
		local_byteswapHeader(header);
		byteswap(&blocksize, sizeof(int));
	}

	xfwrite(&blocksize, sizeof(int), 1, f);
	xfwrite(header->headerString, sizeof(char),
	        ARTHEADER_HEADERSTRING_LENGTH, f);
	xfwrite(&(header->aexpn), sizeof(float), 121, f);
	xfwrite(&blocksize, sizeof(int), 1, f);

	if (header->fileEndianess != systemEndianess)
		local_byteswapHeader(header);

	xfclose(&f);
}
//writes a huffresult array to the file.
static void writeHuffmanTable(FILE *file, huffResult * resultArray)
{
    char * newLine = "\n";
    for(int i = 0; i < 256; i++)
    {
        huffResult *currentResult = &resultArray[i];
        xfwrite(currentResult->string, sizeof(char),
            strlen(currentResult->string), file);
        xfwrite(newLine, sizeof(char), strlen(newLine), file);
    }
}
Esempio n. 3
0
/* build the new symbol and string tables
*/
static void buildNewTables(const HDR *x, long nsyms)
{
	long remaining = nsyms;  // total number of symbol table entries remaining to process
#if FAST_NONPORTABLE_STRUCT_ARRAY_READ
	const int bunch = 1024;  // number of symbol table entries to process at a time	
#else
	const int bunch = 1;
#endif
	char *syms = new char[bunch*SYMSZ];	// buffer of old symbol table entries
	fseek(sym, N_SYMOFF(*x), 0);		// go to old symbol table
						// fill the buffer
	int numInBuffer = xfread(syms, SYMSZ, min(bunch, remaining), sym);  
	int symsi = 0;				// index in buffer
	char *thisSym = syms;			// pointer to entry symsi in buffer
	int auxEntries = 0;			// number of aux entries still to skip over
	while (remaining)
	{
		if (auxEntries)  // skip over them
		{
			if (auxEntries < 0)
				fatalError("Bad symbol table");
			int skip = min(numInBuffer-symsi, auxEntries);
			if (remaining < skip)
				fatalError("Bad symbol table (missing auxiliary entries)");
			auxEntries -= skip;
			remaining -= skip;
			symsi += skip;
			thisSym += skip*SYMSZ;
		}
		else
		{
			transformSymEntry((SYM*)thisSym);
			auxEntries = N_AUX(*(SYM*)thisSym);
			remaining--;
			symsi++;
			thisSym += SYMSZ;
		}
		assert (symsi <= bunch);
		if (symsi == bunch)  // write and then refill the buffer
		{
			xfwrite(syms, SYMSZ, numInBuffer, newSym);
			numInBuffer = xfread(syms, SYMSZ, min(bunch, remaining), sym);
			symsi = 0;
			thisSym = syms;
		}	
	}
	xfwrite(syms, SYMSZ, numInBuffer, newSym);
	delete syms;  
}
Esempio n. 4
0
static void pack_file(FILE *fp, char *filename, const struct stat *sb)
{
    size_t fnlen = strlen(filename);
    FILE *srcfp = xfopen(filename, "r");
    char *sep;

    for (sep = filename; (sep = strchr(sep, '/'));)
        *sep = '\\';

    xfwritedw(fnlen, fp);
    xfwrite(filename, fnlen, 1, fp);   
    xfwrite(" ", 1, 1, fp);
    xfwritedw(sb->st_size, fp);
    copy_data(srcfp, fp, sb->st_size);
    fclose(srcfp);
}
Esempio n. 5
0
static void write_header(FILE *fp, uint32_t size, uint32_t chksum,
                         const char *desc)
{
    char buf[17];
    time_t cur_time = time(NULL);
    struct tm *cur_tm = localtime(&cur_time);
    size_t desc_len = strlen(desc);

    xfwritedw(HXF_SIGNATURE, fp);
    strftime(buf, sizeof(buf), "0100%Y%m%d%H%M", cur_tm);
    xfwrite(buf, 16, 1, fp);
    xfwritedw(size, fp);
    xfwritedw(chksum, fp);
    xfwritedw(0, fp);
    xfwrite(desc, desc_len > 32 ? 32 : desc_len, 1, fp);
}
Esempio n. 6
0
afs_uint32
WriteTagByte(XFILE * X, unsigned char tag, unsigned char val)
{
    char buffer[2];
    buffer[0] = tag;
    buffer[1] = val;
    return xfwrite(X, buffer, 2);
}
Esempio n. 7
0
/* overwrite file from onto to, starting at current location of to.
*/
void overwrite(FILE *from, FILE *to)
{
	fseek(from, 0, 0);
	char *c = new char[bufsize];
	int i;
	while ((i=fread(c, sizeof(char), bufsize, from)) > 0)
		xfwrite(c, sizeof(char), i, to);
	delete c;
}
Esempio n. 8
0
afs_uint32
WriteTagInt16(XFILE * X, unsigned char tag, afs_uint16 val)
{
    char buffer[3];
    buffer[0] = tag;
    buffer[1] = (val & 0xff00) >> 8;
    buffer[2] = val & 0xff;
    return xfwrite(X, buffer, 3);
}
Esempio n. 9
0
/*
 * Function to write the EVD for the disc.
 */
static int FDECL1(tvd_write, FILE *, outfile)
{
  /*
   * Next we write out the boot volume descriptor for the disc 
   */
  get_torito_desc(&gboot_desc);
  xfwrite(&gboot_desc, 1, 2048, outfile);
  last_extent_written ++;
  return 0;
}
Esempio n. 10
0
/* do_write for profiled xfiles */
static afs_uint32
xf_PROFILE_do_write(XFILE * X, void *buf, afs_uint32 count)
{
    PFILE *PF = X->refcon;
    afs_uint32 err;

    err = xfwrite(&PF->content, buf, count);
    xfprintf(&PF->profile, "W %ld =%ld\n", (long)count, (long)err);
    return err;
}
Esempio n. 11
0
afs_uint32
WriteTagInt32(XFILE * X, unsigned char tag, afs_uint32 val)
{
    char buffer[5];
    buffer[0] = tag;
    buffer[1] = (val & 0xff000000) >> 24;
    buffer[2] = (val & 0xff0000) >> 16;
    buffer[3] = (val & 0xff00) >> 8;
    buffer[4] = val & 0xff;
    return xfwrite(X, buffer, 5);
}
Esempio n. 12
0
static int write_image_to_file(const image_t *image, const char *filename)
{
	FILE *fp;

	fp = fopen(filename, "wb");
	if (fp == NULL)
		log_err("fopen");
	xfwrite(image->buffer, image->toc_e.size, fp, filename);
	fclose(fp);
	return 0;
}
Esempio n. 13
0
/* Write spaces faster than one at a time */
static afs_uint32
wsp(XFILE * X, int count)
{
    char *x;
    afs_uint32 err;
    int i;

    if (!spbuf[0]) {
	for (x = spbuf, i = SPBUFLEN; i; x++, i--)
	    *x = ' ';
    }

    while (count > SPBUFLEN) {
	err = xfwrite(X, spbuf, SPBUFLEN);
	if (err)
	    return err;
	count -= SPBUFLEN;
    }
    if (count > 0)
	return xfwrite(X, spbuf, count);
    return 0;
}
Esempio n. 14
0
static Boolean flush(unsigned int n)
/*****************************************************************************
 * 0 if ok 1 if error in static global err_status
 *****************************************************************************/
{
	assert(n < 256);
	xfputc(n, gif_save_file);
	if (xfwrite(gif_byte_buff, 1, n, gif_save_file) < n)
	{
		err_status = xerrno();
		return(1);
	}
	return(0);
}
Esempio n. 15
0
static void _bta_write_cell(FILE *fp, bta_cell_t *btac)
{
	fp_write16le(fp, btac->x);
	fp_write16le(fp, btac->y);
	fp_write16le(fp, btac->width);
	fp_write16le(fp, btac->height);
	fp_write16le(fp, btac->delay);

	btac->gfx = zlib_compress(btac->gfx);

	/* Write the compressed size */
	fp_write32le(fp, btac->gfx->size);
	xfwrite(btac->gfx->buf, sizeof(uint8_t), btac->gfx->size, fp);
}
Esempio n. 16
0
File: fileIO.c Progetto: pingwei/CMS
void do_output_file(char *sfile)
{
	FILE *fp;

	fp = fopen( sfile, "wb" );
	if( fp == NULL )  {
		ErrMsg( "* File Open Error ... %s\n", sfile );
		return;
	}
	xfwrite( wave.data, sizeof(short), wave.nsample, fp );
	fclose( fp );

	do_output_info(sfile);
}
Esempio n. 17
0
static void overwriteOldTables(const HDR *x)
{
	// write the new symbol table to the original a.out,
	// beginning at the beginning of the original symbol table
	fseek(sym, N_SYMOFF(*x), 0);
	overwrite(newSym, sym);

	// write the new string table to the original a.out,
	// beginning right after the new symbol table
	long len = ftell(newSng) + 4;
	xfwrite(&len, 4, 1, sym);
	overwrite(newSng, sym);

	// rem: truncate, but probably doesn't need it.
}
Esempio n. 18
0
static int
copyfile(XFILE * in, XFILE * out, int size)
{
    static char buf[COPYBUFSIZE];
    int nr, r;

    while (size) {
	nr = (size > COPYBUFSIZE) ? COPYBUFSIZE : size;
	if ((r = xfread(in, buf, nr)))
	    return r;
	if ((r = xfwrite(out, buf, nr)))
	    return r;
	size -= nr;
    }
    return 0;
}
Esempio n. 19
0
afs_uint32
WriteTagInt32Pair(XFILE * X, unsigned char tag, afs_uint32 val1,
		  afs_uint32 val2)
{
    char buffer[9];
    buffer[0] = tag;
    buffer[1] = (val1 & 0xff000000) >> 24;
    buffer[2] = (val1 & 0xff0000) >> 16;
    buffer[3] = (val1 & 0xff00) >> 8;
    buffer[4] = val1 & 0xff;
    buffer[5] = (val2 & 0xff000000) >> 24;
    buffer[6] = (val2 & 0xff0000) >> 16;
    buffer[7] = (val2 & 0xff00) >> 8;
    buffer[8] = val2 & 0xff;
    return xfwrite(X, buffer, 9);
}
Esempio n. 20
0
afs_uint32
xfread(XFILE * X, void *buf, afs_uint32 count)
{
    afs_uint32 code;
    u_int64 tmp64;

    code = (X->do_read) (X, buf, count);
    if (code)
	return code;

    add64_32(tmp64, X->filepos, count);
    cp64(X->filepos, tmp64);
    if (X->passthru)
	return xfwrite(X->passthru, buf, count);
    return 0;
}
Esempio n. 21
0
static void
local_writeParticle(FILE        *f,
                    const float *partData,
                    bool        doByteswap)
{
	for (int i = 0; i < 6; i++) {
		if (isnan(partData[i]))
			xfseek(f, sizeof(float), SEEK_CUR);
		else {
			float val = partData[i];
			if (doByteswap)
				byteswap(&val, sizeof(float));
			xfwrite(&val, sizeof(float), 1, f);
		}
	}
}
Esempio n. 22
0
static void mem_file_sync(struct mem_file *mf, FILE *file, uint64_t rel_offset)
{
	struct mem_block *mb;

	if (rel_offset != 0) {
		struct mem_file_reloc *rel;

		always_assert(!mf->relocs || rel_offset != OFFSET_NORELOC);

		for (rel = mf->relocs; rel; rel = rel->next)
			*rel->ptr += rel_offset;
	}

	for (mb = mf->head; mb; mb = mb->next)
		xfwrite(mb->base, mb->wptr - mb->base, file);
}
Esempio n. 23
0
File: port.c Progetto: KeenS/benz
static pic_value
pic_port_open_input_blob(pic_state *pic)
{
  struct pic_port *port;
  struct pic_blob *blob;

  pic_get_args(pic, "b", &blob);

  port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port *), PIC_TT_PORT);
  port->file = xmopen();
  port->flags = PIC_PORT_IN | PIC_PORT_BINARY;
  port->status = PIC_PORT_OPEN;

  xfwrite(blob->data, 1, blob->len, port->file);
  xfflush(port->file);
  xrewind(port->file);

  return pic_obj_value(port);
}
Esempio n. 24
0
static void
local_writeComponent(art_t    art,
                     uint64_t pSkip,
                     uint64_t pWrite,
                     stai_t   component,
                     bool     doByteswap)
{
	if ((component == NULL) || (pSkip == art->numParticlesInPage)) {
		xfseek(art->f, art->numParticlesInPage * sizeof(float), SEEK_CUR);
		return;
	}
	float *buffer;
	bool  bufferIsAllocated = false;

	if (stai_isLinear(component)
	    && (stai_getSizeOfElementInBytes(component) == sizeof(float))) {
		buffer = stai_getBase(component);
	} else {
		buffer            = xmalloc(sizeof(float) * pWrite);
		bufferIsAllocated = true;
		local_fillBufferFromStai(buffer, component, pWrite);
	}

	if (doByteswap) {
		for (int i = 0; i < pWrite; i++)
			byteswap(buffer + i, sizeof(float));
	}

	xfseek(art->f, (long)pSkip * sizeof(float), SEEK_CUR);
	xfwrite(buffer, sizeof(float), pWrite, art->f);
	xfseek(art->f,
	       (long)(art->numParticlesInPage - pSkip - pWrite) * sizeof(float),
	       SEEK_CUR);

	if (doByteswap && !bufferIsAllocated) {
		// Restore the original byte order of the data array.
		for (int i = 0; i < art->numParticlesInPage; i++)
			byteswap(buffer + i, sizeof(float));
	}
	if (bufferIsAllocated)
		xfree(buffer);
} /* local_writeComponent */
Esempio n. 25
0
/* process a single symbol table entry.
*  (notice that all non-SYSV strings are in the string table.)
*/
static void transformSymEntry(SYM *n)
{
	String s = buildNewString(n);
#ifdef SYSV
	n->n_zeroes = 0;
#endif
	N_STRINDEX(*n) = 0;				
	if (s.length() > 0)
	{
		const char *t = (const char*)s;
#ifdef SYSV
		if (s.length() <= SYMNMLEN)
			strncpy(n->n_name, t, SYMNMLEN);
		else
#endif
		{
			N_STRINDEX(*n) = newSngLoc;  // fix n's index 
			newSngLoc += xfwrite(t, sizeof(char), s.length()+1, newSng);  // write the new string
		}
	}
}
Esempio n. 26
0
/* Dump a stage backup header */
afs_uint32
DumpStageHdr(XFILE * OX, backup_system_header * hdr)
{
    char buf[STAGE_HDRLEN];
    struct stage_header *bckhdr = (struct stage_header *)buf;
    afs_uint32 checksum;
    afs_uint32 r;

    memset(buf, 0, STAGE_HDRLEN);
    bckhdr->c_vers = hdr->version;
    bckhdr->c_fdate = htonl(hdr->from_date);
    bckhdr->c_tdate = htonl(hdr->to_date);
    bckhdr->c_filenum = htonl(hdr->filenum);
    bckhdr->c_time = htonl(hdr->dump_date);
    bckhdr->c_id = htonl(hdr->volid);
#ifdef NATIVE_INT64
    bckhdr->c_length = htonl((afs_uint32) hdr->dumplen);
#else
    bckhdr->c_length = htonl(hdr->dumplen.lo);
#endif
    bckhdr->c_level = htonl(hdr->level);
    bckhdr->c_magic = htonl(STAGE_MAGIC);
    bckhdr->c_flags = htonl(hdr->flags);

    strcpy(bckhdr->c_host, (char *)hdr->server);
    strcpy(bckhdr->c_disk, (char *)hdr->part);
    strcpy(bckhdr->c_name, (char *)hdr->volname);

    /* Now, compute the checksum */
    checksum = hdr_checksum(buf, STAGE_HDRLEN);
    bckhdr->c_checksum = htonl(STAGE_CHECKSUM - checksum);

    if ((r = xfwrite(OX, buf, STAGE_HDRLEN)))
	return r;
    return 0;
}
Esempio n. 27
0
static void my_expr_print_file_helper(void *data, struct symbol *sym, const char *str)
{
	xfwrite(str, strlen(str), 1, data);
}
Esempio n. 28
0
static int boot_mips_write(FILE *outfile)
{
	struct directory_entry	*boot_file;	/* Boot file we need to search for */
    unsigned long length = 0;
    unsigned long extent = 0;
	int i;
	struct volume_header vh;
    unsigned long long iso_size = 0;
    char *filename = NULL;

	memset(&vh, 0, sizeof(vh));

    iso_size = last_extent * 2048;

    write_be32(VHMAGIC, (unsigned char *)&vh.vh_magic);

	/* Values from an IRIX cd */
    write_be16(BYTES_PER_SECTOR, (unsigned char *)&vh.vh_dp.dp_secbytes);
    write_be16(SECTORS_PER_TRACK, (unsigned char *)&vh.vh_dp.dp_secs);
    write_be32(DP_RESEEK|DP_IGNOREERRORS|DP_TRKFWD, (unsigned char *)&vh.vh_dp.dp_flags);
    write_be16(1, (unsigned char *)&vh.vh_dp.dp_trks0);

    write_be16((iso_size + BYTES_PER_SECTOR - 1) / (SECTORS_PER_TRACK * BYTES_PER_SECTOR),
               (unsigned char *)&vh.vh_dp.dp_cyls);

	for(i = 0; i < boot_mips_num_files; i++)
    {
        boot_file = search_tree_file(root, boot_mips_filename[i]);
        
        if (!boot_file) {
#ifdef	USE_LIBSCHILY
            comerrno(EX_BAD, "Uh oh, I cant find the MIPS boot file '%s'!\n",
                     boot_mips_filename[i]);
#else
            fprintf(stderr, "Uh oh, I cant find the MIPS boot file '%s'!\n",
                    boot_mips_filename[i]);
            exit(1);
#endif
        }

        extent = get_733(boot_file->isorec.extent) * 4;
        length = ((get_733(boot_file->isorec.size) + 2047) / 2048) * 2048;
        filename = file_base_name(boot_mips_filename[i]);

        strncpy((char *)vh.vh_vd[i].vd_name, filename, MIN(VDNAMESIZE, strlen(filename)));
        write_be32(extent, (unsigned char *)&vh.vh_vd[i].vd_lbn);
        write_be32(length, (unsigned char *)&vh.vh_vd[i].vd_nbytes);
        
        fprintf(stderr, "Found mips boot image %s, using extent %lu (0x%lX), #blocks %lu (0x%lX)\n",
                filename, extent, extent, length, length);
	}

	/* Create volume partition on whole cd iso */
    write_be32((iso_size + (BYTES_PER_SECTOR - 1))/ BYTES_PER_SECTOR, (unsigned char *)&vh.vh_pt[10].pt_nblks);
    write_be32(0, (unsigned char *)&vh.vh_pt[10].pt_firstlbn);
    write_be32(PTYPE_VOLUME, (unsigned char *)&vh.vh_pt[10].pt_type);

	/* Create volume header partition, also on WHOLE cd iso */
    write_be32((iso_size + (BYTES_PER_SECTOR - 1))/ BYTES_PER_SECTOR, (unsigned char *)&vh.vh_pt[8].pt_nblks);
    write_be32(0, (unsigned char *)&vh.vh_pt[8].pt_firstlbn);
    write_be32(PTYPE_VOLHDR, (unsigned char *)&vh.vh_pt[8].pt_type);

	/* Create checksum */
	vh_calc_checksum(&vh);

    jtwrite(&vh, sizeof(vh), 1, 0, FALSE);
    xfwrite(&vh, sizeof(vh), 1, outfile, 0, FALSE);
    last_extent_written++;

	return 0;
}
Esempio n. 29
0
static void
unit_map_entry(void)
{
  xfwrite(unit_fn, TRUE, &data.u, sizeof(struct wm_uid), 1, unit_fp);
}
Esempio n. 30
0
static void
kwic_map_entry(void)
{
  xfwrite(kwic_fn, TRUE, &data.w, sizeof(struct wm_wid), 1, kwic_fp);
}