Mercurial > geeqie.yaz
comparison src/ui_fileops.c @ 576:9dc0513837b5
dropped path_list functions, use filelist functions everywhere
author | nadvornik |
---|---|
date | Sun, 04 May 2008 21:54:20 +0000 |
parents | e421326e8b43 |
children | 651ae2be1031 |
comparison
equal
deleted
inserted
replaced
575:b941403a4cd9 | 576:9dc0513837b5 |
---|---|
503 g_free(pathl); | 503 g_free(pathl); |
504 | 504 |
505 return path8; | 505 return path8; |
506 } | 506 } |
507 | 507 |
508 static gint path_list_real(const gchar *path, GList **files, GList **dirs, | 508 void string_list_free(GList *list) |
509 gint follow_links) | |
510 { | |
511 DIR *dp; | |
512 struct dirent *dir; | |
513 GList *f_list = NULL; | |
514 GList *d_list = NULL; | |
515 gchar *pathl; | |
516 | |
517 if (!path) return FALSE; | |
518 | |
519 pathl = path_from_utf8(path); | |
520 dp = opendir(pathl); | |
521 if (!dp) | |
522 { | |
523 /* dir not found */ | |
524 g_free(pathl); | |
525 return FALSE; | |
526 } | |
527 | |
528 /* root dir fix */ | |
529 if (pathl[0] == '/' && pathl[1] == '\0') | |
530 { | |
531 g_free(pathl); | |
532 pathl = g_strdup(""); | |
533 } | |
534 | |
535 while ((dir = readdir(dp)) != NULL) | |
536 { | |
537 struct stat st_buf; | |
538 gchar *name; | |
539 gchar *filepath; | |
540 gint result; | |
541 | |
542 name = dir->d_name; | |
543 filepath = g_strconcat(pathl, "/", name, NULL); | |
544 | |
545 if (follow_links) | |
546 { | |
547 result = stat(filepath, &st_buf); | |
548 } | |
549 else | |
550 { | |
551 result = lstat(filepath, &st_buf); | |
552 } | |
553 | |
554 if (result == 0) | |
555 { | |
556 gchar *path8; | |
557 gchar *name8; | |
558 | |
559 name8 = path_to_utf8(name); | |
560 path8 = g_strconcat(path, "/", name8, NULL); | |
561 g_free(name8); | |
562 | |
563 if (dirs && S_ISDIR(st_buf.st_mode) && | |
564 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) ) | |
565 { | |
566 d_list = g_list_prepend(d_list, path8); | |
567 path8 = NULL; | |
568 } | |
569 else if (files && | |
570 (S_ISREG(st_buf.st_mode) || (!follow_links && S_ISLNK(st_buf.st_mode))) ) | |
571 { | |
572 f_list = g_list_prepend(f_list, path8); | |
573 path8 = NULL; | |
574 } | |
575 g_free(path8); | |
576 } | |
577 | |
578 g_free(filepath); | |
579 } | |
580 | |
581 closedir(dp); | |
582 | |
583 g_free(pathl); | |
584 | |
585 if (dirs) *dirs = g_list_reverse(d_list); | |
586 if (files) *files = g_list_reverse(f_list); | |
587 | |
588 return TRUE; | |
589 } | |
590 | |
591 gint path_list(const gchar *path, GList **files, GList **dirs) | |
592 { | |
593 return path_list_real(path, files, dirs, TRUE); | |
594 } | |
595 | |
596 gint path_list_lstat(const gchar *path, GList **files, GList **dirs) | |
597 { | |
598 return path_list_real(path, files, dirs, FALSE); | |
599 } | |
600 | |
601 void path_list_free(GList *list) | |
602 { | 509 { |
603 g_list_foreach(list, (GFunc)g_free, NULL); | 510 g_list_foreach(list, (GFunc)g_free, NULL); |
604 g_list_free(list); | 511 g_list_free(list); |
605 } | 512 } |
606 | 513 |
607 GList *path_list_copy(GList *list) | 514 GList *string_list_copy(GList *list) |
608 { | 515 { |
609 GList *new_list = NULL; | 516 GList *new_list = NULL; |
610 GList *work; | 517 GList *work; |
611 | 518 |
612 work = list; | 519 work = list; |