dev: remove strcln in favor of strdup

This commit is contained in:
javalsai 2025-06-11 16:13:01 +02:00
parent aa1cafe743
commit cbb3aa3910
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
4 changed files with 3 additions and 8 deletions

View File

@ -11,7 +11,6 @@
enum keys find_keyname(char*); enum keys find_keyname(char*);
enum keys find_ansi(char*); enum keys find_ansi(char*);
void read_press(u_char*, char*); void read_press(u_char*, char*);
void strcln(char** dest, const char* source);
struct Vector { struct Vector {
uint32_t length; uint32_t length;

View File

@ -174,7 +174,8 @@ bool launch(char* user, char* passwd, struct session session, void (*cb)(void),
if (pid == 0) { // child if (pid == 0) { // child
char* term = NULL; char* term = NULL;
char* getterm = getenv("TERM"); char* getterm = getenv("TERM");
if (getterm != NULL) strcln(&term, getterm); // TODO: handle malloc error
if (getterm != NULL) term = strdup(getterm);
if (clearenv() != 0) { if (clearenv() != 0) {
print_errno("clearenv"); print_errno("clearenv");
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);

View File

@ -46,7 +46,7 @@ struct Vector get_human_users() {
struct passwd* NULLABLE pwd; struct passwd* NULLABLE pwd;
while ((pwd = getpwent()) != NULL) { while ((pwd = getpwent()) != NULL) {
if (strcmp(pwd->pw_dir, "/home/") != 0) continue; if (!pwd->pw_dir || strcmp(pwd->pw_dir, "/home/") != 0) continue;
struct user* user_i = malloc(sizeof(struct user)); struct user* user_i = malloc(sizeof(struct user));
if (user_i == NULL) continue; // malloc error if (user_i == NULL) continue; // malloc error

View File

@ -11,11 +11,6 @@
static int selret_magic(); static int selret_magic();
void strcln(char** dest, const char* source) {
*dest = malloc(strlen(source) + sizeof(char));
strcpy(*dest, source);
}
enum keys find_keyname(char* name) { enum keys find_keyname(char* name) {
for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) { for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) {
if (strcmp(key_names[i], name) == 0) return (enum keys)i; if (strcmp(key_names[i], name) == 0) return (enum keys)i;