예제 #1
0
unsigned long
midifile::parse_prop_header (int file_size)
{
    unsigned long result = 0;
    if ((file_size - m_pos) > (int) sizeof(unsigned long))
    {
        result = read_long();                   /* status (new), or tag     */
        unsigned char status = (result & 0xFF000000) >> 24;
        if (status == 0xFF)
        {
            m_pos -= 3;                         /* back up to retrench      */
            unsigned char type = read_byte();   /* get meta type            */
            if (type == 0x7F)
            {
                (void) read_varinum();          /* prop section length      */
                result = read_long();           /* control tag              */
            }
            else
            {
                fprintf
                (
                    stderr,
                    "Bad status '%x' in proprietary section near offset %x",
                    int(type), m_pos
                );
            }
        }
    }
예제 #2
0
파일: dbpack.c 프로젝트: braddr/cold
static cDict *unpack_dict(cBuf *buf, Long *buf_pos)
{
    cDict *dict;
    cList *keys, *values;
    Int i;

    keys = unpack_list(buf, buf_pos);
    values = unpack_list(buf, buf_pos);
    if (keys->len <= 64) {
        dict = dict_new(keys, values);
        list_discard(keys);
        list_discard(values);
        return dict;
    } else {
        dict = EMALLOC(cDict, 1);
        dict->keys = keys;
        dict->values = values;
        dict->hashtab_size = read_long(buf, buf_pos);
        dict->links = EMALLOC(Int, dict->hashtab_size);
        dict->hashtab = EMALLOC(Int, dict->hashtab_size);
        for (i = 0; i < dict->hashtab_size; i++) {
            dict->links[i] = read_long(buf, buf_pos);
            dict->hashtab[i] = read_long(buf, buf_pos);
        }
        dict->refs = 1;
        return dict;
    }
}
예제 #3
0
파일: dbpack.c 프로젝트: braddr/cold
static void unpack_methods(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i, size;

    size = read_long(buf, buf_pos);

    if (size == -1) {
        obj->methods = NULL;
        return;
    }

    obj->methods = EMALLOC(ObjMethods, 1);

    obj->methods->size = size;
    obj->methods->blanks = read_long(buf, buf_pos);

    obj->methods->hashtab = EMALLOC(Int, obj->methods->size);
    obj->methods->tab = EMALLOC(struct mptr, obj->methods->size);

    for (i = 0; i < obj->methods->size; i++) {
	obj->methods->hashtab[i] = read_long(buf, buf_pos);
	obj->methods->tab[i].m = unpack_method(buf, buf_pos);
	if (obj->methods->tab[i].m)
	    obj->methods->tab[i].m->object = obj;
	obj->methods->tab[i].next = read_long(buf, buf_pos);
    }

    unpack_strings(buf, buf_pos, obj);
    unpack_idents(buf, buf_pos, obj);
}
예제 #4
0
파일: lw.c 프로젝트: DX-MON/gtkGLExt2
lwObject *lw_object_read(const char *lw_file)
{
  FILE *f = NULL;
  lwObject *lw_object = NULL;

  gint32 form_bytes = 0;
  gint32 read_bytes = 0;

  /* open file */
  f = fopen(lw_file, "rb");
  if (f == NULL) {
    g_warning("can't open file %s", lw_file);
    return NULL;
  }

  /* check for headers */
  if (read_long(f) != ID_FORM) {
    g_warning("file %s is not an IFF file", lw_file);
    fclose(f);
    return NULL;
  }
  form_bytes = read_long(f);
  read_bytes += 4;

  if (read_long(f) != ID_LWOB) {
    g_warning("file %s is not a LWOB file", lw_file);
    fclose(f);
    return NULL;
  }

  /* create new lwObject */
  lw_object = g_malloc0(sizeof(lwObject));

  /* read chunks */
  while (read_bytes < form_bytes) {
    gint32  id     = read_long(f);
    gint32  nbytes = read_long(f);
    read_bytes += 8 + nbytes + (nbytes%2);

    switch (id) {
    case ID_PNTS:
      read_pnts(f, nbytes, lw_object);
      break;
    case ID_POLS:
      read_pols(f, nbytes, lw_object);
      break;
    case ID_SRFS:
      read_srfs(f, nbytes, lw_object);
      break;
    case ID_SURF:
      read_surf(f, nbytes, lw_object);
      break;
    default:
      fseek(f, nbytes + (nbytes%2), SEEK_CUR);
    }
  }

  fclose(f);
  return lw_object;
}
예제 #5
0
파일: serial.c 프로젝트: 309972460/software
/* perform_restoreundo():
   Pull a state pointer from the undo chain. This returns 0 on success,
   1 on failure. Note that if it succeeds, the frameptr, localsbase,
   and valstackbase registers are invalid; they must be rebuilt from
   the stack.
*/
glui32 perform_restoreundo()
{
  dest_t dest;
  glui32 res, val;
  glui32 heapsumlen = 0;
  glui32 *heapsumarr = NULL;

  if (undo_chain_size == 0 || undo_chain_num == 0)
    return 1;

  dest.ismem = TRUE;
  dest.size = 0;
  dest.pos = 0;
  dest.ptr = undo_chain[0];
  dest.str = NULL;

  res = 0;
  if (res == 0) {
    res = read_long(&dest, &val);
  }
  if (res == 0) {
    res = read_memstate(&dest, val);
  }
  if (res == 0) {
    res = read_long(&dest, &val);
  }
  if (res == 0) {
    res = read_heapstate(&dest, val, FALSE, &heapsumlen, &heapsumarr);
  }
  if (res == 0) {
    res = read_long(&dest, &val);
  }
  if (res == 0) {
    res = read_stackstate(&dest, val, FALSE);
  }
  /* ### really, many of the failure modes of those calls ought to
     cause fatal errors. The stack or main memory may be damaged now. */

  if (res == 0) {
    if (heapsumarr)
      res = heap_apply_summary(heapsumlen, heapsumarr);
  }

  if (res == 0) {
    /* It worked. */
    if (undo_chain_size > 1)
      memmove(undo_chain, undo_chain+1,
        (undo_chain_size-1) * sizeof(unsigned char *));
    undo_chain_num -= 1;
    glulx_free(dest.ptr);
    dest.ptr = NULL;
  }
  else {
    /* It didn't work. */
    dest.ptr = NULL;
  }

  return res;
}
예제 #6
0
파일: lw.cpp 프로젝트: gitrider/wxsj2
lwObject *lw_object_read(const char *lw_file)
{

  /* open file */
  FILE *f = fopen(lw_file, "rb");
  if (f == NULL) {
    return NULL;
  }

  /* check for headers */
  if (read_long(f) != ID_FORM) {
    fclose(f);
    return NULL;
  }

  wxInt32 read_bytes = 0;

  wxInt32 form_bytes = read_long(f);
  read_bytes += 4;

  if (read_long(f) != ID_LWOB) {
    fclose(f);
    return NULL;
  }

  /* create new lwObject */
  lwObject *lw_object = (lwObject*) calloc(sizeof(lwObject),1);

  /* read chunks */
  while (read_bytes < form_bytes) {
    wxInt32  id     = read_long(f);
    wxInt32  nbytes = read_long(f);
    read_bytes += 8 + nbytes + (nbytes%2);

    switch (id) {
    case ID_PNTS:
      read_pnts(f, nbytes, lw_object);
      break;
    case ID_POLS:
      read_pols(f, nbytes, lw_object);
      break;
    case ID_SRFS:
      read_srfs(f, nbytes, lw_object);
      break;
    case ID_SURF:
      read_surf(f, nbytes, lw_object);
      break;
    default:
      fseek(f, nbytes + (nbytes%2), SEEK_CUR);
    }
  }

  fclose(f);
  return lw_object;
}
예제 #7
0
파일: dbpack.c 프로젝트: braddr/cold
static void unpack_idents(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->methods->idents_size = read_long(buf, buf_pos);
    obj->methods->num_idents = read_long(buf, buf_pos);
    obj->methods->idents = EMALLOC(Ident_entry, obj->methods->idents_size);
    for (i = 0; i < obj->methods->num_idents; i++) {
	obj->methods->idents[i].id = read_ident(buf, buf_pos);
	if (obj->methods->idents[i].id != NOT_AN_IDENT)
	    obj->methods->idents[i].refs = read_long(buf, buf_pos);
    }
}
예제 #8
0
gint lw_is_lwobject(const char *lw_file)
{
  FILE *f = osgDB::fopen(lw_file, "rb");
  if (f) {
    gint32 form = read_long(f);
    gint32 nlen = read_long(f);
    gint32 lwob = read_long(f);
    fclose(f);
    if (form == ID_FORM && nlen != 0 && lwob == ID_LWOB)
      return TRUE;
  }
  return FALSE;
}
예제 #9
0
파일: lw.cpp 프로젝트: gitrider/wxsj2
bool lw_is_lwobject(const char *lw_file)
{
  FILE *f = fopen(lw_file, "rb");
  if (f) {
    wxInt32 form = read_long(f);
    wxInt32 nlen = read_long(f);
    wxInt32 lwob = read_long(f);
    fclose(f);
    if (form == ID_FORM && nlen != 0 && lwob == ID_LWOB)
      return true;
  }
  return false;
}
예제 #10
0
파일: spy.c 프로젝트: Flight310/vlm
void	SendMBINBuffers (EmbMBINChannel* mbinChannel)
{
  register EmbQueue *gthQ = mbinChannel->guestToHostQueue;
  register EmbQueue *gthrQ = mbinChannel->guestToHostReturnQueue;
  EmbPtr bufferPtr;
  struct rm_aligned_pkt *buffer;
  struct rm_pkt pkt;
  unsigned int nBytes, id;
  int historyID;

  if (mbinChannel->header.messageChannel->guestToHostImpulse)
    switch (mbinChannel->header.messageChannel->guestToHostImpulse)
    {
      case EmbMBINImpulseShutdown:
        activeMBINChannel = NULL;
	ResetIncomingQueue (gthQ);
	ResetOutgoingQueue (gthrQ);
	ResetIncomingQueue (mbinChannel->hostToGuestSupplyQueue);
	ResetOutgoingQueue (mbinChannel->hostToGuestQueue);
	mbinChannel->header.messageChannel->guestToHostImpulse = EmbMessageImpulseNone;
	UnthreadMessageChannel (mbinChannel->header.messageChannel);
	free (mbinChannel);
	return;
      default:
	mbinChannel->header.messageChannel->guestToHostImpulse = EmbMessageImpulseNone;
        break;
    }

  while (EmbQueueFilled (gthQ)) {
    if (0 == EmbQueueSpace (gthrQ)) {
      SignalLater (gthQ->signal);
      return;
    }
    bufferPtr = EmbQueueTakeWord (gthQ);
    if (bufferPtr && (bufferPtr != NullEmbPtr) && mbin_sinValid) {
      buffer = (struct rm_aligned_pkt*) HostPointer (bufferPtr);
      nBytes = read_long(&buffer->rm_operand[0]) & 0xFFFFFF;
      memcpy (&pkt.rm_id[0], &buffer->rm_id[0], REMOTE_MEMORY_ALIGNED_PACKET_HEADER);
      memcpy (&pkt.data[0], &buffer->data[0], nBytes);
      if (rm_ack == buffer->rm_opcode) {
	id = read_long(&buffer->rm_id[0]);
	historyID = id & 0xF;
	MBINHistory[historyID].id = id;
	MBINHistory[historyID].acked = TRUE;
      }
      spy_transmit(&pkt, REMOTE_MEMORY_PACKET_HEADER + nBytes, &mbin_sin);
    }
    EmbQueuePutWord (gthrQ, bufferPtr);
  }
}
예제 #11
0
파일: dbpack.c 프로젝트: braddr/cold
Ident read_ident(cBuf *buf, Long *buf_pos)
{
    Int   len;
    Char *s;
    Ident id;

    /* Read the length of the identifier. */
    len = read_long(buf, buf_pos);

    /* If the length is -1, it's not really an identifier, but a -1 signalling
     * a blank variable or method. */
    if (len == NOT_AN_IDENT)
	return NOT_AN_IDENT;

    /* Otherwise, it's an identifier.  Read it into temporary storage. */
    s = TMALLOC(Char, len + 1);
    MEMCPY(s, &(buf->s[*buf_pos]), len);
    (*buf_pos) += len;
    s[len] = 0;

    /* Get the index for the identifier and free the temporary memory. */
    id = ident_get(s);
    tfree_chars(s);

    return id;
}
예제 #12
0
파일: lw.cpp 프로젝트: gitrider/wxsj2
static void read_surf(FILE *f, int nbytes, lwObject *lwo)
{
  int i;
  char name[LW_MAX_NAME_LEN];
  lwMaterial *material = NULL;

  /* read surface name */
  nbytes -= read_string(f,name);

  /* find material */
  for (i=0; i< lwo->material_cnt; i++) {
    if (strcmp(lwo->material[i].name,name) == 0) {
      material = &lwo->material[i];
      break;
    }
  }

  /* read values */
  while (nbytes > 0) {
    int id = read_long(f);
    int len = read_short(f);
    nbytes -= 6 + len + (len%2);

    switch (id) {
    case ID_COLR:
      material->r = read_char(f) / 255.0;
      material->g = read_char(f) / 255.0;
      material->b = read_char(f) / 255.0;
      read_char(f); /* dummy */
      break;
    default:
      fseek(f, len+(len%2), SEEK_CUR);
    }
  }
}
예제 #13
0
int test_qtostr(testspec_t *t, FILE *ofp)
{
  mp_rat    in[2];
  long      radix;
  mp_result res, len;

  if(!parse_rat_values(t, in, NULL, NULL))
    return imath_errno = MP_BADARG, 0;

  trim_line(t->input[1]);
  if(!read_long(&radix, t->input[1]))
    return imath_errno = MP_BADARG, 0;

  if(radix < MP_MIN_RADIX || radix > MP_MAX_RADIX) {
    fprintf(stderr, "Line %d: Radix %ld out of range\n", 
	    t->line, radix);
    return imath_errno = MP_RANGE, 0;
  }

  trim_line(t->output[0]);
  len = mp_rat_string_len(in[0], radix);

  if((res = mp_rat_to_string(in[0], radix, g_output, len)) != MP_OK)
    return imath_errno = res, 0;

  if(strcmp(t->output[0], g_output) != 0)
    return imath_errno = OTHER_ERROR, 0;

  return 1;
}
예제 #14
0
int main(int argc, char **argv)
{
    printf("utf_view " VERSION "\n\n");
    CHECK_ERROR(argc != 2 && argc != 3, "Incorrect program usage\n\nusage: utf_tab file [offset]");

    long offset = 0;
    if (argc == 3)
    {
        offset = read_long(argv[2]);
    }

    /* open file */
    FILE *infile = fopen(argv[1], "rb");
    CHECK_ERRNO(!infile, "fopen");

    /* get file size */
    CHECK_ERRNO(fseek(infile, 0 , SEEK_END) != 0, "fseek");
    long file_length = ftell(infile);
    CHECK_ERRNO(file_length == -1, "ftell");

    rewind(infile);

    analyze(infile, offset, file_length);

    exit(EXIT_SUCCESS);
}
예제 #15
0
ucell load_dictionary(const char *data, ucell len)
{
	u32 checksum=0;
	const char *checksum_walk;
	ucell *walk, *reloc_table;
	dictionary_header_t *header=(dictionary_header_t *)data;

	/* assertions */
	if (len <= (sizeof(dictionary_header_t)) || strncmp(DICTID, data, 8))
		return 0;
#ifdef CONFIG_DEBUG_DICTIONARY
	dump_header(header);
#endif

	checksum_walk=data;
	while (checksum_walk<data+len) {
		checksum+=read_long(checksum_walk);
		checksum_walk+=sizeof(u32);
	}

	if(checksum) {
		printk("Checksum invalid (%08x)!\n", checksum);
		return 0;
	}

	data += sizeof(dictionary_header_t);

	dicthead = target_long(header->length);

	memcpy(dict, data, dicthead);
	reloc_table=(ucell *)(data+dicthead);

#ifdef CONFIG_DEBUG_DICTIONARY
	printk("\nmoving dictionary (%x bytes) to %x\n",
			(ucell)dicthead, (ucell)dict);
	printk("\ndynamic relocation...");
#endif

	for (walk = (ucell *) dict; walk < (ucell *) (dict + dicthead);
	     walk++) {
		int pos, bit, l;
		l=(walk-(ucell *)dict);
		pos=l/BITS;
		bit=l&~(-BITS);
                if (reloc_table[pos] & target_ucell((ucell)1ULL << bit)) {
			// printk("%lx, pos %x, bit %d\n",*walk, pos, bit);
			write_ucell(walk, read_ucell(walk)+pointer2cell(dict));
		}
	}

#ifdef CONFIG_DEBUG_DICTIONARY
	printk(" done.\n");
#endif

	last = (ucell *)(dict + target_ucell(header->last));

	return -1;
}
예제 #16
0
파일: ascii1.c 프로젝트: FuzzyHobbit/mordor
int read_object_basic(FILE *fp, int *index, object *obj)
{
	int	i;
	char	str[10];
	
/* begin of object data */
	read_int(fp, index);  /* object # */
	
	read_chars(fp, obj->name, sizeof(obj->name));
	read_chars(fp, obj->description, sizeof(obj->description));
	for (i = 0; i != 3; i++)
		read_chars(fp, obj->key[i], sizeof(obj->key[i]));
	read_chars(fp, obj->use_output, sizeof(obj->use_output));
	read_long(fp, &obj->value);
	read_short(fp, &obj->weight);
	
	read_char(fp, &obj->type);
	read_char(fp, &obj->adjustment);
	
	read_short(fp, &obj->shotsmax);
	read_short(fp, &obj->shotscur);
	read_short(fp, &obj->ndice);
	read_short(fp, &obj->sdice);
	read_short(fp, &obj->pdice);
	
	read_char(fp, &obj->armor);
	read_char(fp, &obj->wearflag);
	read_char(fp, &obj->magicpower);
	read_char(fp, &obj->magicrealm);
	read_short(fp, &obj->special);
	read_chars(fp, obj->flags, sizeof(obj->flags));
	read_char(fp, &obj->questnum);
	read_char(fp,&obj->strength);
	read_char(fp,&obj->dexterity);
	read_char(fp,&obj->constitution);
	read_char(fp,&obj->intelligence);
	read_char(fp,&obj->piety);
	for (i = 0; i != 16; i++)
		read_short(fp, &obj->sets_flag[i]);
	read_short(fp,&obj->special1);
	read_long(fp,&obj->special2);
	
/* end of object data */
	return(0);
}
예제 #17
0
파일: handled_frob.c 프로젝트: braddr/cold
void unpack_handled (cBuf *buf, Long *buf_pos, cData *d)
{
    HandledFrob *h=TMALLOC(HandledFrob, 1);

    h->cclass = read_long(buf, buf_pos);
    unpack_data (buf, buf_pos, &h->rep);
    h->handler = read_ident(buf, buf_pos);
    d->u.instance = (void*) h;
}
예제 #18
0
파일: dbpack.c 프로젝트: braddr/cold
static void unpack_strings(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;
    Long size;

    size = read_long(buf, buf_pos);
    if (size != -1) {
#if 1
        obj->methods->strings = string_tab_new_with_size(size);
        obj->methods->strings->tab_num = read_long(buf, buf_pos);
        obj->methods->strings->blanks = read_long(buf, buf_pos);
        for (i = 0; i < size; i++) {
	    obj->methods->strings->hashtab[i] = read_long(buf, buf_pos);
	    obj->methods->strings->tab[i].next = read_long(buf, buf_pos);
	    obj->methods->strings->tab[i].hash = read_long(buf, buf_pos);
	    obj->methods->strings->tab[i].refs = read_long(buf, buf_pos);
        }
        for (i = 0; i < obj->methods->strings->tab_size; i++) {
	    obj->methods->strings->tab[i].str = string_unpack(buf, buf_pos);
        }
#else
        Long last_blank = -1;

        // caused 3 crashes on TEC, disabling code until problem can be determined
        obj->methods->strings = string_tab_new_with_size(size);
        obj->methods->strings->tab_size = size;
        obj->methods->strings->blanks = 0;
        for (i = 0; i < size; i++) {
            obj->methods->strings->tab[i].str = string_unpack(buf, buf_pos);
            if (obj->methods->strings->tab[i].str) {
                obj->methods->strings->tab_num++;
	        obj->methods->strings->tab[i].hash = read_long(buf, buf_pos);
                obj->methods->strings->tab[i].refs = read_long(buf, buf_pos);
                if (obj->methods->strings->blanks == i) {
                    obj->methods->strings->blanks = i+1;
                    last_blank = i+1;
                }
            } else {
                if (last_blank != -1)
                    obj->methods->strings->tab[last_blank].next = i;
                last_blank = i;
            }
        }
        string_tab_fixup_hashtab(obj->methods->strings, obj->methods->strings->tab_size);
#endif
    } else {
        obj->methods->strings = string_tab_new();
    }
}
예제 #19
0
int test_qtodec(testspec_t *t, FILE *ofp)
{
  mp_rat in[4];
  long   radix, prec;
  mp_round_mode rmode;
  mp_result res, expect = MP_OK, len;

  if(!parse_rat_values(t, in, NULL, NULL))
    return imath_errno = MP_BADARG, 0;

  if(t->output[0][0] == '$' && !parse_result_code(t->output[0], &expect)) {
    fprintf(stderr, "Line %d: Invalid result code [%s]\n", 
	    t->line, t->output[0]);
    return 0;
  }
  
  trim_line(t->input[1]);
  trim_line(t->input[2]);
  trim_line(t->input[3]);
  if(!read_long(&radix, t->input[1]))
    return imath_errno = MP_BADARG, 0;
  if(!read_long(&prec, t->input[2]))
    return imath_errno = MP_BADARG, 0;
  if(!read_long((long *)&rmode, t->input[3]))
    return imath_errno = MP_BADARG, 0;

  if(prec < 0) {
    fprintf(stderr, "Line %d: Precision %ld out of range\n", 
	    t->line, prec);
    return imath_errno = MP_RANGE, 0;
  }
  
  trim_line(t->output[0]);
  len = mp_rat_decimal_len(in[0], radix, prec);

  if((res = mp_rat_to_decimal(in[0], radix, prec, 
                              rmode, g_output, len)) != expect)
    return imath_errno = res, 0;
  
  if(res == MP_OK && strcmp(t->output[0], g_output) != 0)
    return imath_errno = OTHER_ERROR, 0;
  
  return 1;
}
예제 #20
0
파일: main.c 프로젝트: aclark4life/CS
main()
{
	char **tokenv;
	char *s;
	int tokenc;
	int i;

	prompt();
	for ( s=read_long(); s!=NULL; s=read_long() )
	{
		tokenv=tokenize(s,&tokenc);
		if (!no_token(tokenv)) /* if there is a token */
		{
			check_for_exit(tokenv); 
			do_fork(tokenv,&tokenc);
		}
		prompt();
	}
}
예제 #21
0
파일: dbpack.c 프로젝트: braddr/cold
static void unpack_vars(cBuf *buf, Long *buf_pos, Obj *obj)
{
    Int i;

    obj->vars.size = read_long(buf, buf_pos);
    obj->vars.blanks = read_long(buf, buf_pos);

    obj->vars.hashtab = EMALLOC(Int, obj->vars.size);
    obj->vars.tab = EMALLOC(Var, obj->vars.size);

    for (i = 0; i < obj->vars.size; i++) {
	obj->vars.hashtab[i] = read_long(buf, buf_pos);
	obj->vars.tab[i].name = read_ident(buf, buf_pos);
	if (obj->vars.tab[i].name != NOT_AN_IDENT) {
	    obj->vars.tab[i].cclass = read_long(buf, buf_pos);
	    unpack_data(buf, buf_pos, &obj->vars.tab[i].val);
	}
	obj->vars.tab[i].next = read_long(buf, buf_pos);
    }

}
예제 #22
0
파일: png.c 프로젝트: dienbk7x/apex
static int next_chunk (struct png* png)
{
//  printf ("%s:%d\n", __FUNCTION__, png->ib);

  if (png->ib)
    png->ib += 8 + png->c.length + 4;
  else
    png->ib = 8;		/* Skip MAGIC */
//  printf ("%s:  %d %d\n", __FUNCTION__, png->ib, png->cb);
  if (png->ib >= png->cb)
    return -1;

  png->c.length = read_long (png->pb + png->ib);
  memcpy (&png->c.id, &png->pb[png->ib + 4], 4);
  return 0;
}
예제 #23
0
static void		read_file(t_env *env, int fd)
{
	long	tmp;
	char	*data;

	while ((tmp = read_long(env)) >= 0)
	{
		data = read_mem(env, tmp);
		tmp = write(fd, data, tmp);
		free(data);
	}
	if (tmp == -2)
		ft_putendl("ERROR: error while reading file");
	else if (tmp == -1)
		ft_putendl("SUCCESS");
}
예제 #24
0
static glui32 read_heapstate(dest_t *dest, glui32 chunklen, int portable,
  glui32 *sumlen, glui32 **summary)
{
  glui32 res, count, lx;
  glui32 *arr;

  *sumlen = 0;
  *summary = NULL;

  if (chunklen == 0)
    return 0; /* no heap */

  if (!portable) {
    count = chunklen / sizeof(glui32);

    arr = glulx_malloc(chunklen);
    if (!arr)
      return 1;

    res = read_buffer(dest, (void *)arr, chunklen);
    if (res)
      return res;

    *sumlen = count;
    *summary = arr;

    return 0;
  }

  count = chunklen / 4;

  arr = glulx_malloc(count * sizeof(glui32));
  if (!arr)
    return 1;
  
  for (lx=0; lx<count; lx++) {
    res = read_long(dest, arr+lx);
    if (res)
      return res;
  }

  *sumlen = count;
  *summary = arr;

  return 0;
}
예제 #25
0
파일: dbpack.c 프로젝트: braddr/cold
static cList *unpack_list(cBuf *buf, Long *buf_pos)
{
    Int len, i;
    cList *list;
    cData *d;

    len = read_long(buf, buf_pos);
    if (len == -1) {
        list = NULL;
    } else {
        list = list_new(len);
        d = list_empty_spaces(list, len);
        for (i = 0; i < len; i++)
            unpack_data(buf, buf_pos, d++);
    }
    return list;
}
예제 #26
0
static void		do_the_thing(t_env *env, char **splitted)
{
	char	*file;
	int		fd;

	file = get_file_name(splitted[1]);
	if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY
					, (int)read_long(env))) == -1)
	{
		write_long(env, 0);
		ft_putendl("ERROR: can't create file");
		return ;
	}
	write_long(env, 1);
	read_file(env, fd);
	close(fd);
	free(file);
}
예제 #27
0
static int       parse_binary(char *str, unsigned char *buf, int limit)
{
  int    pos = 0;
  char  *tok;

  trim_line(str);

  for(tok = strtok(str, ".");
      tok != NULL && pos < limit;
      tok = strtok(NULL, ".")) {
    long v;

    if(!read_long(&v, tok) || v > UCHAR_MAX || v < 0)
      return -1;
      
    buf[pos++] = (unsigned char)v;
  }

  return pos;
}
예제 #28
0
void			command_get(t_env *env, char **splitted)
{
	int		res;

	if (!splitted[1])
	{
		ft_putendl("ERROR: you must specify a file to get");
		return ;
	}
	write_long(env, COMMAND_GET);
	write_str(env, splitted[1]);
	if ((res = read_long(env)) == -1)
		ft_putendl("ERROR: file not found");
	else if (res == -2)
		ft_putendl("ERROR: permissions denied");
	else if (res == -3)
		ft_putendl("ERROR: unknown error");
	else
		do_the_thing(env, splitted);
}
예제 #29
0
    /**
     * @todo ЗАДОКУМЕНТИРОВАТЬ
     * @return
     */
    SimpleRedisClient::operator long () const
    {
        if(data_size < 1)
        {
            printf("SimpleRedisClient::operator long (%u) \n", data_size);
            return data_size;
        }

        if(getData() == 0)
        {
            printf("SimpleRedisClient::operator long (%u) \n", data_size);
            return -1;
        }

        int d = 0;
        int r = read_long(getData(), &d);

        printf("SimpleRedisClient::operator long (%u|res=%d) \n", data_size, r);

        return r;
    }
예제 #30
0
int main(int argc, char **argv)
{
    printf("utf_view " VERSION "\n\n");
    CHECK_ERROR(argc != 2 && argc != 3, "Incorrect program usage\n\nusage: utf_tab file [offset]");

    long offset = 0;
    if (argc == 3)
    {
        offset = read_long(argv[2]);
    }

    /* open file */
    reader_t *infile = open_reader_file(argv[1]);
    CHECK_ERRNO(!infile, "fopen");

    /* get file size */
    long file_length = reader_length(infile);

    analyze(infile, offset, file_length);

    exit(EXIT_SUCCESS);
}