bin/tests/dst/t_dst.c
/*
 * Read sig in file at path to buf.
 */
Read sig in file at path to buf.
Read sig in file at path to buf .
static int
sig_fromfile(char *path, isc_buffer_t *iscbuf) {
	int		rval;
	int		len;
	int		fd;
	unsigned char	val;
	struct stat	sb;
	char		*p;
	char		*buf;
	rval = stat(path, &sb);
	if (rval != 0) {
		t_info("stat %s failed, errno == %d\n", path, errno);
		return(1);
	}
	buf = (char *) malloc((sb.st_size + 1) * sizeof(unsigned char));
	if (buf == NULL) {
		t_info("malloc failed, errno == %d\n", errno);
		return(1);
	}
	fd = open(path, O_RDONLY);
	if (fd < 0) {
		t_info("open failed, errno == %d\n", errno);
		(void) free(buf);
		return(1);
	}
	len = sb.st_size;
	p = buf;
	while (len) {
		rval = read(fd, p, len);
		if (rval > 0) {
			len -= rval;
			p += rval;
		}
		else {
			t_info("read failed %d, errno == %d\n", rval, errno);
			(void) free(buf);
			(void) close(fd);
			return(1);
		}
	}
	close(fd);
	p = buf;
	len = sb.st_size;
	while(len) {
		if (*p == '\n') {
			++p;
			--len;
			continue;
		}
		if (('0' <= *p) && (*p <= '9'))
			val = *p - '0';
		else
			val = *p - 'A' + 10;
		++p;
		val <<= 4;
		--len;
		if (('0' <= *p) && (*p <= '9'))
			val |= (*p - '0');
		else
			val |= (*p - 'A' + 10);
		++p;
		--len;
		isc_buffer_putuint8(iscbuf, val);
	}
	(void) free(buf);
	return(0);
}
static int sig_fromfile ( char * path , isc_buffer_t * iscbuf ) { int rval ; int len ; int fd ; unsigned char val ; struct stat sb ; char * p ; char * buf ; rval = stat ( path , & sb ) ; if ( rval != 0 ) { t_info ( " \n " , path , errno ) ; return ( 1 ) ; } buf = ( char * ) malloc ( ( sb . st_size + 1 ) * sizeof ( unsigned char ) ) ; if ( buf == NULL ) { t_info ( " \n " , errno ) ; return ( 1 ) ; } fd = open ( path , O_RDONLY ) ; if ( fd < 0 ) { t_info ( " \n " , errno ) ; ( void ) free ( buf ) ; return ( 1 ) ; } len = sb . st_size ; p = buf ; while ( len ) { rval = read ( fd , p , len ) ; if ( rval > 0 ) { len -= rval ; p += rval ; } else { t_info ( " \n " , rval , errno ) ; ( void ) free ( buf ) ; ( void ) close ( fd ) ; return ( 1 ) ; } } close ( fd ) ; p = buf ; len = sb . st_size ; while ( len ) { if ( * p == ' \n ' ) { ++ p ; -- len ; continue ; } if ( ( ' ' <= * p ) && ( * p <= ' ' ) ) val = * p - ' ' ; else val = * p - ' ' + 10 ; ++ p ; val <<= 4 ; -- len ; if ( ( ' ' <= * p ) && ( * p <= ' ' ) ) val |= ( * p - ' ' ) ; else val |= ( * p - ' ' + 10 ) ; ++ p ; -- len ; isc_buffer_putuint8 ( iscbuf , val ) ; } ( void ) free ( buf ) ; return ( 0 ) ; }
Read sig in file at path to buf.
Read sig in file at path to buf .