]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/device-nodes.c
bbbe563fa1f36e2bbad8270a6ddaa1021e79d78b
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2008-2011 Kay Sievers
12 #include "device-nodes.h"
15 int whitelisted_char_for_devnode(char c
, const char *white
) {
17 if ((c
>= '0' && c
<= '9') ||
18 (c
>= 'A' && c
<= 'Z') ||
19 (c
>= 'a' && c
<= 'z') ||
20 strchr("#+-.:=@_", c
) != NULL
||
21 (white
!= NULL
&& strchr(white
, c
) != NULL
))
27 int encode_devnode_name(const char *str
, char *str_enc
, size_t len
) {
33 for (i
= 0, j
= 0; str
[i
] != '\0'; i
++) {
36 seqlen
= utf8_encoded_valid_unichar(&str
[i
]);
39 if (len
-j
< (size_t)seqlen
)
42 memcpy(&str_enc
[j
], &str
[i
], seqlen
);
46 } else if (str
[i
] == '\\' || !whitelisted_char_for_devnode(str
[i
], NULL
)) {
51 sprintf(&str_enc
[j
], "\\x%02x", (unsigned char) str
[i
]);