FreeBSD/contrib/openbsm/libbsm/bsm_control.c
/*
 * Convert a string to a policy.  Return -1 on failure (with errno EINVAL,
 * ENOMEM) or 0 on success.
 */
Convert a string to a policy.  Return -1 on failure (with errno EINVAL,
ENOMEM) or 0 on success.
Convert a string to a policy . Return - 1 on failure ( with errno EINVAL ENOMEM ) or 0 on success .
int
au_strtopol(const char *polstr, int *policy)
{
	char *bufp, *string;
	char *buffer;
	int i, matched;
	*policy = 0;
	buffer = strdup(polstr);
	if (buffer == NULL)
		return (-1);
	bufp = buffer;
	while ((string = strsep(&bufp, ",")) != NULL) {
		matched = i = 0;
		do {
			if (strcmp(string, au_polstr[i].ap_str) == 0) {
				*policy |= au_polstr[i].ap_policy;
				matched = 1;
				break;
			}
		} while (NULL != au_polstr[++i].ap_str);
		if (!matched) {
			free(buffer);
			errno = EINVAL;
			return (-1);
		}
	}
	free(buffer);
	return (0);
}
int au_strtopol ( const char * polstr , int * policy ) { char * bufp , * string ; char * buffer ; int i , matched ; * policy = 0 ; buffer = strdup ( polstr ) ; if ( buffer == NULL ) return ( -1 ) ; bufp = buffer ; while ( ( string = strsep ( & bufp , " " ) ) != NULL ) { matched = i = 0 ; do { if ( strcmp ( string , au_polstr [ i ] . ap_str ) == 0 ) { * policy |= au_polstr [ i ] . ap_policy ; matched = 1 ; break ; } } while ( NULL != au_polstr [ ++ i ] . ap_str ) ; if ( ! matched ) { free ( buffer ) ; errno = EINVAL ; return ( -1 ) ; } } free ( buffer ) ; return ( 0 ) ; }
Convert a string to a policy.
Convert a string to a policy .