FreeBSD/usr.sbin/ypldap/aldap.c
/*
 * Parse a LDAP value
 * notes:
 *	the argument u should be a NULL terminated sequence of ASCII bytes.
 */
Parse a LDAP value
notes:
the argument u should be a NULL terminated sequence of ASCII bytes.
Parse a LDAP value notes : the argument u should be a NULL terminated sequence of ASCII bytes .
char *
parseval(char *p, size_t len)
{
	char	 hex[3];
	char	*cp = p, *buffer, *newbuffer;
	size_t	 size, newsize, i, j;
	size = 50;
	if ((buffer = calloc(1, size)) == NULL)
		return NULL;
	for (i = j = 0; j < len; i++) {
		if (i >= size) {
			newsize = size + 1024;
			if ((newbuffer = realloc(buffer, newsize)) == NULL) {
				free(buffer);
				return (NULL);
			}
			buffer = newbuffer;
			size = newsize;
		}
		if (cp[j] == '\\') {
			strlcpy(hex, cp + j + 1, sizeof(hex));
			buffer[i] = (char)strtoumax(hex, NULL, 16);
			j += 3;
		} else {
			buffer[i] = cp[j];
			j++;
		}
	}
	return buffer;
}
char * parseval ( char * p , size_t len ) { char hex [ 3 ] ; char * cp = p , * buffer , * newbuffer ; size_t size , newsize , i , j ; size = 50 ; if ( ( buffer = calloc ( 1 , size ) ) == NULL ) return NULL ; for ( i = j = 0 ; j < len ; i ++ ) { if ( i >= size ) { newsize = size + 1024 ; if ( ( newbuffer = realloc ( buffer , newsize ) ) == NULL ) { free ( buffer ) ; return ( NULL ) ; } buffer = newbuffer ; size = newsize ; } if ( cp [ j ] == ' \\ ' ) { strlcpy ( hex , cp + j + 1 , sizeof ( hex ) ) ; buffer [ i ] = ( char ) strtoumax ( hex , NULL , 16 ) ; j += 3 ; } else { buffer [ i ] = cp [ j ] ; j ++ ; } } return buffer ; }
Parse a LDAP value
 notes:
      the argument u should be a NULL terminated sequence of ASCII bytes.
Parse a LDAP value notes : the argument u should be a NULL terminated sequence of ASCII bytes .