Ejemplo n.º 1
0
unsigned short disrus(
    
  struct tcp_chan *chan,
  int *retval)
  
  {
  int  locret;
  int  negate;
  unsigned value;

  assert(retval != NULL);

  locret = disrsi_(chan, &negate, &value, 1, pbs_tcp_timeout);

  if (locret != DIS_SUCCESS)
    {
    value = 0;
    }
  else if (negate)
    {
    value = 0;
    locret = DIS_BADSIGN;
    }
  else if (value > USHRT_MAX)
    {
    value = USHRT_MAX;
    locret = DIS_OVERFLOW;
    }

  *retval = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?

            DIS_NOCOMMIT : locret;
  return ((unsigned short)value);
  }
Ejemplo n.º 2
0
/**
 * @brief
 *	Gets a Data-is-Strings signed integer from <stream>, converts it
 *	into a short, and returns it
 *
 * @param[in] stream - pointer to data stream
 * @param[out] retval - return value
 *
 * @return      short
 * @retval      converted value         success
 * @retval      0                       error
 *
 */
short disrss(int stream, int *retval)
{
	int		locret;
	int		negate;
	short		value;
	unsigned	uvalue;

	assert(retval != NULL);
	assert(disr_commit != NULL);

	value = 0;
	switch (locret = disrsi_(stream, &negate, &uvalue, 1, 0)) {
		case DIS_SUCCESS:
			if (negate ? -uvalue >= SHRT_MIN : uvalue <= SHRT_MAX) {
				value = negate ? -uvalue : uvalue;
				break;
			} else
				locret = DIS_OVERFLOW;
		case DIS_OVERFLOW:
			value = negate ? SHRT_MIN : SHRT_MAX;
	}
	*retval = ((*disr_commit)(stream, locret == DIS_SUCCESS) < 0) ?
		DIS_NOCOMMIT : locret;
	return (value);
}
Ejemplo n.º 3
0
/**
 * @brief
 *	-Gets a Data-is-Strings character string from <stream> and converts it
 *      into a counted string, puts the string into <value>, a pre-allocated
 *      string, <achars> long, and puts the count into *<nchars>.  The character
 *      string in <stream> consists of an unsigned integer, followed by a number
 *      of characters determined by the unsigned integer.
 *
 * @param[in] stream - socket descriptor
 * @param[out] nchars - chars count
 * @param[out] achars - long value
 * @param[out] value - string value
 *
 * @return	int
 * @retval	DIS_success/error status
 *
 */
int
disrfcs(int stream, size_t *nchars, size_t achars, char *value)
{
	int		locret;
	int		negate;
	unsigned	count = 0;

	assert(nchars != NULL);
	assert(value != NULL);
	assert(dis_gets != NULL);
	assert(disr_commit != NULL);

	locret = disrsi_(stream, &negate, &count, 1, 0);
	if (locret == DIS_SUCCESS) {
		if (negate)
			locret = DIS_BADSIGN;
		else if ((*nchars = count) > achars)
			locret = DIS_OVERFLOW;
		else if ((*dis_gets)(stream, value, *nchars) != *nchars)
			locret = DIS_PROTO;
	}
	locret = (*disr_commit)(stream, locret == DIS_SUCCESS) ?
		DIS_NOCOMMIT : locret;
	if (locret != DIS_SUCCESS)
		*nchars = 0;
	return (locret);
}
Ejemplo n.º 4
0
int
disrsi(int stream, int *retval)
{
	int		locret;
	int		negate;
	int		value;
	unsigned int	uvalue;

	assert(retval != NULL);
	assert(disr_commit != NULL);

	value = 0;
	switch (locret = disrsi_(stream, &negate, &uvalue, 1, 0)) {
		case DIS_SUCCESS:
			if (negate ? uvalue <= (unsigned)-(INT_MIN + 1) + 1 :
				uvalue <= (unsigned)INT_MAX) {
				value = negate ? -uvalue : uvalue;
				break;
			} else
				locret = DIS_OVERFLOW;
		case DIS_OVERFLOW:
			value = negate ? INT_MIN : INT_MAX;
	}
	*retval = ((*disr_commit)(stream, locret == DIS_SUCCESS) < 0) ?
		DIS_NOCOMMIT : locret;
	return (value);
}
Ejemplo n.º 5
0
char *disrst(

  struct tcp_chan *chan,
  int *retval)

  {
  int        locret;
  int        negate;
  unsigned int count;

  char *value = NULL;

  assert(retval != NULL);

  locret = disrsi_(chan, &negate, &count, 1);

  if (locret == DIS_SUCCESS)
    {
    if (negate)
      {
      locret = DIS_BADSIGN;
      }
    else
      {
      value = (char *)calloc(1, (size_t)count + 1);

      if (value == NULL)
        {
        locret = DIS_NOMALLOC;
        }
      else
        {
        if (tcp_gets(chan, value, (size_t)count) != (int)count)
          locret = DIS_PROTO;

#ifndef NDEBUG
        else if (memchr(value, 0, (size_t)count))
          locret = DIS_NULLSTR;

#endif
        else
          value[count] = '\0';
        }
      }
    locret = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?  DIS_NOCOMMIT : locret;
    }

  *retval = locret;

  if ((locret != DIS_SUCCESS) && (value != NULL))
    {
    free(value);

    value = NULL;
    }

  return(value);
  }  /* END disrst() */
Ejemplo n.º 6
0
int disrfst(

  struct tcp_chan *chan,
  size_t  achars,
  char   *value)

  {
  int  locret;
  /*int           rc;*/

  int  negate;
  unsigned count;

  assert(value != NULL);
  
  locret = disrsi_(chan, &negate, &count, 1, pbs_tcp_timeout);

  if (locret == DIS_SUCCESS)
    {
    if (negate)
      locret = DIS_BADSIGN;
    else if (count > achars)
      locret = DIS_OVERFLOW;
    else if (tcp_gets(chan, value, (size_t)count, pbs_tcp_timeout) != (int)count)
      locret = DIS_PROTO;

#ifndef NDEBUG
    else if (memchr(value, 0, (size_t)count))
      locret = DIS_NULLSTR;

#endif
    else
      value[count] = '\0';
    }

  /*
    if (locret == DIS_SUCCESS)
      rc = tcp_rcommit(chan,TRUE);
    else
      rc = tcp_rcommit(chan,FALSE);

    locret = (rc != 0) ? rc : DIS_NOCOMMIT;
  */

  locret = tcp_rcommit(chan, locret == DIS_SUCCESS) ?
           DIS_NOCOMMIT :
           locret;

  if (locret != DIS_SUCCESS)
    *value = '\0';

  return(locret);
  }  /* END disrfst() */
Ejemplo n.º 7
0
float
disrf(int stream, int *retval)
{
	int		expon;
	unsigned	uexpon;
	int		locret;
	int		negate;
	/* following were static vars, so initializing them to defaults */
	unsigned        ndigs=0; /* 3 vars now stack variables for threads */
	unsigned        nskips=0;
	double          dval=0.0;


	assert(retval != NULL);
	assert(stream >= 0);
	assert(dis_getc != NULL);
	assert(dis_gets != NULL);
	assert(disr_skip != NULL);
	assert(disr_commit != NULL);

	dval = 0.0;
	if ((locret = disrd_(stream, 1, &ndigs, &nskips, &dval, 0)) == DIS_SUCCESS) {
		locret = disrsi_(stream, &negate, &uexpon, 1, 0);
		if (locret == DIS_SUCCESS) {
			expon = negate ? nskips - uexpon : nskips + uexpon;
			if (expon + (int)ndigs > FLT_MAX_10_EXP) {
				if (expon + (int)ndigs > FLT_MAX_10_EXP + 1) {
					dval = dval < 0.0 ?
						-HUGE_VAL : HUGE_VAL;
					locret = DIS_OVERFLOW;
				} else {
					dval *= disp10d_(expon - 1);
					if (dval > FLT_MAX / 10.0) {
						dval = dval < 0.0 ?
							-HUGE_VAL : HUGE_VAL;
						locret = DIS_OVERFLOW;
					} else
						dval *= 10.0;
				}
			} else {
				if (expon < DBL_MIN_10_EXP) {
					dval *= disp10d_(expon + (int)ndigs);
					dval /= disp10d_((int)ndigs);
				} else
					dval *= disp10d_(expon);
			}
		}
	}
	if ((*disr_commit)(stream, locret == DIS_SUCCESS) < 0)
		locret = DIS_NOCOMMIT;
	*retval = locret;
	return (dval);
}
Ejemplo n.º 8
0
char *disrcs(
    
  struct tcp_chan *chan,
  size_t *nchars,
  int    *retval)
  
  {
  int  locret;
  int  negate;
  unsigned count = 0;
  char  *value = NULL;

  assert(nchars != NULL);
  assert(retval != NULL);

  locret = disrsi_(chan, &negate, &count, 1);
  locret = negate ? DIS_BADSIGN : locret;

  if (locret == DIS_SUCCESS)
    {
    value = (char *)calloc(1, (size_t)count + 1);

    if (value == NULL)
      locret = DIS_NOMALLOC;
    else
      {
      if (tcp_gets(chan, value,
                      (size_t)count) != (int)count)
        locret = DIS_PROTO;
      else
        value[count] = '\0';
      }
    }

  locret = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?

           DIS_NOCOMMIT : locret;

  if ((*retval = locret) != DIS_SUCCESS && value != NULL)
    {
    count = 0;
    free(value);
    value = NULL;
    }

  *nchars = count;

  return (value);
  }
Ejemplo n.º 9
0
dis_long_double_t
disrl(int stream, int *retval)
{
	int		expon;
	unsigned	uexpon;
	int		locret;
	int		negate;
	unsigned	ndigs;
	unsigned	nskips;
	dis_long_double_t 	ldval;

	assert(retval != NULL);
	assert(disr_commit != NULL);

	ldval = 0.0L;
	locret = disrl_(stream, &ldval, &ndigs, &nskips, LDBL_DIG, 1, 0);
	if (locret == DIS_SUCCESS) {
		locret = disrsi_(stream, &negate, &uexpon, 1, 0);
		if (locret == DIS_SUCCESS) {
			expon = negate ? nskips - uexpon : nskips + uexpon;
			if (expon + (int)ndigs > LDBL_MAX_10_EXP) {
				if (expon + (int)ndigs > LDBL_MAX_10_EXP + 1) {
					ldval = ldval < 0.0L ?
						-HUGE_VAL : HUGE_VAL;
					locret = DIS_OVERFLOW;
				} else {
					ldval *= disp10l_(expon - 1);
					if (ldval > LDBL_MAX / 10.0L) {
						ldval = ldval < 0.0L ?
							-HUGE_VAL : HUGE_VAL;
						locret = DIS_OVERFLOW;
					} else
						ldval *= 10.0L;
				}
			} else {
				if (expon < LDBL_MIN_10_EXP) {
					ldval *= disp10l_(expon + (int)ndigs);
					ldval /= disp10l_((int)ndigs);
				} else
					ldval *= disp10l_(expon);
			}
		}
	}
	if ((*disr_commit)(stream, locret == DIS_SUCCESS) < 0)
		locret = DIS_NOCOMMIT;
	*retval = locret;
	return (ldval);
}
Ejemplo n.º 10
0
int disrsi(

  struct tcp_chan *chan,
  int *retval)

  {
  int  locret;
  int  negate;
  int  value = 0;
  unsigned uvalue;

  assert(retval != NULL);

  switch (locret = disrsi_(chan, &negate, &uvalue, 1, pbs_tcp_timeout))
    {

    case DIS_SUCCESS:

      if (negate ? uvalue <= (unsigned) - (INT_MIN + 1) + 1 : uvalue <= (unsigned)INT_MAX)
        {
        value = negate ? -uvalue : uvalue;
        *retval = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?  DIS_NOCOMMIT : locret;

        break;
        }
      else
        {
        locret = DIS_OVERFLOW;
        *retval = locret;
        }

    case DIS_OVERFLOW:

      value = negate ? INT_MIN : INT_MAX;
      *retval = locret;
      break;

    default:
      *retval = locret;
      break;

    }


  return(value);
  }
Ejemplo n.º 11
0
short disrss(
    
  struct tcp_chan *chan,
  int *retval)
  
  {
  int  locret;
  int  negate;
  short  value;
  unsigned uvalue;

  assert(retval != NULL);

  value = 0;

  switch (locret = disrsi_(chan, &negate, &uvalue, 1))
    {

    case DIS_SUCCESS:

      if (negate ? (int) - uvalue >= SHRT_MIN : uvalue <= SHRT_MAX)
        {
        value = negate ? -uvalue : uvalue;
        break;
        }
      else
        locret = DIS_OVERFLOW;

    case DIS_OVERFLOW:
      value = negate ? SHRT_MIN : SHRT_MAX;
    }

  *retval = (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0) ?
            DIS_NOCOMMIT : locret;

  return (value);
  }
Ejemplo n.º 12
0
unsigned char
disruc(int stream, int *retval)
{
	int		locret;
	int		negate;
	unsigned	value;

	assert(retval != NULL);
	assert(disr_commit != NULL);

	locret = disrsi_(stream, &negate, &value, 1, 0);
	if (locret != DIS_SUCCESS) {
		value = 0;
	} else if (negate) {
		value = 0;
		locret = DIS_BADSIGN;
	} else if (value > UCHAR_MAX) {
		value = UCHAR_MAX;
		locret = DIS_OVERFLOW;
	}
	*retval = ((*disr_commit)(stream, locret == DIS_SUCCESS) < 0) ?
		DIS_NOCOMMIT : locret;
	return ((unsigned char)value);
}
Ejemplo n.º 13
0
double disrd(
    
  struct tcp_chan *chan,
  int *retval)
  
  {
  int  expon;
  unsigned uexpon;
  int  locret;
  int  negate;
  unsigned ndigs;
  unsigned nskips;
  dis_long_double_t ldval;

  assert(retval != NULL);

  ldval = 0.0L;
  locret = disrl_(chan, &ldval, &ndigs, &nskips, DBL_DIG, 1);

  if (locret == DIS_SUCCESS)
    {
    locret = disrsi_(chan, &negate, &uexpon, 1);

    if (locret == DIS_SUCCESS)
      {
      expon = negate ? nskips - uexpon : nskips + uexpon;

      if (expon + (int)ndigs > DBL_MAX_10_EXP)
        {
        if (expon + (int)ndigs > DBL_MAX_10_EXP + 1)
          {
          ldval = ldval < 0.0L ?
                  -HUGE_VAL : HUGE_VAL;
          locret = DIS_OVERFLOW;
          }
        else
          {
          ldval *= disp10l_(expon - 1);

          if (ldval > DBL_MAX / 10.0L)
            {
            ldval = ldval < 0.0L ?
                    -HUGE_VAL : HUGE_VAL;
            locret = DIS_OVERFLOW;
            }
          else
            ldval *= 10.0L;
          }
        }
      else
        {
        if (expon < LDBL_MIN_10_EXP)
          {
          ldval *= disp10l_(expon + (int)ndigs);
          ldval /= disp10l_((int)ndigs);
          }
        else
          ldval *= disp10l_(expon);
        }
      }
    }

  if (tcp_rcommit(chan, locret == DIS_SUCCESS) < 0)
    locret = DIS_NOCOMMIT;

  *retval = locret;

  return((double)ldval);
  }
Ejemplo n.º 14
0
int disrsi_(

  int       stream,
  int      *negate,
  unsigned *value,
  unsigned  count)

  {
  int  c;
  unsigned locval;
  unsigned ndigs;
  char  *cp;
  char  scratch[DIS_BUFSIZ+1];

  assert(negate != NULL);
  assert(value != NULL);
  assert(count);
  assert(stream >= 0);
  assert(dis_getc != NULL);
  assert(dis_gets != NULL);

  memset(scratch, 0, DIS_BUFSIZ+1);
  if (dis_umaxd == 0)
    disiui_();

  switch (c = (*dis_getc)(stream))
    {

    case '-':

    case '+':

      *negate = c == '-';

      if ((*dis_gets)(stream, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count >= dis_umaxd)
        {
        if (count > dis_umaxd)
          goto overflow;

        if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if (((c = *cp++) < '0') || (c > '9'))
          {
          return(DIS_NONDIGIT);
          }

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;

      return (DIS_SUCCESS);

      break;

    case '0':

      return (DIS_LEADZRO);

      break;

    case '1':

    case '2':

    case '3':

    case '4':

    case '5':

    case '6':

    case '7':

    case '8':

    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if ((*dis_gets)(stream, scratch + 1, count - 1) != (int)count - 1)
          {
          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= dis_umaxd)
          {
          if (count > dis_umaxd)
            break;

          *cp = c;

          if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }    /* END if (count > 1) */

      return(disrsi_(stream, negate, value, ndigs));

      /*NOTREACHED*/

      break;

    case - 1:

      return(DIS_EOD);

      /*NOTREACHED*/

      break;

    case -2:

      return(DIS_EOF);

      /*NOTREACHED*/

      break;

    default:

      return(DIS_NONDIGIT);

      /*NOTREACHED*/

      break;
    }

  *negate = FALSE;

overflow:

  *value = UINT_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsi_() */
Ejemplo n.º 15
0
/**
 * @brief
 *      -Gets a Data-is-Strings signed integer from <stream>, converts it into a
 *      signed char, and returns it.  The signed integer in <stream> consists
 *      of a counted string of digits, starting with a zero or a minus sign,
 *      which represents the number.  If the number doesn't lie between -9 and
 *      9, inclusive, it is preceeded by at least one count.
 *
 *
 * @return      int
 * @retval      DIS_success/error status
 *
 */
int
disrsi_(int stream, int *negate, unsigned *value, unsigned count, int recursv)
{
	int		c;
	unsigned	locval;
	unsigned	ndigs;
	char		*cp;

	assert(negate != NULL);
	assert(value != NULL);
	assert(count);
	assert(stream >= 0);
	assert(dis_getc != NULL);
	assert(dis_gets != NULL);

	if (++recursv > DIS_RECURSIVE_LIMIT)
		return (DIS_PROTO);
	/* dis_umaxd would be initialized by prior call to dis_init_tables */
	switch (c = (*dis_getc)(stream)) {
		case '-':
		case '+':
			*negate = c == '-';
			if (count > dis_umaxd)
				goto overflow;
			if ((*dis_gets)(stream, dis_buffer, count) != count)
				return (DIS_EOD);
			if (count == dis_umaxd) {
				if (memcmp(dis_buffer, dis_umax, dis_umaxd) > 0)
					goto overflow;
			}
			cp = dis_buffer;
			locval = 0;
			do {
				if ((c = *cp++) < '0' || c > '9')
					return (DIS_NONDIGIT);
				locval = 10 * locval + c - '0';
			} while (--count);
			*value = locval;
			return (DIS_SUCCESS);
		case '0':
			return (DIS_LEADZRO);
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			ndigs = c - '0';
			if (count > 1) {
				if (count > dis_umaxd)
					break;
				if ((*dis_gets)(stream, dis_buffer + 1, count - 1) !=
					count - 1)
					return (DIS_EOD);
				cp = dis_buffer;
				if (count == dis_umaxd) {
					*cp = c;
					if (memcmp(dis_buffer, dis_umax, dis_umaxd) > 0)
						break;
				}
				while (--count) {
					if ((c = *++cp) < '0' || c > '9')
						return (DIS_NONDIGIT);
					ndigs = 10 * ndigs + c - '0';
				}
			}
			return (disrsi_(stream, negate, value, ndigs, recursv));
		case -1:
			return (DIS_EOD);
		case -2:
			return (DIS_EOF);
		default:
			return (DIS_NONDIGIT);
	}
	*negate = FALSE;
overflow:
	*value = UINT_MAX;
	return (DIS_OVERFLOW);
}
Ejemplo n.º 16
0
int disrsi_(

  struct tcp_chan *chan,
  int             *negate,
  unsigned        *value,
  unsigned         count)

  {
  int       c;
  unsigned  locval;
  unsigned  ndigs;
  char     *cp = NULL;
  char      scratch[DIS_BUFSIZ];

  if (negate == NULL)
    return DIS_INVALID;
  if (value == NULL)
    return DIS_INVALID;
  if (count == 0)
    return DIS_INVALID;

  memset(scratch, 0, sizeof(scratch));

  if (dis_umaxd == 0)
    disiui_();
  
  if (count > sizeof(scratch) - 1)
    return DIS_INVALID;

  switch (c = tcp_getc(chan))
    {

    case '-':
    case '+':

      *negate = c == '-';

      if (tcp_gets(chan, scratch, count) != (int)count)
        {
        return(DIS_EOD);
        }

      if (count > dis_umaxd)
        goto overflow;
      if (count == dis_umaxd)
        {
        if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
          goto overflow;
        }

      cp = scratch;

      locval = 0;

      do
        {
        if (((c = *cp++) < '0') || (c > '9'))
          return(DIS_NONDIGIT);

        locval = 10 * locval + c - '0';
        }
      while (--count);

      *value = locval;
      return (DIS_SUCCESS);
      break;

    case '0':
      return (DIS_LEADZRO);
      break;

    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':

      ndigs = c - '0';

      if (count > 1)
        {
        if (tcp_gets(chan, scratch + 1, count - 1) != (int)count - 1)
          {
          return(DIS_EOD);
          }

        cp = scratch;

        if (count >= dis_umaxd)
          {
          if (count > dis_umaxd)
            break;

          *cp = c;

          if (memcmp(scratch, dis_umax, dis_umaxd) > 0)
            break;
          }

        while (--count)
          {
          if (((c = *++cp) < '0') || (c > '9'))
            {
            return(DIS_NONDIGIT);
            }

          ndigs = 10 * ndigs + c - '0';
          }
        }    /* END if (count > 1) */

      return(disrsi_(chan, negate, value, ndigs));
      break;

    case -1:
      return(DIS_EOD);
      break;

    case -2:
      return(DIS_EOF);
      break;

    default:

      return(DIS_NONDIGIT);
      break;
    }

  *negate = FALSE;

overflow:

  *value = UINT_MAX;

  return(DIS_OVERFLOW);
  }  /* END disrsi_() */