Example #1
0
char *
cf_parse_u64(const char *str, u64 *ptr)
{
  char *msg = NULL;
  if (!*str)
    msg = "Missing number";
  else {
    const struct unit *u;
    char *end;
    errno = 0;
    u64 x = strtoull(str, &end, 0);
    if (errno == ERANGE)
      msg = cf_rngerr;
    else if (u = lookup_unit(str, end, &msg)) {
      if (x > ~(u64)0 / u->num)
	msg = "Number out of range";
      else {
	x *= u->num;
	if (x % u->den)
	  msg = "Number is not an integer";
	else
	  *ptr = x / u->den;
      }
    } else
      *ptr = x;
  }
  return msg;
}
Example #2
0
char *
cf_parse_int(const char *str, int *ptr)
{
  char *msg = NULL;
  if (!*str)
    msg = "Missing number";
  else {
    const struct unit *u;
    char *end;
    errno = 0;
    uns x = strtoul(str, &end, 0);
    if (errno == ERANGE)
      msg = cf_rngerr;
    else if (u = lookup_unit(str, end, &msg)) {
      u64 y = (u64)x * u->num;
      if (y % u->den)
	msg = "Number is not an integer";
      else {
	y /= u->den;
	if (y > 0xffffffff)
	  msg = cf_rngerr;
	*ptr = y;
      }
    } else
      *ptr = x;
  }
  return msg;
}
Example #3
0
struct scsi_unit *
scsi_register_unit( scsi_unit_pb_t *pb, int scsi_id, void *usr_data )
{
	scsi_unit_t *unit;
	
	if( lookup_unit(scsi_id) )
		return NULL;

	unit = calloc( sizeof( scsi_unit_t),1 );
	unit->next = bus->units;
	bus->units = unit;

	unit->scsi_id = scsi_id;
	unit->pb = *pb;

	/* DEFAULT values */
	if( !unit->pb.block_size )
		unit->pb.block_size = DEFAULT_BLOCK_SIZE;

	if( !unit->pb.handle_mes_proc )
		unit->pb.handle_mes_proc = default_mes_handler;
	if( !unit->pb.next_sphase_proc )
		unit->pb.next_sphase_proc = default_next_sphase;

	unit->usr_data = usr_data;

	return unit;
}
Example #4
0
char *
cf_parse_double(const char *str, double *ptr)
{
  char *msg = NULL;
  if (!*str)
    msg = "Missing number";
  else {
    const struct unit *u;
    double x;
    uns read_chars;
    if (sscanf(str, "%lf%n", &x, &read_chars) != 1)
      msg = "Invalid number";
    else if (u = lookup_unit(str, str + read_chars, &msg))
      *ptr = x * u->num / u->den;
    else
      *ptr = x;
  }
  return msg;
}