diff --git a/src/bin/lsindex.cpp b/src/bin/lsindex.cpp index 6631119aa2..21f00f31db 100644 --- a/src/bin/lsindex.cpp +++ b/src/bin/lsindex.cpp @@ -1,10 +1,13 @@ -// lsindex - for Haiku -// -// authors, in order of contribution: -// jonas.sundstrom@kirilla.com -// revol@free.fr -// axeld@pinc-software.de -// +/* + * Copyright 2002-2020, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * jonas.sundstrom@kirilla.com + * revol@free.fr + * Axel Dörfler, axeld@pinc-software.de + */ + #include #include @@ -18,7 +21,7 @@ static void print_help(void) { - fprintf (stderr, + fprintf (stderr, "Usage: lsindex [--help | -v | --verbose | --mkindex | -l | --long] [volume path]\n" " -l --long\t outputs long listing\n" " -v --verbose\t gives index type, dates and owner\n" @@ -137,11 +140,13 @@ print_index_verbose_stat(const index_info &info, char *name) // Created char string[30]; - strftime(string, sizeof(string), "%Y-%m-%d %H:%M", localtime(&info.creation_time)); + strftime(string, sizeof(string), "%Y-%m-%d %H:%M", + localtime(&info.creation_time)); printf("%s ", string); // Modified - strftime(string, sizeof(string), "%Y-%m-%d %H:%M", localtime(&info.modification_time)); + strftime(string, sizeof(string), "%Y-%m-%d %H:%M", + localtime(&info.modification_time)); printf("%s", string); // User @@ -166,20 +171,23 @@ main(int argc, char **argv) if (!strcmp(argv[i], "--help")) { print_help(); return 0; - } else if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-v")) + } + if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-v")) verbose = true; else if (!strcmp(argv[i], "--long") || !strcmp(argv[i], "-l")) longListing = true; else if (!strcmp(argv[i], "--mkindex")) mkindexOutput = true; else { - fprintf(stderr, "%s: option %s is not understood (use --help for help)\n", argv[0], argv[i]); + fprintf(stderr, "%s: option %s is not understood (use --help " + "for help)\n", argv[0], argv[i]); return -1; } } else { device = dev_for_path(argv[i]); if (device < 0) { - fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], argv[i]); + fprintf(stderr, "%s: can't get information about volume: %s\n", + argv[0], argv[i]); return -1; } } @@ -198,10 +206,13 @@ main(int argc, char **argv) } while (1) { + // We have to reset errno before calling fs_read_index_dir(). + errno = 0; dirent *index = fs_read_index_dir(indices); if (index == NULL) { if (errno != B_ENTRY_NOT_FOUND && errno != B_OK) { - printf("%s: fs_read_index_dir: (%d) %s\n", argv[0], errno, strerror(errno)); + printf("%s: fs_read_index_dir: (%d) %s\n", argv[0], errno, + strerror(errno)); return errno; } break; @@ -211,7 +222,8 @@ main(int argc, char **argv) index_info info; if (fs_stat_index(device, index->d_name, &info) != B_OK) { - printf("%s: fs_stat_index(): (%d) %s\n", argv[0], errno, strerror(errno)); + printf("%s: fs_stat_index(): (%d) %s\n", argv[0], errno, + strerror(errno)); return errno; } @@ -219,8 +231,11 @@ main(int argc, char **argv) print_index_verbose_stat(info, index->d_name); else if (longListing) print_index_long_stat(info, index->d_name); - else /* mkindexOutput */ - printf("mkindex -t %s '%s'\n", print_index_type(info, true), index->d_name); + else { + // mkindex output + printf("mkindex -t %s '%s'\n", print_index_type(info, true), + index->d_name); + } } else printf("%s\n", index->d_name); }