mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 14:25:03 +02:00
fix: missing \n (added perror too)
This commit is contained in:
parent
93f14f398e
commit
844687809b
@ -40,6 +40,7 @@ static u_int16_t used_size = 0;
|
||||
static struct session *sessions = NULL;
|
||||
static struct sessions_list *__sessions_list = NULL;
|
||||
|
||||
// NOTE: commented printf's here would be nice to have debug logs if I ever implement it
|
||||
static enum session_type session_type;
|
||||
static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||
// practically impossible to reach this
|
||||
@ -47,12 +48,14 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||
if (used_size == 0xffff)
|
||||
return 0;
|
||||
|
||||
if (!S_ISREG(sb->st_mode))
|
||||
if (sb == NULL || !S_ISREG(sb->st_mode))
|
||||
return 0;
|
||||
|
||||
/*printf("gonna open %s\n", fpath);*/
|
||||
FILE *fd = fopen(fpath, "r");
|
||||
if (fd == NULL) {
|
||||
fprintf(stderr, "error opening file (r) %s", fpath);
|
||||
perror("fopen");
|
||||
fprintf(stderr, "error opening file (r) %s\n", fpath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -63,6 +66,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||
char *exec_buf = NULL;
|
||||
char *tryexec_buf = NULL;
|
||||
while (true) {
|
||||
/*printf(".");*/
|
||||
char *buf = malloc(sb->st_blksize);
|
||||
ssize_t read_size = getline(&buf, &alloc_size, fd);
|
||||
if (read_size == -1) {
|
||||
@ -91,11 +95,13 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
||||
if (found == 0b111)
|
||||
break;
|
||||
}
|
||||
/*printf("\nend parsing...\n");*/
|
||||
|
||||
fclose(fd);
|
||||
|
||||
// just add this to the list
|
||||
if (name_buf != NULL && exec_buf != NULL) {
|
||||
/*printf("gonna add to session list\n");*/
|
||||
if (used_size >= alloc_size) {
|
||||
alloc_size += bs;
|
||||
sessions = realloc(sessions, alloc_size * unit_size);
|
||||
@ -128,6 +134,7 @@ struct sessions_list *get_avaliable_sessions() {
|
||||
|
||||
for (uint i = 0; i < sources_size; i++) {
|
||||
session_type = sources[i].type;
|
||||
/*printf("recurring into %s\n", sources[i].dir);*/
|
||||
ftw(sources[i].dir, &fn, 1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user