mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
Userland: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code.
This commit is contained in:
parent
5574d45eda
commit
0248ddc427
22 changed files with 85 additions and 83 deletions
|
@ -31,7 +31,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("usage: allocate [number [unit (B/KB/MB)]]\n");
|
printf("usage: allocate [number [unit (B/KB/MB)]]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -44,7 +44,7 @@ int target_day;
|
||||||
int current_year;
|
int current_year;
|
||||||
int current_month;
|
int current_month;
|
||||||
|
|
||||||
void append_to_print(char* buffer, int row, int column, char* text)
|
static void append_to_print(char* buffer, int row, int column, char* text)
|
||||||
{
|
{
|
||||||
int starting_point = (line_width * row) + (column * column_width);
|
int starting_point = (line_width * row) + (column * column_width);
|
||||||
for (int i = 0; text[i] != '\0'; i++) {
|
for (int i = 0; text[i] != '\0'; i++) {
|
||||||
|
@ -52,7 +52,7 @@ void append_to_print(char* buffer, int row, int column, char* text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert_month_to_print(int column, int month, int year)
|
static void insert_month_to_print(int column, int month, int year)
|
||||||
{
|
{
|
||||||
int printing_column = column;
|
int printing_column = column;
|
||||||
int printing_row = 0;
|
int printing_row = 0;
|
||||||
|
@ -95,7 +95,7 @@ void insert_month_to_print(int column, int month, int year)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean_buffers()
|
static void clean_buffers()
|
||||||
{
|
{
|
||||||
for (int i = 1; i < line_width * line_count; ++i) {
|
for (int i = 1; i < line_width * line_count; ++i) {
|
||||||
print_buffer[i - 1] = i % line_width == 0 ? '\n' : ' ';
|
print_buffer[i - 1] = i % line_width == 0 ? '\n' : ' ';
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct Options {
|
||||||
StringView type;
|
StringView type;
|
||||||
};
|
};
|
||||||
|
|
||||||
Options parse_options(int argc, char* argv[])
|
static Options parse_options(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
const char* type = "text/plain";
|
const char* type = "text/plain";
|
||||||
Vector<const char*> text;
|
Vector<const char*> text;
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct Result {
|
||||||
u64 read_bps;
|
u64 read_bps;
|
||||||
};
|
};
|
||||||
|
|
||||||
Result average_result(const Vector<Result>& results)
|
static Result average_result(const Vector<Result>& results)
|
||||||
{
|
{
|
||||||
Result average;
|
Result average;
|
||||||
|
|
||||||
|
@ -57,13 +57,13 @@ Result average_result(const Vector<Result>& results)
|
||||||
return average;
|
return average;
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_with_usage(int rc)
|
static void exit_with_usage(int rc)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: disk_benchmark [-h] [-d directory] [-t time_per_benchmark] [-f file_size1,file_size2,...] [-b block_size1,block_size2,...]\n");
|
fprintf(stderr, "Usage: disk_benchmark [-h] [-d directory] [-t time_per_benchmark] [-f file_size1,file_size2,...] [-b block_size1,block_size2,...]\n");
|
||||||
exit(rc);
|
exit(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache);
|
static Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ bool g_follow_symlinks = false;
|
||||||
bool g_there_was_an_error = false;
|
bool g_there_was_an_error = false;
|
||||||
bool g_have_seen_action_command = false;
|
bool g_have_seen_action_command = false;
|
||||||
|
|
||||||
[[noreturn]] void fatal_error(const char* format, ...)
|
[[noreturn]] static void fatal_error(const char* format, ...)
|
||||||
{
|
{
|
||||||
fputs("\033[31m", stderr);
|
fputs("\033[31m", stderr);
|
||||||
|
|
||||||
|
@ -309,11 +309,11 @@ private:
|
||||||
NonnullOwnPtr<Command> m_rhs;
|
NonnullOwnPtr<Command> m_rhs;
|
||||||
};
|
};
|
||||||
|
|
||||||
OwnPtr<Command> parse_complex_command(char* argv[]);
|
static OwnPtr<Command> parse_complex_command(char* argv[]);
|
||||||
|
|
||||||
// Parse a simple command starting at optind; leave optind at its the last
|
// Parse a simple command starting at optind; leave optind at its the last
|
||||||
// argument. Return nullptr if we reach the end of arguments.
|
// argument. Return nullptr if we reach the end of arguments.
|
||||||
OwnPtr<Command> parse_simple_command(char* argv[])
|
static OwnPtr<Command> parse_simple_command(char* argv[])
|
||||||
{
|
{
|
||||||
StringView arg = argv[optind];
|
StringView arg = argv[optind];
|
||||||
|
|
||||||
|
@ -352,14 +352,16 @@ OwnPtr<Command> parse_simple_command(char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Command> parse_complex_command(char* argv[])
|
static OwnPtr<Command> parse_complex_command(char* argv[])
|
||||||
{
|
{
|
||||||
auto command = parse_simple_command(argv);
|
auto command = parse_simple_command(argv);
|
||||||
|
|
||||||
while (command && argv[optind] && argv[optind + 1]) {
|
while (command && argv[optind] && argv[optind + 1]) {
|
||||||
StringView arg = argv[++optind];
|
StringView arg = argv[++optind];
|
||||||
|
|
||||||
enum { And, Or } binary_operation = And;
|
enum { And,
|
||||||
|
Or } binary_operation
|
||||||
|
= And;
|
||||||
|
|
||||||
if (arg == "-a") {
|
if (arg == "-a") {
|
||||||
optind++;
|
optind++;
|
||||||
|
@ -389,7 +391,7 @@ OwnPtr<Command> parse_complex_command(char* argv[])
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<Command> parse_all_commands(char* argv[])
|
static NonnullOwnPtr<Command> parse_all_commands(char* argv[])
|
||||||
{
|
{
|
||||||
auto command = parse_complex_command(argv);
|
auto command = parse_complex_command(argv);
|
||||||
|
|
||||||
|
@ -405,7 +407,7 @@ NonnullOwnPtr<Command> parse_all_commands(char* argv[])
|
||||||
return make<AndCommand>(command.release_nonnull(), make<PrintCommand>());
|
return make<AndCommand>(command.release_nonnull(), make<PrintCommand>());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* parse_options(int argc, char* argv[])
|
static const char* parse_options(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Sadly, we can't use Core::ArgsParser, because find accepts arguments in
|
// Sadly, we can't use Core::ArgsParser, because find accepts arguments in
|
||||||
// an extremely unusual format. We're going to try to use getopt(), though.
|
// an extremely unusual format. We're going to try to use getopt(), though.
|
||||||
|
@ -440,7 +442,7 @@ const char* parse_options(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void walk_tree(const char* root_path, Command& command)
|
static void walk_tree(const char* root_path, Command& command)
|
||||||
{
|
{
|
||||||
command.evaluate(root_path);
|
command.evaluate(root_path);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
OwnPtr<DebugSession> g_debug_session;
|
static OwnPtr<DebugSession> g_debug_session;
|
||||||
static bool g_should_output_color = false;
|
static bool g_should_output_color = false;
|
||||||
|
|
||||||
static void handle_sigint(int)
|
static void handle_sigint(int)
|
||||||
|
@ -58,7 +58,7 @@ static void handle_sigint(int)
|
||||||
g_debug_session = nullptr;
|
g_debug_session = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_function_call(String function_name, size_t depth)
|
static void print_function_call(String function_name, size_t depth)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < depth; ++i) {
|
for (size_t i = 0; i < depth; ++i) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
@ -66,7 +66,7 @@ void print_function_call(String function_name, size_t depth)
|
||||||
printf("=> %s\n", function_name.characters());
|
printf("=> %s\n", function_name.characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_syscall(PtraceRegisters& regs, size_t depth)
|
static void print_syscall(PtraceRegisters& regs, size_t depth)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < depth; ++i) {
|
for (size_t i = 0; i < depth; ++i) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
@ -83,7 +83,7 @@ void print_syscall(PtraceRegisters& regs, size_t depth)
|
||||||
end_color);
|
end_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
static NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
||||||
{
|
{
|
||||||
(void)demangle("foo"); // Required for linked with __cxa_demangle
|
(void)demangle("foo"); // Required for linked with __cxa_demangle
|
||||||
auto instrumented = make<HashMap<void*, X86::Instruction>>();
|
auto instrumented = make<HashMap<void*, X86::Instruction>>();
|
||||||
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_uid_object(uid_t uid)
|
static bool print_uid_object(uid_t uid)
|
||||||
{
|
{
|
||||||
if (flag_print_name) {
|
if (flag_print_name) {
|
||||||
struct passwd* pw = getpwuid(uid);
|
struct passwd* pw = getpwuid(uid);
|
||||||
|
@ -92,7 +92,7 @@ bool print_uid_object(uid_t uid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_gid_object(gid_t gid)
|
static bool print_gid_object(gid_t gid)
|
||||||
{
|
{
|
||||||
if (flag_print_name) {
|
if (flag_print_name) {
|
||||||
struct group* gr = getgrgid(gid);
|
struct group* gr = getgrgid(gid);
|
||||||
|
@ -102,7 +102,7 @@ bool print_gid_object(gid_t gid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_gid_list()
|
static bool print_gid_list()
|
||||||
{
|
{
|
||||||
int extra_gid_count = getgroups(0, nullptr);
|
int extra_gid_count = getgroups(0, nullptr);
|
||||||
if (extra_gid_count) {
|
if (extra_gid_count) {
|
||||||
|
@ -127,7 +127,7 @@ bool print_gid_list()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_full_id_list()
|
static bool print_full_id_list()
|
||||||
{
|
{
|
||||||
|
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
|
@ -159,7 +159,7 @@ bool print_full_id_list()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int print_id_objects()
|
static int print_id_objects()
|
||||||
{
|
{
|
||||||
if (flag_print_uid) {
|
if (flag_print_uid) {
|
||||||
if (!print_uid_object(getuid()))
|
if (!print_uid_object(getuid()))
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
String si_bytes(unsigned bytes)
|
static String si_bytes(unsigned bytes)
|
||||||
{
|
{
|
||||||
if (bytes >= GB)
|
if (bytes >= GB)
|
||||||
return String::format("%fGiB", (double)bytes / (double)GB);
|
return String::format("%fGiB", (double)bytes / (double)GB);
|
||||||
|
|
|
@ -82,7 +82,7 @@ static String prompt_for_level(int level)
|
||||||
return prompt_builder.build();
|
return prompt_builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
String read_next_piece()
|
static String read_next_piece()
|
||||||
{
|
{
|
||||||
StringBuilder piece;
|
StringBuilder piece;
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ static void print_regexp(const JS::Object& object, HashTable<JS::Object*>&)
|
||||||
printf("\033[34;1m/%s/%s\033[0m", regexp.content().characters(), regexp.flags().characters());
|
printf("\033[34;1m/%s/%s\033[0m", regexp.content().characters(), regexp.flags().characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
|
static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
|
||||||
{
|
{
|
||||||
if (value.is_empty()) {
|
if (value.is_empty()) {
|
||||||
printf("\033[34;1m<empty>\033[0m");
|
printf("\033[34;1m<empty>\033[0m");
|
||||||
|
@ -292,14 +292,14 @@ static void print(JS::Value value)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_has_shebang(AK::ByteBuffer file_contents)
|
static bool file_has_shebang(AK::ByteBuffer file_contents)
|
||||||
{
|
{
|
||||||
if (file_contents.size() >= 2 && file_contents[0] == '#' && file_contents[1] == '!')
|
if (file_contents.size() >= 2 && file_contents[0] == '#' && file_contents[1] == '!')
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView strip_shebang(AK::ByteBuffer file_contents)
|
static StringView strip_shebang(AK::ByteBuffer file_contents)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 2; i < file_contents.size(); ++i) {
|
for (i = 2; i < file_contents.size(); ++i) {
|
||||||
|
@ -309,7 +309,7 @@ StringView strip_shebang(AK::ByteBuffer file_contents)
|
||||||
return StringView((const char*)file_contents.data() + i, file_contents.size() - i);
|
return StringView((const char*)file_contents.data() + i, file_contents.size() - i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_to_file(const StringView& path)
|
static bool write_to_file(const StringView& path)
|
||||||
{
|
{
|
||||||
int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
for (size_t i = 0; i < repl_statements.size(); i++) {
|
for (size_t i = 0; i < repl_statements.size(); i++) {
|
||||||
|
@ -335,7 +335,7 @@ bool write_to_file(const StringView& path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_and_run(JS::Interpreter& interpreter, const StringView& source)
|
static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source)
|
||||||
{
|
{
|
||||||
auto parser = JS::Parser(JS::Lexer(source));
|
auto parser = JS::Parser(JS::Lexer(source));
|
||||||
auto program = parser.parse_program();
|
auto program = parser.parse_program();
|
||||||
|
@ -443,7 +443,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file)
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void repl(JS::Interpreter& interpreter)
|
static void repl(JS::Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
while (!s_fail_repl) {
|
while (!s_fail_repl) {
|
||||||
String piece = read_next_piece();
|
String piece = read_next_piece();
|
||||||
|
@ -455,7 +455,7 @@ void repl(JS::Interpreter& interpreter)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Function<void()> interrupt_interpreter;
|
static Function<void()> interrupt_interpreter;
|
||||||
void sigint_handler()
|
static void sigint_handler()
|
||||||
{
|
{
|
||||||
interrupt_interpreter();
|
interrupt_interpreter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ int main(int argc, char** argv)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int print_escaped(const char* name)
|
static int print_escaped(const char* name)
|
||||||
{
|
{
|
||||||
int printed = 0;
|
int printed = 0;
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ static String& hostname()
|
||||||
return s_hostname;
|
return s_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t print_name(const struct stat& st, const String& name, const char* path_for_link_resolution, const char* path_for_hyperlink)
|
static size_t print_name(const struct stat& st, const String& name, const char* path_for_link_resolution, const char* path_for_hyperlink)
|
||||||
{
|
{
|
||||||
if (!flag_disable_hyperlinks) {
|
if (!flag_disable_hyperlinks) {
|
||||||
if (auto* full_path = realpath(path_for_hyperlink, nullptr)) {
|
if (auto* full_path = realpath(path_for_hyperlink, nullptr)) {
|
||||||
|
@ -250,7 +250,7 @@ static String human_readable_size(size_t size)
|
||||||
return number_string_with_one_decimal((float)size / (float)GB, "G");
|
return number_string_with_one_decimal((float)size / (float)GB, "G");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_filesystem_object(const String& path, const String& name, const struct stat& st)
|
static bool print_filesystem_object(const String& path, const String& name, const struct stat& st)
|
||||||
{
|
{
|
||||||
if (flag_show_inode)
|
if (flag_show_inode)
|
||||||
printf("%08u ", st.st_ino);
|
printf("%08u ", st.st_ino);
|
||||||
|
@ -318,7 +318,7 @@ bool print_filesystem_object(const String& path, const String& name, const struc
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_file_system_object_long(const char* path)
|
static int do_file_system_object_long(const char* path)
|
||||||
{
|
{
|
||||||
Core::DirIterator di(path, !flag_show_dotfiles ? Core::DirIterator::SkipDots : Core::DirIterator::Flags::NoFlags);
|
Core::DirIterator di(path, !flag_show_dotfiles ? Core::DirIterator::SkipDots : Core::DirIterator::Flags::NoFlags);
|
||||||
if (di.has_error()) {
|
if (di.has_error()) {
|
||||||
|
@ -383,7 +383,7 @@ int do_file_system_object_long(const char* path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_filesystem_object_short(const char* path, const char* name, size_t* nprinted)
|
static bool print_filesystem_object_short(const char* path, const char* name, size_t* nprinted)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int rc = lstat(path, &st);
|
int rc = lstat(path, &st);
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct OpenFile {
|
||||||
String name;
|
String name;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
||||||
{
|
{
|
||||||
auto file = Core::File::open(String::format("/proc/%d/fds", pid), Core::IODevice::OpenMode::ReadOnly);
|
auto file = Core::File::open(String::format("/proc/%d/fds", pid), Core::IODevice::OpenMode::ReadOnly);
|
||||||
if (file.is_error()) {
|
if (file.is_error()) {
|
||||||
|
@ -69,7 +69,7 @@ Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_entry(const OpenFile& file, const Core::ProcessStatistics& statistics)
|
static void display_entry(const OpenFile& file, const Core::ProcessStatistics& statistics)
|
||||||
{
|
{
|
||||||
printf("%-28s %4d %4d %-10s %4d %s\n", statistics.name.characters(), file.pid, statistics.pgid, statistics.username.characters(), file.fd, file.name.characters());
|
printf("%-28s %4d %4d %-10s %4d %s\n", statistics.name.characters(), file.pid, statistics.pgid, statistics.username.characters(), file.fd, file.name.characters());
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
static int key_fd;
|
static int key_fd;
|
||||||
|
|
||||||
void wait_for_key()
|
static void wait_for_key()
|
||||||
{
|
{
|
||||||
printf("\033[7m--[ more ]--\033[0m");
|
printf("\033[7m--[ more ]--\033[0m");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int parse_options(const StringView& options)
|
static int parse_options(const StringView& options)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
Vector<StringView> parts = options.split_view(',');
|
Vector<StringView> parts = options.split_view(',');
|
||||||
|
@ -60,12 +60,12 @@ int parse_options(const StringView& options)
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_source_none(const char* source)
|
static bool is_source_none(const char* source)
|
||||||
{
|
{
|
||||||
return !strcmp("none", source);
|
return !strcmp("none", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_source_fd(const char* source)
|
static int get_source_fd(const char* source)
|
||||||
{
|
{
|
||||||
if (is_source_none(source))
|
if (is_source_none(source))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -81,7 +81,7 @@ int get_source_fd(const char* source)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mount_all()
|
static bool mount_all()
|
||||||
{
|
{
|
||||||
// Mount all filesystems listed in /etc/fstab.
|
// Mount all filesystems listed in /etc/fstab.
|
||||||
dbg() << "Mounting all filesystems...";
|
dbg() << "Mounting all filesystems...";
|
||||||
|
@ -139,7 +139,7 @@ bool mount_all()
|
||||||
return all_ok;
|
return all_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_mounts()
|
static bool print_mounts()
|
||||||
{
|
{
|
||||||
// Output info about currently mounted filesystems.
|
// Output info about currently mounted filesystems.
|
||||||
auto df = Core::File::construct("/proc/df");
|
auto df = Core::File::construct("/proc/df");
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
uint16_t internet_checksum(const void* ptr, size_t count)
|
static uint16_t internet_checksum(const void* ptr, size_t count)
|
||||||
{
|
{
|
||||||
uint32_t checksum = 0;
|
uint32_t checksum = 0;
|
||||||
auto* w = (const uint16_t*)ptr;
|
auto* w = (const uint16_t*)ptr;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int remove(bool recursive, bool force, String path)
|
static int remove(bool recursive, bool force, String path)
|
||||||
{
|
{
|
||||||
struct stat path_stat;
|
struct stat path_stat;
|
||||||
if (lstat(path.characters(), &path_stat) < 0) {
|
if (lstat(path.characters(), &path_stat) < 0) {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
double get_double(const char* name, const char* d_string, int* number_of_decimals)
|
static double get_double(const char* name, const char* d_string, int* number_of_decimals)
|
||||||
{
|
{
|
||||||
char* end;
|
char* end;
|
||||||
double d = strtod(d_string, &end);
|
double d = strtod(d_string, &end);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void handle_sigint(int)
|
static void handle_sigint(int)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#define DEFAULT_LINE_COUNT 10
|
#define DEFAULT_LINE_COUNT 10
|
||||||
|
|
||||||
int tail_from_pos(Core::File& file, off_t startline, bool want_follow)
|
static int tail_from_pos(Core::File& file, off_t startline, bool want_follow)
|
||||||
{
|
{
|
||||||
if (!file.seek(startline + 1))
|
if (!file.seek(startline + 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -62,7 +62,7 @@ int tail_from_pos(Core::File& file, off_t startline, bool want_follow)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t find_seek_pos(Core::File& file, int wanted_lines)
|
static off_t find_seek_pos(Core::File& file, int wanted_lines)
|
||||||
{
|
{
|
||||||
// Rather than reading the whole file, start at the end and work backwards,
|
// Rather than reading the whole file, start at the end and work backwards,
|
||||||
// stopping when we've found the number of lines we want.
|
// stopping when we've found the number of lines we want.
|
||||||
|
|
|
@ -41,7 +41,7 @@ static int max_depth = INT_MAX;
|
||||||
static int g_directories_seen = 0;
|
static int g_directories_seen = 0;
|
||||||
static int g_files_seen = 0;
|
static int g_files_seen = 0;
|
||||||
|
|
||||||
void print_directory_tree(const String& root_path, int depth, const String& indent_string)
|
static void print_directory_tree(const String& root_path, int depth, const String& indent_string)
|
||||||
{
|
{
|
||||||
if (depth > 0) {
|
if (depth > 0) {
|
||||||
String root_indent_string;
|
String root_indent_string;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
static const u8 central_directory_file_header_sig[] = "\x50\x4b\x01\x02";
|
static const u8 central_directory_file_header_sig[] = "\x50\x4b\x01\x02";
|
||||||
|
|
||||||
bool seek_and_read(u8* buffer, const MappedFile& file, off_t seek_to, size_t bytes_to_read)
|
static bool seek_and_read(u8* buffer, const MappedFile& file, off_t seek_to, size_t bytes_to_read)
|
||||||
{
|
{
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return false;
|
return false;
|
||||||
|
@ -46,7 +46,7 @@ bool seek_and_read(u8* buffer, const MappedFile& file, off_t seek_to, size_t byt
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool find_next_central_directory(off_t file_size, const MappedFile& file, off_t current_index, off_t& return_index)
|
static bool find_next_central_directory(off_t file_size, const MappedFile& file, off_t current_index, off_t& return_index)
|
||||||
{
|
{
|
||||||
off_t start_index = current_index == 0 ? current_index : current_index + 1;
|
off_t start_index = current_index == 0 ? current_index : current_index + 1;
|
||||||
for (off_t index = start_index; index < file_size - 4; index++) {
|
for (off_t index = start_index; index < file_size - 4; index++) {
|
||||||
|
@ -62,7 +62,7 @@ bool find_next_central_directory(off_t file_size, const MappedFile& file, off_t
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unpack_file_for_central_directory_index(off_t central_directory_index, const MappedFile& file)
|
static bool unpack_file_for_central_directory_index(off_t central_directory_index, const MappedFile& file)
|
||||||
{
|
{
|
||||||
enum CentralFileDirectoryHeaderOffsets {
|
enum CentralFileDirectoryHeaderOffsets {
|
||||||
CFDHCompressionMethodOffset = 10,
|
CFDHCompressionMethodOffset = 10,
|
||||||
|
|
|
@ -42,7 +42,7 @@ static bool flag_beep_on_fail = false;
|
||||||
static volatile int exit_code = 0;
|
static volatile int exit_code = 0;
|
||||||
static volatile pid_t child_pid = -1;
|
static volatile pid_t child_pid = -1;
|
||||||
|
|
||||||
String build_header_string(const Vector<const char*>& command, const struct timeval& interval)
|
static String build_header_string(const Vector<const char*>& command, const struct timeval& interval)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendf("Every %d", interval.tv_sec);
|
builder.appendf("Every %d", interval.tv_sec);
|
||||||
|
@ -52,7 +52,7 @@ String build_header_string(const Vector<const char*>& command, const struct time
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval get_current_time()
|
static struct timeval get_current_time()
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -61,14 +61,14 @@ struct timeval get_current_time()
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t usecs_from(const struct timeval& start, const struct timeval& end)
|
static int64_t usecs_from(const struct timeval& start, const struct timeval& end)
|
||||||
{
|
{
|
||||||
struct timeval diff;
|
struct timeval diff;
|
||||||
timeval_sub(end, start, diff);
|
timeval_sub(end, start, diff);
|
||||||
return 1000000 * diff.tv_sec + diff.tv_usec;
|
return 1000000 * diff.tv_sec + diff.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_signal(int signal)
|
static void handle_signal(int signal)
|
||||||
{
|
{
|
||||||
if (child_pid > 0) {
|
if (child_pid > 0) {
|
||||||
if (kill(child_pid, signal) < 0) {
|
if (kill(child_pid, signal) < 0) {
|
||||||
|
@ -84,7 +84,7 @@ void handle_signal(int signal)
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_command(const Vector<const char*>& command)
|
static int run_command(const Vector<const char*>& command)
|
||||||
{
|
{
|
||||||
if ((errno = posix_spawnp(const_cast<pid_t*>(&child_pid), command[0], nullptr, nullptr, const_cast<char**>(command.data()), environ))) {
|
if ((errno = posix_spawnp(const_cast<pid_t*>(&child_pid), command[0], nullptr, nullptr, const_cast<char**>(command.data()), environ))) {
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
|
|
|
@ -44,7 +44,7 @@ bool output_line = false;
|
||||||
bool output_byte = false;
|
bool output_byte = false;
|
||||||
bool output_word = false;
|
bool output_word = false;
|
||||||
|
|
||||||
void wc_out(Count& count)
|
static void wc_out(Count& count)
|
||||||
{
|
{
|
||||||
if (output_line)
|
if (output_line)
|
||||||
printf("%7i ", count.lines);
|
printf("%7i ", count.lines);
|
||||||
|
@ -56,7 +56,7 @@ void wc_out(Count& count)
|
||||||
printf("%14s\n", count.name.characters());
|
printf("%14s\n", count.name.characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
Count get_count(const String& file_name)
|
static Count get_count(const String& file_name)
|
||||||
{
|
{
|
||||||
Count count;
|
Count count;
|
||||||
FILE* file_pointer = nullptr;
|
FILE* file_pointer = nullptr;
|
||||||
|
@ -86,7 +86,7 @@ Count get_count(const String& file_name)
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
Count get_total_count(Vector<Count>& counts)
|
static Count get_total_count(Vector<Count>& counts)
|
||||||
{
|
{
|
||||||
Count total_count { "total" };
|
Count total_count { "total" };
|
||||||
for (auto& count : counts) {
|
for (auto& count : counts) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue