From 0aaf5f12b22b70dbc0ae903768e5c3765aaf20b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Sat, 3 Feb 2024 19:37:46 +0900 Subject: [PATCH] =?utf8?q?=E6=9C=80=E6=96=B0=E3=83=AB=E3=83=BC=E3=83=AB?= =?utf8?q?=E3=81=AB=E5=BE=93=E3=81=86=E6=A7=98=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- listpass.c | 62 +++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/listpass.c b/listpass.c index 93429e8..0b18a6f 100644 --- a/listpass.c +++ b/listpass.c @@ -18,37 +18,37 @@ void listpass(char* basePath, int level) { } while ((entry = readdir(dir)) != NULL) { - if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { - char path[1000]; - int needed = snprintf(path, sizeof(path), "%s/%s", basePath, entry->d_name); - if (needed >= (int)sizeof(path) || needed < 0) { - if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Error: Path is too long, or failed to getting lenth"); - else perror("エラー:パスが長すぎる、又は長さを受取に失敗"); - continue; - } - - struct stat statbuf; - if (stat(path, &statbuf) == -1) { - if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading file status"); - else perror("ファイル状況を読込に失敗"); - continue; - } - - for (int i = 0; i < level; i++) { - printf(" "); - } - - if (S_ISDIR(statbuf.st_mode)) { - printf("|-- %s\n", entry->d_name); - listpass(path, level + 1); - } else if (S_ISREG(statbuf.st_mode)) { - char* filename = entry->d_name; - char* ext = strstr(filename, ".gpg"); - if (ext) { - *ext = '\0'; - } - printf("|-- %s\n", filename); - } + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { + continue; + } + + char path[1000]; + int needed = snprintf(path, sizeof(path), "%s/%s", basePath, entry->d_name); + if (needed >= (int)sizeof(path) || needed < 0) { + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Error: Path is too long, or failed to getting lenth"); + else perror("エラー:パスが長すぎる、又は長さを受取に失敗"); + continue; + } + + struct stat statbuf; + if (stat(path, &statbuf) == -1) { + if (lang != NULL && strncmp(lang, "en", 2) == 0) perror("Failed to reading file status"); + else perror("ファイル状況を読込に失敗"); + continue; + } + + for (int i = 0; i < level; i++) { + printf(" "); + } + + if (S_ISDIR(statbuf.st_mode)) { + printf("|-- %s\n", entry->d_name); + listpass(path, level + 1); + } else if (S_ISREG(statbuf.st_mode)) { + char* filename = entry->d_name; + char* ext = strstr(filename, ".gpg"); + if (ext) *ext = '\0'; + printf("|-- %s\n", filename); } } -- 2.43.0