示例#1
0
FLOAT
STRTOD_NAN (const STRING_TYPE *str, STRING_TYPE **endptr, STRING_TYPE endc)
{
  const STRING_TYPE *cp = str;

  while ((*cp >= L_('0') && *cp <= L_('9'))
	 || (*cp >= L_('A') && *cp <= L_('Z'))
	 || (*cp >= L_('a') && *cp <= L_('z'))
	 || *cp == L_('_'))
    ++cp;

  FLOAT retval = NAN;
  if (*cp != endc)
    goto out;

  /* This is a system-dependent way to specify the bitmask used for
     the NaN.  We expect it to be a number which is put in the
     mantissa of the number.  */
  STRING_TYPE *endp;
  unsigned long long int mant;

  mant = STRTOULL (str, &endp, 0);
  if (endp == cp)
    SET_NAN_PAYLOAD (retval, mant);

 out:
  if (endptr != NULL)
    *endptr = (STRING_TYPE *) cp;
  return retval;
}
示例#2
0
size_t NaClReadHexTextWithPc(FILE* file, NaClPcAddress* pc,
                             uint8_t* mbase, size_t mbase_size) {
  char input_line[NACL_MAX_INPUT_LINE];
  *pc = 0;  /* Default if no input. */
  while (1) {
    if (fgets(input_line, NACL_MAX_INPUT_LINE, file) == NULL) return 0;
    if (input_line[0] == '#') {
      /* i.e. treat line as a comment. */
      continue;
    } else if (input_line[0] == '@') {
      *pc = (NaClPcAddress) STRTOULL(&input_line[1], NULL, 16);
    } else {
      return NaClReadHexData(file, mbase, mbase_size, input_line);
    }
  }
  /* NOT REACHED */
  return 0;
}
示例#3
0
static errcode_t parse_uint(struct field_set_info *info, char *arg)
{
	unsigned long long num, limit;
	char *tmp;
	union {
		__u64	*ptr64;
		__u32	*ptr32;
		__u16	*ptr16;
		__u8	*ptr8;
	} u;

	u.ptr8 = (__u8 *) info->ptr;
	if (info->flags & FLAG_ARRAY)
		u.ptr8 += array_idx * info->size;

	errno = 0;
	num = STRTOULL(arg, &tmp, 0);
	if (*tmp || errno) {
		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
			arg, info->name);
		return EINVAL;
	}
	limit = ~0ULL >> ((8 - info->size) * 8);
	if (num > limit) {
		fprintf(stderr, "Value '%s' exceeds field %s maximum %llu.\n",
			arg, info->name, limit);
		return EINVAL;
	}
	switch (info->size) {
	case 8:
		*u.ptr64 = num;
		break;
	case 4:
		*u.ptr32 = num;
		break;
	case 2:
		*u.ptr16 = num;
		break;
	case 1:
		*u.ptr8 = num;
		break;
	}
	return 0;
}
示例#4
0
/*
 * Note: info->size == 6 is special; this means a base size 4 bytes,
 * and secondiory (high) size of 2 bytes.  This is needed for the
 * special case of i_blocks_high and i_file_acl_high.
 */
static errcode_t parse_uint(struct field_set_info *info, char *field,
			    char *arg)
{
	unsigned long long n, num, mask, limit;
	int suffix = check_suffix(field);
	char *tmp;
	void *field1 = info->ptr, *field2 = info->ptr2;
	int size = (info->size == 6) ? 4 : info->size;
	union {
		__u64	*ptr64;
		__u32	*ptr32;
		__u16	*ptr16;
		__u8	*ptr8;
	} u;

	if (suffix == 1)
		field2 = 0;
	if (suffix == 2) {
		field1 = field2;
		field2 = 0;
	}

	u.ptr8 = (__u8 *) field1;
	if (info->flags & FLAG_ARRAY)
		u.ptr8 += array_idx * info->size;

	errno = 0;
	num = STRTOULL(arg, &tmp, 0);
	if (*tmp || errno) {
		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
			arg, info->name);
		return EINVAL;
	}
	mask = ~0ULL >> ((8 - size) * 8);
	limit = ~0ULL >> ((8 - info->size) * 8);
	if (field2 && info->size != 6)
		limit = ~0ULL >> ((8 - info->size*2) * 8);

	if (num > limit) {
		fprintf(stderr, "Value '%s' exceeds field %s maximum %llu.\n",
			arg, info->name, limit);
		return EINVAL;
	}
	n = num & mask;
	switch (size) {
	case 8:
		*u.ptr64 = n;
		break;
	case 4:
		*u.ptr32 = n;
		break;
	case 2:
		*u.ptr16 = n;
		break;
	case 1:
		*u.ptr8 = n;
		break;
	}
	if (!field2)
		return 0;
	n = num >> (size*8);
	u.ptr8 = (__u8 *) field2;
	if (info->size == 6)
		size = 2;
	switch (size) {
	case 8:
		*u.ptr64 = n;
		break;
	case 4:
		*u.ptr32 = n;
		break;
	case 2:
		*u.ptr16 = n;
		break;
	case 1:
		*u.ptr8 = n;
		break;
	}
	return 0;
}