iio.c
// get an integer field from a data file, whose position
// and type is determined by "tok"
get an integer field from a data file, whose position
and type is determined by "tok"
get an integer field from a data file whose position and type is determined by " tok "
static int raw_gfp(void *dat, int siz, char *tok, int endianness)
{
	int fpos, fsiz = -4;
	if (2 == sscanf(tok, "%d/%d", &fpos, &fsiz));
	else if (1 == sscanf(tok, "%d", &fpos));
	else return 0;
	IIO_DEBUG("raw gfp tok=%s fpos=%d fiz=%d\n", tok, fpos, fsiz);
	void *pvalue = fpos + (char*)dat;
	if (fpos < 0 || abs(fsiz) + fpos > siz)
		fail("can not read field beyond data size");
	if (endianness && abs(fsiz)==2) switch_2endianness(pvalue, 1);
	if (endianness && abs(fsiz)==4) switch_4endianness(pvalue, 1);
	switch(fsiz) {
	case  1: return *( uint8_t*)pvalue;
	case  2: return *(uint16_t*)pvalue;
	case  4: return *(uint32_t*)pvalue;
	case -1: return *(  int8_t*)pvalue;
	case -2: return *( int16_t*)pvalue;
	case -4: return *( int32_t*)pvalue;
	default: fail("unrecognized field size %d", fsiz);
	}
}
static int raw_gfp ( void * dat , int siz , char * tok , int endianness ) { int fpos , fsiz = -4 ; if ( 2 == sscanf ( tok , " " , & fpos , & fsiz ) ) ; else if ( 1 == sscanf ( tok , " " , & fpos ) ) ; else return 0 ; IIO_DEBUG ( " \n " , tok , fpos , fsiz ) ; void * pvalue = fpos + ( char * ) dat ; if ( fpos < 0 || abs ( fsiz ) + fpos > siz ) fail ( " " ) ; if ( endianness && abs ( fsiz ) == 2 ) switch_2endianness ( pvalue , 1 ) ; if ( endianness && abs ( fsiz ) == 4 ) switch_4endianness ( pvalue , 1 ) ; switch ( fsiz ) { case 1 : return * ( uint8_t * ) pvalue ; case 2 : return * ( uint16_t * ) pvalue ; case 4 : return * ( uint32_t * ) pvalue ; case -1 : return * ( int8_t * ) pvalue ; case -2 : return * ( int16_t * ) pvalue ; case -4 : return * ( int32_t * ) pvalue ; default : fail ( " " , fsiz ) ; } }
get an integer field from a data file, whose position
and type is determined by "tok"
get an integer field from a data file whose position and type is determined by " tok "