/***
This file is part of systemd.
Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <ctype.h>
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libudev.h"
#include "MurmurHash2.h"
#include "device-nodes.h"
#include "libudev-private.h"
#include "syslog-util.h"
#include "utf8.h"
/**
* SECTION:libudev-util
* @short_description: utils
*
* Utilities useful when dealing with devices and device node names.
*/
/* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
{
char *subsys;
char *sysname;
char *attr;
if (string[0] != '[')
return -1;
return -1;
sysname[0] = '\0';
return -1;
attr[0] = '\0';
if (attr[0] == '/')
if (attr[0] == '\0')
return -1;
return -1;
if (read_value) {
const char *val;
else
result[0] = '\0';
} else {
size_t l;
char *s;
s = result;
}
return 0;
}
{
char *endptr;
int prio;
return prio;
else
return -ERANGE;
}
return log_level_from_string(priority);
}
{
size_t i, j;
for (i = 0, j = 0; src[i] != '\0'; i++) {
if (src[i] == '/') {
if (j+4 >= size) {
j = 0;
break;
}
j += 4;
} else if (src[i] == '\\') {
if (j+4 >= size) {
j = 0;
break;
}
j += 4;
} else {
if (j+1 >= size) {
j = 0;
break;
}
j++;
}
}
dest[j] = '\0';
return j;
}
{
return;
}
{
size_t i, j;
/* strip trailing whitespace */
len--;
/* strip leading whitespace */
i = 0;
i++;
j = 0;
while (i < len) {
/* substitute multiple whitespace with a single '_' */
i++;
to[j++] = '_';
}
}
to[j] = '\0';
return 0;
}
/* allow chars in whitelist, plain ascii, hex-escaping and valid utf8 */
{
size_t i = 0;
int replaced = 0;
while (str[i] != '\0') {
int len;
i++;
continue;
}
/* accept hex encoding */
i += 2;
continue;
}
/* accept valid utf8 */
if (len > 1) {
i += len;
continue;
}
/* if space is allowed, replace whitespace with ordinary space */
str[i] = ' ';
i++;
replaced++;
continue;
}
/* everything else is replaced with '_' */
str[i] = '_';
i++;
replaced++;
}
return replaced;
}
/**
* udev_util_encode_string:
* @str: input string to be encoded
* @str_enc: output string to store the encoded input string
* @len: maximum size of the output string, which may be
* four times as long as the input string
*
* Encode all potentially unsafe characters of a string to the
* corresponding 2 char hex value prefixed by '\x'.
*
* Returns: 0 if the entire string was copied, non-zero otherwise.
**/
{
}
{
}
/* get a bunch of bit numbers out of the hash, and set the bits in our bit field */
{
return bits;
}