1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:17:35 +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:
Ben Wiederhake 2020-08-10 23:48:37 +02:00 committed by Andreas Kling
parent 5574d45eda
commit 0248ddc427
22 changed files with 85 additions and 83 deletions

View file

@ -31,7 +31,7 @@
#include <string.h>
#include <unistd.h>
void usage(void)
static void usage(void)
{
printf("usage: allocate [number [unit (B/KB/MB)]]\n");
exit(1);

View file

@ -44,7 +44,7 @@ int target_day;
int current_year;
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);
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_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) {
print_buffer[i - 1] = i % line_width == 0 ? '\n' : ' ';

View file

@ -39,7 +39,7 @@ struct Options {
StringView type;
};
Options parse_options(int argc, char* argv[])
static Options parse_options(int argc, char* argv[])
{
const char* type = "text/plain";
Vector<const char*> text;

View file

@ -42,7 +42,7 @@ struct Result {
u64 read_bps;
};
Result average_result(const Vector<Result>& results)
static Result average_result(const Vector<Result>& results)
{
Result average;
@ -57,13 +57,13 @@ Result average_result(const Vector<Result>& results)
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");
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)
{

View file

@ -40,7 +40,7 @@ bool g_follow_symlinks = false;
bool g_there_was_an_error = 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);
@ -309,11 +309,11 @@ private:
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
// 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];
@ -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);
while (command && argv[optind] && argv[optind + 1]) {
StringView arg = argv[++optind];
enum { And, Or } binary_operation = And;
enum { And,
Or } binary_operation
= And;
if (arg == "-a") {
optind++;
@ -389,7 +391,7 @@ OwnPtr<Command> parse_complex_command(char* argv[])
return command;
}
NonnullOwnPtr<Command> parse_all_commands(char* argv[])
static NonnullOwnPtr<Command> parse_all_commands(char* 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>());
}
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
// 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);

View file

@ -47,7 +47,7 @@
#include <string.h>
#include <unistd.h>
OwnPtr<DebugSession> g_debug_session;
static OwnPtr<DebugSession> g_debug_session;
static bool g_should_output_color = false;
static void handle_sigint(int)
@ -58,7 +58,7 @@ static void handle_sigint(int)
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) {
printf(" ");
@ -66,7 +66,7 @@ void print_function_call(String function_name, size_t depth)
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) {
printf(" ");
@ -83,7 +83,7 @@ void print_syscall(PtraceRegisters& regs, size_t depth)
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
auto instrumented = make<HashMap<void*, X86::Instruction>>();

View file

@ -81,7 +81,7 @@ int main(int argc, char** argv)
return status;
}
bool print_uid_object(uid_t uid)
static bool print_uid_object(uid_t uid)
{
if (flag_print_name) {
struct passwd* pw = getpwuid(uid);
@ -92,7 +92,7 @@ bool print_uid_object(uid_t uid)
return true;
}
bool print_gid_object(gid_t gid)
static bool print_gid_object(gid_t gid)
{
if (flag_print_name) {
struct group* gr = getgrgid(gid);
@ -102,7 +102,7 @@ bool print_gid_object(gid_t gid)
return true;
}
bool print_gid_list()
static bool print_gid_list()
{
int extra_gid_count = getgroups(0, nullptr);
if (extra_gid_count) {
@ -127,7 +127,7 @@ bool print_gid_list()
return true;
}
bool print_full_id_list()
static bool print_full_id_list()
{
uid_t uid = getuid();
@ -159,7 +159,7 @@ bool print_full_id_list()
return true;
}
int print_id_objects()
static int print_id_objects()
{
if (flag_print_uid) {
if (!print_uid_object(getuid()))

View file

@ -38,7 +38,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
String si_bytes(unsigned bytes)
static String si_bytes(unsigned bytes)
{
if (bytes >= GB)
return String::format("%fGiB", (double)bytes / (double)GB);

View file

@ -82,7 +82,7 @@ static String prompt_for_level(int level)
return prompt_builder.build();
}
String read_next_piece()
static String read_next_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());
}
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()) {
printf("\033[34;1m<empty>\033[0m");
@ -292,14 +292,14 @@ static void print(JS::Value value)
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] == '!')
return true;
return false;
}
StringView strip_shebang(AK::ByteBuffer file_contents)
static StringView strip_shebang(AK::ByteBuffer file_contents)
{
size_t i = 0;
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);
}
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);
for (size_t i = 0; i < repl_statements.size(); i++) {
@ -335,7 +335,7 @@ bool write_to_file(const StringView& path)
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 program = parser.parse_program();
@ -443,7 +443,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file)
return JS::Value(true);
}
void repl(JS::Interpreter& interpreter)
static void repl(JS::Interpreter& interpreter)
{
while (!s_fail_repl) {
String piece = read_next_piece();
@ -455,7 +455,7 @@ void repl(JS::Interpreter& interpreter)
}
static Function<void()> interrupt_interpreter;
void sigint_handler()
static void sigint_handler()
{
interrupt_interpreter();
}

View file

@ -137,7 +137,7 @@ int main(int argc, char** argv)
return status;
}
int print_escaped(const char* name)
static int print_escaped(const char* name)
{
int printed = 0;
@ -172,7 +172,7 @@ static String& 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 (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");
}
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)
printf("%08u ", st.st_ino);
@ -318,7 +318,7 @@ bool print_filesystem_object(const String& path, const String& name, const struc
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);
if (di.has_error()) {
@ -383,7 +383,7 @@ int do_file_system_object_long(const char* path)
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;
int rc = lstat(path, &st);

View file

@ -42,7 +42,7 @@ struct OpenFile {
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);
if (file.is_error()) {
@ -69,7 +69,7 @@ Vector<OpenFile> get_open_files_by_pid(pid_t pid)
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());
}

View file

@ -31,7 +31,7 @@
static int key_fd;
void wait_for_key()
static void wait_for_key()
{
printf("\033[7m--[ more ]--\033[0m");
fflush(stdout);

View file

@ -35,7 +35,7 @@
#include <string.h>
#include <unistd.h>
int parse_options(const StringView& options)
static int parse_options(const StringView& options)
{
int flags = 0;
Vector<StringView> parts = options.split_view(',');
@ -60,12 +60,12 @@ int parse_options(const StringView& options)
return flags;
}
bool is_source_none(const char* source)
static bool is_source_none(const char* 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))
return -1;
@ -81,7 +81,7 @@ int get_source_fd(const char* source)
return fd;
}
bool mount_all()
static bool mount_all()
{
// Mount all filesystems listed in /etc/fstab.
dbg() << "Mounting all filesystems...";
@ -139,7 +139,7 @@ bool mount_all()
return all_ok;
}
bool print_mounts()
static bool print_mounts()
{
// Output info about currently mounted filesystems.
auto df = Core::File::construct("/proc/df");

View file

@ -36,7 +36,7 @@
#include <time.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;
auto* w = (const uint16_t*)ptr;

View file

@ -35,7 +35,7 @@
#include <sys/stat.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;
if (lstat(path.characters(), &path_stat) < 0) {

View file

@ -30,7 +30,7 @@
#include <string.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;
double d = strtod(d_string, &end);

View file

@ -30,7 +30,7 @@
#include <string.h>
#include <unistd.h>
void handle_sigint(int)
static void handle_sigint(int)
{
}

View file

@ -36,7 +36,7 @@
#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))
return 1;
@ -62,7 +62,7 @@ int tail_from_pos(Core::File& file, off_t startline, bool want_follow)
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,
// stopping when we've found the number of lines we want.

View file

@ -41,7 +41,7 @@ static int max_depth = INT_MAX;
static int g_directories_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) {
String root_indent_string;

View file

@ -33,7 +33,7 @@
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)
return false;
@ -46,7 +46,7 @@ bool seek_and_read(u8* buffer, const MappedFile& file, off_t seek_to, size_t byt
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;
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;
}
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 {
CFDHCompressionMethodOffset = 10,

View file

@ -42,7 +42,7 @@ static bool flag_beep_on_fail = false;
static volatile int exit_code = 0;
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;
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();
}
struct timeval get_current_time()
static struct timeval get_current_time()
{
struct timespec ts;
struct timeval tv;
@ -61,14 +61,14 @@ struct timeval get_current_time()
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;
timeval_sub(end, start, diff);
return 1000000 * diff.tv_sec + diff.tv_usec;
}
void handle_signal(int signal)
static void handle_signal(int signal)
{
if (child_pid > 0) {
if (kill(child_pid, signal) < 0) {
@ -84,7 +84,7 @@ void handle_signal(int signal)
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))) {
exit_code = 1;

View file

@ -44,7 +44,7 @@ bool output_line = false;
bool output_byte = false;
bool output_word = false;
void wc_out(Count& count)
static void wc_out(Count& count)
{
if (output_line)
printf("%7i ", count.lines);
@ -56,7 +56,7 @@ void wc_out(Count& count)
printf("%14s\n", count.name.characters());
}
Count get_count(const String& file_name)
static Count get_count(const String& file_name)
{
Count count;
FILE* file_pointer = nullptr;
@ -86,7 +86,7 @@ Count get_count(const String& file_name)
return count;
}
Count get_total_count(Vector<Count>& counts)
static Count get_total_count(Vector<Count>& counts)
{
Count total_count { "total" };
for (auto& count : counts) {