]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/device-nodes.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2008-2011 Kay Sievers
10 #include "device-nodes.h"
13 int whitelisted_char_for_devnode(char c
, const char *white
) {
15 if ((c
>= '0' && c
<= '9') ||
16 (c
>= 'A' && c
<= 'Z') ||
17 (c
>= 'a' && c
<= 'z') ||
18 strchr("#+-.:=@_", c
) != NULL
||
19 (white
!= NULL
&& strchr(white
, c
) != NULL
))
25 int encode_devnode_name(const char *str
, char *str_enc
, size_t len
) {
31 for (i
= 0, j
= 0; str
[i
] != '\0'; i
++) {
34 seqlen
= utf8_encoded_valid_unichar(&str
[i
]);
37 if (len
-j
< (size_t)seqlen
)
40 memcpy(&str_enc
[j
], &str
[i
], seqlen
);
44 } else if (str
[i
] == '\\' || !whitelisted_char_for_devnode(str
[i
], NULL
)) {
49 sprintf(&str_enc
[j
], "\\x%02x", (unsigned char) str
[i
]);