ltos.c revision 4201a95e0468170d576f82c3aa63afecf718497a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#if !defined(_KERNEL)
#include <errno.h>
#endif /* !defined(_KERNEL) */
#if !defined(_KERNEL)
#include "clnt.h"
#include "labeld.h"
#endif /* !defined(_KERNEL) */
#if defined(_KERNEL)
#else
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#endif
static _mac_label_impl_t low;
static _mac_label_impl_t high;
static int inited = 0;
#if defined(_KERNEL)
#else /* defined(_KERNEL) */
#endif /* defined(_KERNEL) */
/* 0x + Classification + '-' + ll + '-' + Compartments + end of string */
/* 0x + Classification + '-' + ll + '-' + end of string */
static char digits[] = "0123456789abcdef";
#define HEX(h, i, l, s) \
for (; i < s; /* */) {\
h[i++] = digits[(unsigned int)(*l >> 4)];\
h[i++] = digits[(unsigned int)(*l++&0xF)]; }
static int
{
char *hex;
int i = 0;
int hex_len;
if (*len == 0) {
/* old binary label */
} else {
}
return (-1);
}
/* header */
hex[i++] = '0';
hex[i++] = 'x';
/* classification */
hl++; /* start at classification */
/* Add compartments length */
hex[i++] = '-';
hex[i++] = '-';
/* compartments */
hex[i] = '\0';
/* truncate trailing zeros */
i -= 2;
}
hex[i] = '\0';
return (-1);
}
return (0);
}
int
l_to_str_internal(const m_label_t *l, char **s)
{
if (inited == 0) {
inited = 1;
}
#if !defined(_KERNEL)
#endif /* !defined(_KERNEL) */
*s = NULL;
return (-1);
}
return (-1);
}
return (0);
}
return (-1);
}
return (0);
}
return (__hex(s, l));
}
#if !defined(_KERNEL)
/*
* label_to_str -- convert a label to the requested type of string.
*
* Entry l = label to convert;
* t = type of conversion;
* f = flags for conversion type;
*
* Exit *s = allocated converted string;
* Caller must call free() to free.
*
* Returns 0, success.
* -1, error, errno set; *s = NULL.
*
* Calls labeld
*/
int
{
int err;
int string_start = 0;
if (inited == 0) {
inited = 1;
}
switch (t) {
case M_LABEL:
SUCCESS) {
*s = NULL;
return (-1);
}
/* release returned buffer */
}
if (*s == NULL) {
return (-1);
}
return (0);
}
switch (err) {
case NOSERVER:
/* server not present */
/* special case admin_low and admin_high */
return (-1);
}
return (0);
return (-1);
}
return (0);
}
break;
default:
break;
}
*s = NULL;
return (-1);
case M_INTERNAL: {
return (l_to_str_internal(l, s));
}
case M_COLOR:
*s = NULL;
return (-1);
}
/* release returned buffer */
}
if (*s == NULL) {
return (-1);
}
return (0);
} else {
*s = NULL;
return (-1);
}
case PRINTER_TOP_BOTTOM:
break;
case PRINTER_LABEL:
break;
case PRINTER_CAVEATS:
break;
case PRINTER_CHANNELS:
break;
default:
*s = NULL;
return (-1);
}
/* do the common printer calls */
*s = NULL;
return (-1);
}
/* release returned buffer */
}
if (*s == NULL) {
return (-1);
}
return (0);
} else {
*s = NULL;
return (-1);
}
}
#endif /* !defined(_KERNEL) */