1
0
Fork 0

Merging upstream version 4.2+20231026.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-14 06:32:02 +01:00
parent bb079da599
commit a701b01644
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
30 changed files with 956 additions and 423 deletions

76
lib.c
View file

@ -27,6 +27,24 @@
#include <ctype.h>
#include <limits.h>
/**
* is_string_lq() - Check if string length with NULL byte is lower or equal to requested.
* @str: string to check.
* @max_len: max length.
*
* @str length must be bigger than 0 and be lower or equal @max_len, including termination byte.
*/
bool is_string_lq(const char * const str, size_t max_len)
{
assert(str);
size_t _len = strnlen(str, max_len);
if (_len > 0 && _len < max_len)
return true;
return false;
}
bool is_dev_alive(char *path)
{
if (!path)
@ -465,24 +483,50 @@ void print_quoted(char *str)
putchar(q);
}
void print_escape(char *str)
/**
* is_alphanum() - Check if sign is letter or digit.
* @c: char to analyze.
*
* Similar to isalnum() but additional locales are excluded.
*
* Return: %true on success, %false otherwise.
*/
bool is_alphanum(const char c)
{
/* print str, but change space and tab to '_'
* as is suitable for device names
*/
for (; *str; str++) {
switch (*str) {
case ' ':
case '\t':
putchar('_');
break;
case '/':
putchar('-');
break;
default:
putchar(*str);
}
if (isupper(c) || islower(c) || isdigit(c) != 0)
return true;
return false;
}
/**
* is_name_posix_compatible() - Check if name is POSIX compatible.
* @name: name to check.
*
* POSIX portable file name character set contains ASCII letters,
* digits, '_', '.', and '-'. Also forbid leading '-'.
* The length of the name cannot exceed NAME_MAX - 1 (ensure NULL ending).
*
* Return: %true on success, %false otherwise.
*/
bool is_name_posix_compatible(const char * const name)
{
assert(name);
char allowed_symbols[] = "-_.";
const char *n = name;
if (!is_string_lq(name, NAME_MAX))
return false;
if (*n == '-')
return false;
while (*n != '\0') {
if (!is_alphanum(*n) && !strchr(allowed_symbols, *n))
return false;
n++;
}
return true;
}
int check_env(char *name)