コード例 #1
0
ファイル: datafile.cpp プロジェクト: Crises/teeworlds
bool CDataFileReader::GetCrcSize(class IStorage *pStorage, const char *pFilename, int StorageType, unsigned *pCrc, unsigned *pSize)
{
	IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
	if(!File)
		return false;

	// get crc and size
	unsigned Crc = 0;
	unsigned Size = 0;
	unsigned char aBuffer[64*1024];
	while(1)
	{
		unsigned Bytes = io_read(File, aBuffer, sizeof(aBuffer));
		if(Bytes <= 0)
			break;
		Crc = crc32(Crc, aBuffer, Bytes); // ignore_convention
		Size += Bytes;
	}

	io_close(File);

	*pCrc = Crc;
	*pSize = Size;
	return true;
}
コード例 #2
0
ファイル: run-19-always.c プロジェクト: pastcompute/pettycoin
static void init_conn(int fd, struct data *d)
{
	ok1(d->state == 0);
	d->state++;
	/* Empty read should run immediately... */
	io_set_finish(io_new_conn(fd, io_read(NULL, 0, write_buf, d)),
		      finish_ok, d);
}
コード例 #3
0
ファイル: io.c プロジェクト: vaughan0/vlib
static size_t limited_read(void* _self, char* dst, size_t n) {
  LimitedInput* self = _self;
  n = MIN(n, self->limit - self->read);
  if (n == 0) return 0;
  size_t r = io_read(self->in, dst, n);
  self->read += r;
  return r;
}
コード例 #4
0
UINT32 fscc_card_get_register(struct fscc_card *card, unsigned bar,
                              unsigned offset)
{
    void *address = 0;

    address = fscc_card_get_BAR(card, bar);

    return io_read(card, bar, (ULONG *)((char *)address + offset));
}
コード例 #5
0
ファイル: io.c プロジェクト: Tinkerforge/io16-bricklet
void update_interrupt_callback(const uint8_t port_num) {
	uint8_t new_gpio = io_read(I2C_INTERNAL_ADDRESS_GPIO_A + port_num);
	uint8_t interrupt_mask = (new_gpio ^ BC->current_gpio[port_num]) & BC->current_gpinten[port_num];

	BC->current_gpio[port_num] = new_gpio;

	BC->interrupt_callback_mask[port_num] = interrupt_mask;
	BC->interrupt_callback_value[port_num] = new_gpio;
}
コード例 #6
0
ファイル: io.c プロジェクト: vaughan0/vlib
void io_readall(Input* input, void* _dst, size_t n) {
  char* dst = _dst;
  while (n) {
    size_t read = io_read(input, dst, n);
    if (read == 0) RAISE(EOF);
    n -= read;
    dst += read;
  }
}
コード例 #7
0
ファイル: run-02-read.c プロジェクト: Honglongwu/ccan
static void init_conn(int fd, struct data *d)
{
	ok1(d->state == 0);
	d->state++;

	io_set_finish(io_new_conn(fd,
				  io_read(d->buf, sizeof(d->buf), io_close_cb, d)),
		      finish_ok, d);
}
コード例 #8
0
ファイル: speex.c プロジェクト: jonsafari/mocp
static void get_more_data (struct spx_data *data)
{
	char *buf;
	ssize_t nb_read;

	buf = ogg_sync_buffer (&data->oy, 200);
	nb_read = io_read (data->stream, buf, 200);
	ogg_sync_wrote (&data->oy, nb_read);
}
コード例 #9
0
ファイル: run-19-always.c プロジェクト: cdecker/lightning
static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
{
	ok1(d->state == 0);
	d->state++;
	io_set_finish(conn, finish_ok, d);

	/* Empty read should run immediately... */
	return io_read(conn, NULL, 0, write_buf, d);
}
コード例 #10
0
/**
 * Debug device
 * @param[in,out] ctx context information
 * @return error code
 */
int hdmi_rx_ctrl_debug(struct hdmi_rx_ctrl *ctx)
{
	int error = 0;
	struct hdmi_rx_ctrl_video v;
	struct hdmi_rx_ctrl_audio a;

	if (ctx == 0) {
		return -EINVAL;
	}
	if (ctx->status <= 0) {		/* is not configured? */
		return -EPERM;
	}
	ctx->log_info("%s", file);
	ctx->log_info("  Config clock: %3u.%03uMHz",
			ctx->cfg_clk / 1000, ctx->cfg_clk % 1000);
	ctx->log_info("  TMDS clock:   %3u.%03uMHz",
			ctx->tmds_clk / 1000, ctx->tmds_clk % 1000);
	error |= hdmi_rx_ctrl_get_video(ctx, &v);
	if (error == 0) {
		ctx->log_info("  Video: %ux%u%c@%u.%02uHz: %s, DCM %ub",
				v.hactive, v.vactive, v.interlaced? 'i' : 'p',
				v.refresh_rate / 100, v.refresh_rate % 100,
				v.dvi? "DVI" : "HDMI", v.deep_color_mode);
	}
	error |= hdmi_rx_ctrl_get_audio(ctx, &a);
	if (error == 0) {
		ctx->log_info("  Audio: CT=%u CC=%u SF=%u SS=%u CA=%u",
				a.coding_type, a.channel_count, a.sample_frequency,
				a.sample_size, a.channel_allocation);
	} else {
		ctx->log_info("  Audio");
	}
	ctx->log_info("  - N parameter:     %u", io_read(ctx, RA_PDEC_ACR_N, N_DECODED));
	ctx->log_info("  - CTS parameter:   %u", io_read(ctx, RA_PDEC_ACR_CTS, CTS_DECODED));
	ctx->log_info("  Audio  FIFO reset: %u", ctx->debug_audio_fifo_rst);
	ctx->log_info("  Packet FIFO reset: %u", ctx->debug_packet_fifo_rst);
	ctx->log_info("  IRQ handling:      %u", ctx->debug_irq_handling);
	ctx->log_info("  - packet decoder:  %u", ctx->debug_irq_packet_decoder);
	ctx->log_info("  - audio clock:     %u", ctx->debug_irq_audio_clock);
	ctx->log_info("  - audio FIFO:      %u", ctx->debug_irq_audio_fifo);
	ctx->log_info("  - video mode:      %u", ctx->debug_irq_video_mode);
	ctx->log_info("  - HDMI:            %u", ctx->debug_irq_hdmi);
	return error;
}
コード例 #11
0
ファイル: bme_gfx.c プロジェクト: neuromancer/BOFH
int gfx_loadsprites(int num, char *name)
{
    int handle, size, c;
    int datastart;

    if (!gfx_spriteheaders)
    {
        gfx_setmaxspritefiles(DEFAULT_MAX_SPRFILES);
    }

    bme_error = BME_OPEN_ERROR;
    if (num >= gfx_maxspritefiles) return BME_ERROR;

    gfx_freesprites(num);

    handle = io_open(name);
    if (handle == -1) return BME_ERROR;

    size = io_lseek(handle, 0, SEEK_END);
    io_lseek(handle, 0, SEEK_SET);

    gfx_spriteamount[num] = io_readle32(handle);

    gfx_spriteheaders[num] = malloc(gfx_spriteamount[num] * sizeof(SPRITEHEADER));

    if (!gfx_spriteheaders[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }

    for (c = 0; c < gfx_spriteamount[num]; c++)
    {
        SPRITEHEADER *hptr = gfx_spriteheaders[num] + c;

        hptr->xsize = io_readle16(handle);
        hptr->ysize = io_readle16(handle);
        hptr->xhot = io_readle16(handle);
        hptr->yhot = io_readle16(handle);
        hptr->offset = io_readle32(handle);
    }

    datastart = io_lseek(handle, 0, SEEK_CUR);
    gfx_spritedata[num] = malloc(size - datastart);
    if (!gfx_spritedata[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }
    io_read(handle, gfx_spritedata[num], size - datastart);
    io_close(handle);
    bme_error = BME_OK;
    return BME_OK;
}
コード例 #12
0
ファイル: io.c プロジェクト: vaughan0/vlib
size_t io_copyn(Input* from, Output* to, size_t n) {
  char cbuf[4096];
  size_t copied = 0;
  while (copied < n) {
    size_t r = io_read(from, cbuf, MIN(sizeof(cbuf), n-copied));
    io_write(to, cbuf, r);
    copied += r;
  }
  return copied;
}
コード例 #13
0
ファイル: cmd.c プロジェクト: radare/ired
static int cmd_resize(char *arg) {
	ut8 *buf;
	ut64 tail, n;
	int i, len, ret = 0;
	switch(*arg) {
	case '\0':
		printf("%"LLF"d\n", (ut64)io_seek(0, SEEK_END));
		break;
	case '+': // XXX: needs cleanup
		n = str2ut64(arg+1);
		len = (ut64)io_seek(0, SEEK_END);
		tail = len-curseek;
		if((buf=malloc(tail))) { // XXX: Use block
			io_seek(curseek, SEEK_SET);
			io_read(buf, tail);
			io_seek(curseek+n, SEEK_SET);
			io_write(buf, tail);
			free (buf);
		} else perror("malloc");
		break;
	case '-':
		buf = malloc(bsize);
		if(buf) {
			n = str2ut64(arg+1);
			for(i=0;!ret;i+=len) {
				io_seek(curseek+n+i, SEEK_SET);
				if((len = io_read(buf, bsize))>0) {
					io_seek(curseek+i, SEEK_SET);
					if(io_write(buf, len)<len)
						perror("io_write"),ret=-1;
				} else break; //perror("io_read"), ret=-1;
			}
			free(buf);
			if((ret = io_seek(0, SEEK_END))>n)
				ret = io_truncate(ret-n);
		} else perror("malloc");
		break;
	default:
		ret = io_truncate(str2ut64(arg));
	}
	if(ret<0) perror("truncate");
	return 1;
}
コード例 #14
0
ファイル: keystore.cpp プロジェクト: CytraL/MineTee
void CKeyStore::Load()
{
	IOHANDLE File = m_pStorage->OpenFile(m_aFileStore, IOFLAG_READ, IStorage::TYPE_SAVE);
	if (!File)
		return;

	int32_t Count = 0;
	bool hasErrors = false;
	io_read(File, &Count, sizeof(int32_t));
	for (int i=0; i<Count; i++)
	{
		CKey NewKey;
		hasErrors = (io_read(File, &NewKey, sizeof(CKey)) == 0);
		if (hasErrors) break;
		m_lKeys.push_back(NewKey);
	}

	io_close(File);
}
コード例 #15
0
ファイル: versionsrv.cpp プロジェクト: Enyltyn/AllTheHaxx
void ReadNews()
{
	IOHANDLE newsFile = io_open("news", IOFLAG_READ);
	if (!newsFile)
		return;

	io_read(newsFile, m_aNews, NEWS_SIZE);

	io_close(newsFile);
}
コード例 #16
0
ファイル: io.c プロジェクト: lubing521/HDSegmenter
int main(int argc, char **argv)
{
    int fd = io_open("abc");
    uint8_t buffer[1024];
    int c = io_read(fd, buffer, 1024);
  // printf("%s \n", buffer);
    printf("%d\n", c);
    io_close(fd);
    
}
コード例 #17
0
ファイル: run-02-read.c プロジェクト: HSchroeder/ccan
static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
{
#ifdef DEBUG_CONN
	io_set_debug(conn, true);
#endif
	ok1(d->state == 0);
	d->state++;

	io_set_finish(conn, finish_ok, d);
	return io_read(conn, d->buf, sizeof(d->buf), io_close_cb, d);
}
コード例 #18
0
ファイル: hal_uart_start.c プロジェクト: wosayttn/aos
int32_t hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size,
                         uint32_t *recv_size, uint32_t timeout)
{
    if (uart->port == 0 && uart->priv == 0) {
        uart->port = STDIO_UART;
        uart->priv = &USART_2;
    }
    *recv_size = io_read(&((struct usart_os_descriptor *)uart->priv)->io, (uint8_t *)data, expect_size, timeout); 

    return (*recv_size == 0) ? -1 : 0;
}
コード例 #19
0
ファイル: accountsystem.cpp プロジェクト: CytraL/MineTee
void CAccountSystem::Load()
{
	IOHANDLE File = m_pStorage->OpenFile(m_aFileAccounts, IOFLAG_READ, IStorage::TYPE_SAVE);
	if (!File)
		return;

	m_lAccounts.clear();
	int32_t Count = 0;
	bool hasErrors = false;
	io_read(File, &Count, sizeof(int32_t));
	for (int i=0; i<Count; i++)
	{
		ACCOUNT_INFO NewAccount;
		hasErrors = (io_read(File, &NewAccount, sizeof(ACCOUNT_INFO)) == 0);
		if (hasErrors) break;
		m_lAccounts.push_back(NewAccount);
	}

	io_close(File);
}
コード例 #20
0
ファイル: io_src_tmr.c プロジェクト: Parrot-Developers/fusion
/**
 * Read a value from a timer which has expired
 * @param tmr Time to read the value of
 * @param val In output, value read. Can't be NULL, or you will suffer great
 * pain
 * @return errno compatible negative value on error, 0 on success
 */
static int tmr_read(struct io_src_tmr *tmr, uint64_t *val)
{
	ssize_t sret;
	int ret = 0;

	sret = io_read(tmr->src.fd, val, sizeof(*val));
	if (sret != sizeof(*val))
		ret = -errno;

	return ret;
}
コード例 #21
0
ファイル: dd.c プロジェクト: LuigiBlood/64dd
int detectdisk(void)
{
    uint32_t test = io_read(ASIC_STATUS);	//read status

    test &= LEO_STAT_DISK;		//mask disk status

    if (test == LEO_STAT_DISK)
	return 1;	//disk found
    else
	return 0;	//disk not found
}
コード例 #22
0
ファイル: io.c プロジェクト: vaughan0/vlib
size_t io_copy(Input* from, Output* to) {
  char cbuf[4096];
  size_t copied = 0;
  for (;;) {
    size_t r = io_read(from, cbuf, sizeof(cbuf));
    if (r == 0) break;
    io_write(to, cbuf, r);
    copied += r;
  }
  return copied;
}
コード例 #23
0
ファイル: main.c プロジェクト: kringle/sannsys15
void checkChannel ( int channel ) {

	while(1){
		while(io_read(channel))  // wait
		{}
	
		io_write(channel,LOW);
		usleep(5);
		io_write(channel,HIGH);
	}
}
コード例 #24
0
ファイル: run-15-timeout.c プロジェクト: Honglongwu/ccan
static void init_conn(int fd, struct data *d)
{
	struct io_conn *conn;

	ok1(d->state == 0);
	d->state++;

	conn = io_new_conn(fd, io_read(d->buf, sizeof(d->buf), no_timeout, d));
	io_set_finish(conn, finish_ok, d);
	io_timeout(conn, time_from_usec(d->timeout_usec), timeout, d);
}
コード例 #25
0
ファイル: io_fip.c プロジェクト: Michael-bochi/training
/* Read data from a file in package */
static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
			  size_t *length_read)
{
	int result;
	file_state_t *fp;
	size_t file_offset;
	size_t bytes_read;
	uintptr_t backend_handle;

	assert(entity != NULL);
	assert(buffer != (uintptr_t)NULL);
	assert(length_read != NULL);
	assert(entity->info != (uintptr_t)NULL);

	/* Open the backend, attempt to access the blob image */
	result = io_open(backend_dev_handle, backend_image_spec,
			 &backend_handle);
	if (result != 0) {
		WARN("Failed to open FIP (%i)\n", result);
		result = -ENOENT;
		goto fip_file_read_exit;
	}

	fp = (file_state_t *)entity->info;

	/* Seek to the position in the FIP where the payload lives */
	file_offset = fp->entry.offset_address + fp->file_pos;
	result = io_seek(backend_handle, IO_SEEK_SET, file_offset);
	if (result != 0) {
		WARN("fip_file_read: failed to seek\n");
		result = -ENOENT;
		goto fip_file_read_close;
	}

	result = io_read(backend_handle, buffer, length, &bytes_read);
	if (result != 0) {
		/* We cannot read our data. Fail. */
		WARN("Failed to read payload (%i)\n", result);
		result = -ENOENT;
		goto fip_file_read_close;
	} else {
		/* Set caller length and new file position. */
		*length_read = bytes_read;
		fp->file_pos += bytes_read;
	}

/* Close the backend. */
 fip_file_read_close:
	io_close(backend_handle);

 fip_file_read_exit:
	return result;
}
コード例 #26
0
ファイル: main.c プロジェクト: martinjensen91/ttk4147
void* test(void* num_param) {
	int num = (long) num_param;
	set_cpu(CPU_CORE);
	io_write(num, 1);
	while(1) {
		while (io_read(num));

		io_write(num, 0);
		usleep(5);
		io_write(num, 1);
	}
}
コード例 #27
0
static int load_gpt_entry(uintptr_t image_handle, gpt_entry_t *entry)
{
	size_t bytes_read;
	int result;

	assert(entry != NULL);
	result = io_read(image_handle, (uintptr_t)entry, sizeof(gpt_entry_t),
			 &bytes_read);
	if (sizeof(gpt_entry_t) != bytes_read)
		return -EINVAL;
	return result;
}
コード例 #28
0
ファイル: tuner.c プロジェクト: eframp/p600fw
static NOINLINE void ffDoTimeout(void)
{
	++ff_timeoutCount;
#ifdef DEBUG
	print("bad flip flop status : ");
	phex(ff_step);
	phex(io_read(0x9));
	print(" timeout count : ");
	phex(ff_timeoutCount);
	print("\n");
#endif	
}
コード例 #29
0
ファイル: dd.c プロジェクト: LuigiBlood/64dd
int detect64dd_ipl(void)
{
    //Look at 0x9FF00 from the IPL.
    uint32_t test = io_read(IPL_CHECK);

    //Isolate the highest byte
    test &= 0xFF000000;

    if (test == 0xC3000000)
	return 1;	//if yes, then retail 64DD is present (JPN)
    else if (test == 0x04000000)
	return 2;	//it has found a potential US 64DD.
    else
    {
	test = io_read(ASIC_ID_REG);
	if (test == 0x00040000)
	    return 3;
	else
	    return 0;	//if not, then there are no 64DD connected.
    }
}
コード例 #30
0
ファイル: localization.cpp プロジェクト: egon13/teeworlds
bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, IConsole *pConsole)
{
    // empty string means unload
    if(pFilename[0] == 0)
    {
        m_Strings.clear();
        m_CurrentVersion = 0;
        return true;
    }

    // read file data into buffer
    IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
    if(!File)
        return false;
    int FileSize = (int)io_length(File);
    char *pFileData = (char *)mem_alloc(FileSize+1, 1);
    io_read(File, pFileData, FileSize);
    pFileData[FileSize] = 0;
    io_close(File);

    // init
    char aBuf[64];
    str_format(aBuf, sizeof(aBuf), "loaded '%s'", pFilename);
    pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
    m_Strings.clear();

    // parse json data
    json_settings JsonSettings;
    mem_zero(&JsonSettings, sizeof(JsonSettings));
    char aError[256];
    json_value *pJsonData = json_parse_ex(&JsonSettings, pFileData, aError);
    if(pJsonData == 0)
    {
        pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, pFilename, aError);
        mem_free(pFileData);
        return false;
    }

    // extract data
    const json_value &rStart = (*pJsonData)["translated strings"];
    if(rStart.type == json_array)
    {
        for(unsigned i = 0; i < rStart.u.array.length; ++i)
            AddString((const char *)rStart[i]["or"], (const char *)rStart[i]["tr"]);
    }

    // clean up
    json_value_free(pJsonData);
    mem_free(pFileData);
    m_CurrentVersion = ++m_VersionCounter;
    return true;
}