diff --git a/kernel/process.cpp b/kernel/process.cpp index c8cb3356..7a493c95 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -1084,7 +1084,7 @@ static size_t shebang_count_arguments(char* line) // as the logic in these files: // * kernel/process.cpp // * libc/unistd/execvpe.c -// * utils/which.cpp +// * utils/which.c // NOTE: See comments in execvpe() for algorithmic commentary. static bool sys_execve_alloc(addralloc_t* alloc, size_t size) diff --git a/libc/unistd/execvpe.c b/libc/unistd/execvpe.c index 1fdfec6b..34d1e185 100644 --- a/libc/unistd/execvpe.c +++ b/libc/unistd/execvpe.c @@ -94,7 +94,7 @@ int execvpe_attempt(const char* filename, // as the logic in these files: // * kernel/process.cpp // * libc/unistd/execvpe.c -// * utils/which.cpp +// * utils/which.c int execvpe(const char* filename, char* const* argv, char* const* envp) { diff --git a/utils/Makefile b/utils/Makefile index 71f031ac..359d0c6a 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -5,10 +5,10 @@ include ../build-aux/version.mak include ../build-aux/dirs.mak OPTLEVEL?=$(DEFAULT_OPTLEVEL) -CXXFLAGS?=$(OPTLEVEL) +CFLAGS?=$(OPTLEVEL) +CFLAGS:=$(CFLAGS) -Wall -Wextra CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\" -CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti BINARIES_EXCEPT_INSTALL:=\ basename \ @@ -80,8 +80,8 @@ install: all install $(BINARIES_EXCEPT_INSTALL) $(DESTDIR)$(BINDIR) install xinstall $(DESTDIR)$(BINDIR)/install -%: %.cpp - $(CXX) -std=gnu++11 $(CPPFLAGS) $(CXXFLAGS) $< -o $@ +%: %.c + $(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) $< -o $@ clean: rm -f $(BINARIES) *.o diff --git a/utils/basename.cpp b/utils/basename.c similarity index 98% rename from utils/basename.cpp rename to utils/basename.c index 3609d51f..56644d5a 100644 --- a/utils/basename.cpp +++ b/utils/basename.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - basename.cpp + basename.c Strip directory and suffix from filenames. *******************************************************************************/ @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -104,7 +105,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'a': multiple = true; break; case 's': diff --git a/utils/cat.cpp b/utils/cat.c similarity index 98% rename from utils/cat.cpp rename to utils/cat.c index 1a02ab57..feff12ad 100644 --- a/utils/cat.cpp +++ b/utils/cat.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - cat.cpp + cat.c Concatenate and print files to the standard output. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -134,7 +135,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'u': /* Ignored, POSIX compatibility. */ break; default: diff --git a/utils/chkblayout.cpp b/utils/chkblayout.c similarity index 98% rename from utils/chkblayout.cpp rename to utils/chkblayout.c index 57cc0153..2d3687fd 100644 --- a/utils/chkblayout.cpp +++ b/utils/chkblayout.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - chkblayout.cpp + chkblayout.c Changes the current keyboard layout. *******************************************************************************/ @@ -79,7 +79,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); diff --git a/utils/chmod.cpp b/utils/chmod.c similarity index 99% rename from utils/chmod.cpp rename to utils/chmod.c index df199898..32fa3dd7 100644 --- a/utils/chmod.cpp +++ b/utils/chmod.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - chmod.cpp + chmod.c Change file mode bits. *******************************************************************************/ @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -360,7 +361,8 @@ int main(int argc, char* argv[]) argv[i] = NULL; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': flags |= FLAG_CHANGES; break; case 'H': symderef = SYMDEREF_ARGUMENTS; break; diff --git a/utils/chroot.cpp b/utils/chroot.c similarity index 98% rename from utils/chroot.cpp rename to utils/chroot.c index 6a077cf0..f1c571ca 100644 --- a/utils/chroot.cpp +++ b/utils/chroot.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - chroot.cpp + chroot.c Runs a process with another root directory. *******************************************************************************/ @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -87,7 +88,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'd': devices = true; break; default: diff --git a/utils/chvideomode.cpp b/utils/chvideomode.c similarity index 95% rename from utils/chvideomode.cpp rename to utils/chvideomode.c index a186f07f..a89e1343 100644 --- a/utils/chvideomode.cpp +++ b/utils/chvideomode.c @@ -15,14 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - chvideomode.cpp + chvideomode.c Menu for changing the screen resolution. *******************************************************************************/ -#define __STDC_CONSTANT_MACROS -#define __STDC_LIMIT_MACROS - #include #include #include @@ -32,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -55,10 +53,11 @@ struct dispmsg_crtc_mode* GetAvailableModes(size_t* num_modes_ptr) msg.msgid = DISPMSG_GET_CRTC_MODES; msg.device = 0; msg.connector = 0; - size_t guess = 0; + size_t guess = 1; while ( true ) { - struct dispmsg_crtc_mode* ret = new struct dispmsg_crtc_mode[guess]; + struct dispmsg_crtc_mode* ret = (struct dispmsg_crtc_mode*) + malloc(sizeof(struct dispmsg_crtc_mode) * guess); if ( !ret ) return NULL; msg.modes_length = guess; @@ -68,7 +67,7 @@ struct dispmsg_crtc_mode* GetAvailableModes(size_t* num_modes_ptr) *num_modes_ptr = guess; return ret; } - delete[] ret; + free(ret); if ( errno == ERANGE && guess < msg.modes_length ) { guess = msg.modes_length; @@ -141,7 +140,7 @@ void filter_modes(struct dispmsg_crtc_mode* modes, size_t* num_modes_ptr, struct *num_modes_ptr = out_num; } -size_t parse_size_t(const char* str, size_t def = 0) +size_t parse_size_t(const char* str, size_t def) { if ( !str || !*str ) return def; @@ -152,7 +151,7 @@ size_t parse_size_t(const char* str, size_t def = 0) return ret; } -bool parse_bool(const char* str, bool def = false) +bool parse_bool(const char* str, bool def) { if ( !str || !*str ) return def; @@ -238,11 +237,11 @@ bool minmax_parameter(const char* option, { const char* parameter; if ( string_parameter(option, arg, argc, argv, ip, argv0, ¶meter) ) - return *min_result = *max_result = parse_size_t(parameter), true; + return *min_result = *max_result = parse_size_t(parameter, 0), true; if ( string_parameter(min_option, arg, argc, argv, ip, argv0, ¶meter) ) - return *min_result = parse_size_t(parameter), true; + return *min_result = parse_size_t(parameter, 0), true; if ( string_parameter(max_option, arg, argc, argv, ip, argv0, ¶meter) ) - return *max_result = parse_size_t(parameter), true; + return *max_result = parse_size_t(parameter, 0), true; return false; } @@ -260,7 +259,7 @@ bool bool_parameter(const char* option, { const char* parameter; if ( string_parameter(option, arg, argc, argv, ip, argv0, ¶meter) ) - return *result = parse_bool(parameter), true; + return *result = parse_bool(parameter, false), true; return false; } @@ -300,7 +299,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); @@ -355,11 +355,14 @@ int main(int argc, char* argv[]) num_modes_display_length++; int mode_set_error = 0; -retry_pick_mode: - size_t selection = 0; - bool decided = false; - bool first_render = true; + size_t selection; + bool decided; + bool first_render; struct wincurpos render_at; +retry_pick_mode: + selection = 0; + decided = false; + first_render = true; memset(&render_at, 0, sizeof(render_at)); while ( !decided ) { diff --git a/utils/clear.cpp b/utils/clear.c similarity index 94% rename from utils/clear.cpp rename to utils/clear.c index be8067ab..0026e154 100644 --- a/utils/clear.cpp +++ b/utils/clear.c @@ -15,14 +15,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - clear.cpp + clear.c Clear the terminal screen. *******************************************************************************/ #include -int main(int /*argc*/, char* /*argv*/[]) +int main(void) { printf("\e[H\e[2J"); fflush(stdout); diff --git a/utils/colormake.cpp b/utils/colormake.c similarity index 93% rename from utils/colormake.cpp rename to utils/colormake.c index 1fdd8b1d..f13c1f36 100644 --- a/utils/colormake.cpp +++ b/utils/colormake.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - colormake.cpp + colormake.c Colors the output of the make program. *******************************************************************************/ @@ -30,13 +30,14 @@ #include #include -const int MODE_NONE = 1; -const int MODE_MAKE = 2; -const int MODE_GCC = 3; -const int MODE_GCC_MSG = 4; +static const int MODE_NONE = 1; +static const int MODE_MAKE = 2; +static const int MODE_GCC = 3; +static const int MODE_GCC_MSG = 4; -int main(int /*argc*/, char* argv[]) +int main(int argc, char* argv[]) { + (void) argc; int pipe_fds[2]; if ( pipe(pipe_fds) ) error(1, errno, "pipe"); diff --git a/utils/column.cpp b/utils/column.c similarity index 99% rename from utils/column.cpp rename to utils/column.c index c8343a4f..ac31502e 100644 --- a/utils/column.cpp +++ b/utils/column.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - column.cpp + column.c Columnate lists. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -194,7 +195,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': { diff --git a/utils/command-not-found.cpp b/utils/command-not-found.c similarity index 99% rename from utils/command-not-found.cpp rename to utils/command-not-found.c index d81f114e..68c18509 100644 --- a/utils/command-not-found.cpp +++ b/utils/command-not-found.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - command-not-found.cpp + command-not-found.c Prints a notice that the attempted command wasn't found and possibly suggests how to install the command or suggests the proper spelling in case of a typo. diff --git a/utils/cp.cpp b/utils/cp.c similarity index 99% rename from utils/cp.cpp rename to utils/cp.c index 8f45ccda..17ade278 100644 --- a/utils/cp.cpp +++ b/utils/cp.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - cp.cpp + cp.c Copy files and directories. *******************************************************************************/ @@ -27,9 +27,10 @@ #include #include #include +#include #include -#include #include +#include #include #include #include @@ -479,7 +480,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { #ifdef CP_PRETEND_TO_BE_INSTALL case 'b': /* ignored */ break; diff --git a/utils/date.cpp b/utils/date.c similarity index 96% rename from utils/date.cpp rename to utils/date.c index 1bc9512b..17c2770b 100644 --- a/utils/date.cpp +++ b/utils/date.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - date.cpp + date.c Print or set system date and time. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -int main(/*int argc, char* argv[]*/) +int main(void) { time_t current_time = time(NULL); diff --git a/utils/df.cpp b/utils/df.c similarity index 99% rename from utils/df.cpp rename to utils/df.c index 2c78c90e..604ea62c 100644 --- a/utils/df.cpp +++ b/utils/df.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - df.cpp + df.c Report free disk space. *******************************************************************************/ @@ -30,12 +30,13 @@ #include #include #include +#include #include #include #include #include -#include #include +#include #include __attribute__((format(printf, 1, 2))) @@ -695,7 +696,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'a': all = true; break; case 'h': format.magformat = MAGFORMAT_HUMAN_READABLE; break; diff --git a/utils/dirname.cpp b/utils/dirname.c similarity index 97% rename from utils/dirname.cpp rename to utils/dirname.c index b640b9b4..0c23a9e1 100644 --- a/utils/dirname.cpp +++ b/utils/dirname.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - dirname.cpp + dirname.c Strip last component from file name. *******************************************************************************/ @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'z': zero = true; break; default: diff --git a/utils/du.cpp b/utils/du.c similarity index 97% rename from utils/du.cpp rename to utils/du.c index d3b77806..0f9ca0f5 100644 --- a/utils/du.cpp +++ b/utils/du.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - du.cpp + du.c Estimate file space usage. *******************************************************************************/ @@ -25,11 +25,12 @@ #include #include +#include #include #include -#include #include #include +#include #include #include #include @@ -144,8 +145,8 @@ bool disk_usage_file_at(int relfd, uintmax_t block_size, uintmax_t* total_bytes_ptr, uintmax_t* num_bytes_ptr, - dev_t expected_dev = 0, - mode_t* result_mode_ptr = NULL) + dev_t expected_dev, + mode_t* result_mode_ptr) { bool flag_all = flags & FLAG_ALL; bool flag_is_operand = flags & FLAG_IS_OPERAND; @@ -196,7 +197,7 @@ bool disk_usage_file_at(int relfd, uintmax_t num_bytes = S_ISBLK(st.st_mode) ? 0 : flags & FLAG_APPARENT_SIZE ? - (uintmax_t) st.st_size : + (intmax_t) st.st_size : st.st_blocks * 512; if ( !S_ISDIR(st.st_mode) ) @@ -340,7 +341,7 @@ bool disk_usage_files(int argc, { if ( !disk_usage_file_at(AT_FDCWD, ".", ".", flags | FLAG_IS_OPERAND, symbolic_dereference, block_size, &total_bytes, - NULL) ) + NULL, 0, NULL) ) success = false; } else for ( int i = 1; i < argc; i++ ) @@ -348,7 +349,7 @@ bool disk_usage_files(int argc, const char* path = argv[i]; if ( !disk_usage_file_at(AT_FDCWD, path, path, flags | FLAG_IS_OPERAND, symbolic_dereference, block_size, &total_bytes, - NULL) ) + NULL, 0, NULL) ) success = false; } @@ -358,7 +359,7 @@ bool disk_usage_files(int argc, return success; } -static uintmax_t get_default_block_size() +static uintmax_t get_default_block_size(void) { uintmax_t result = 0; if ( !result && getenv("DU_BLOCK_SIZE") ) @@ -391,7 +392,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'a': flags |= FLAG_ALL; break; case 'b': flags |= FLAG_APPARENT_SIZE, block_size = 1; break; diff --git a/utils/echo.cpp b/utils/echo.c similarity index 98% rename from utils/echo.cpp rename to utils/echo.c index 193d1e81..71c819ae 100644 --- a/utils/echo.cpp +++ b/utils/echo.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - echo.cpp + echo.c Write arguments to standard output. *******************************************************************************/ diff --git a/utils/env.cpp b/utils/env.c similarity index 98% rename from utils/env.cpp rename to utils/env.c index 7b629df8..c2a73391 100644 --- a/utils/env.cpp +++ b/utils/env.c @@ -15,19 +15,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - env.cpp + env.c Set the environment for command invocation. *******************************************************************************/ #include #include +#include #include #include #include #include -void clean_environment() +void clean_environment(void) { while ( environ[0] ) { @@ -99,7 +100,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'i': ignore_environment = true; break; case 'u': diff --git a/utils/expr.cpp b/utils/expr.c similarity index 97% rename from utils/expr.cpp rename to utils/expr.c index b35b624d..c1502451 100644 --- a/utils/expr.cpp +++ b/utils/expr.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - expr.cpp + expr.c Evaluate expressions. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -60,21 +61,21 @@ char* print_intmax_or_die(intmax_t value) } __attribute__((noreturn)) -void syntax_error() +void syntax_error(void) { error(2, 0, "syntax error"); __builtin_unreachable(); } __attribute__((noreturn)) -void non_integer_argument() +void non_integer_argument(void) { error(2, 0, "non-integer argument"); __builtin_unreachable(); } __attribute__((noreturn)) -void division_by_zero() +void division_by_zero(void) { error(2, 0, "division by zero"); __builtin_unreachable(); @@ -141,8 +142,9 @@ char* bool_to_boolean_value(bool b) char* interpret_literal(char** tokens, size_t num_tokens, - const void* = NULL) + const void* ctx) { + (void) ctx; if ( num_tokens != 1 ) syntax_error(); return strdup_or_die(tokens[0]); @@ -150,13 +152,13 @@ char* interpret_literal(char** tokens, char* interpret_parentheses(char** tokens, size_t num_tokens, - const void* = NULL) + const void* ctx) { if ( 2 <= num_tokens && strcmp(tokens[0], "(") == 0 && strcmp(tokens[num_tokens-1], ")") == 0 ) return interpret(tokens + 1, num_tokens - 2); - return interpret_literal(tokens, num_tokens); + return interpret_literal(tokens, num_tokens, ctx); } char* evaluate_and(const char* a, const char* b) diff --git a/utils/false.cpp b/utils/false.c similarity index 98% rename from utils/false.cpp rename to utils/false.c index d029ffea..a6393f3c 100644 --- a/utils/false.cpp +++ b/utils/false.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - false.cpp + false.c Exit with a status code indicating failure. *******************************************************************************/ diff --git a/utils/find.cpp b/utils/find.c similarity index 99% rename from utils/find.cpp rename to utils/find.c index 0543066f..a33b6bc8 100644 --- a/utils/find.cpp +++ b/utils/find.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - find.cpp + find.c Locate files and directories. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/utils/head.cpp b/utils/head.c similarity index 96% rename from utils/head.cpp rename to utils/head.c index 7bb03c89..a36a6bf6 100644 --- a/utils/head.cpp +++ b/utils/head.c @@ -15,10 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - head.cpp + head.c Output the first part of files. *******************************************************************************/ #define HEAD -#include "tail.cpp" +#include "tail.c" diff --git a/utils/help.cpp b/utils/help.c similarity index 96% rename from utils/help.cpp rename to utils/help.c index 7af880d2..43068ea1 100644 --- a/utils/help.cpp +++ b/utils/help.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - help.cpp + help.c Prints a friendly message and print the names of everything in PATH. *******************************************************************************/ @@ -31,7 +31,7 @@ #include #include -int main(int /*argc*/, char* /*argv*/[]) +int main(void) { printf("Please enter the name of one of the following programs:\n"); @@ -83,7 +83,8 @@ int main(int /*argc*/, char* /*argv*/[]) DIR* dir = opendir(dirname); if ( !dir ) continue; - while ( struct dirent* entry = readdir(dir) ) + struct dirent* entry; + while ( (entry = readdir(dir)) ) { if ( entry->d_name[0] == '.' ) continue; diff --git a/utils/id.cpp b/utils/id.c similarity index 98% rename from utils/id.cpp rename to utils/id.c index 119f333e..3077c810 100644 --- a/utils/id.cpp +++ b/utils/id.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - id.cpp + id.c Return user identity. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -100,7 +101,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'G': groups_only = true; break; case 'g': group_only = true; break; diff --git a/utils/kernelinfo.cpp b/utils/kernelinfo.c similarity index 95% rename from utils/kernelinfo.cpp rename to utils/kernelinfo.c index 35a6e759..fab317cc 100644 --- a/utils/kernelinfo.cpp +++ b/utils/kernelinfo.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - kernelinfo.cpp + kernelinfo.c Prints a kernel information string. *******************************************************************************/ @@ -58,7 +58,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); @@ -83,8 +84,9 @@ int main(int argc, char* argv[]) error(1, errno, "malloc"); for ( int i = 1; i < argc; i++ ) { + ssize_t ret; retry: - ssize_t ret = kernelinfo(argv[i], buf, bufsize); + ret = kernelinfo(argv[i], buf, bufsize); if ( ret < 0 ) { if ( errno == EINVAL ) diff --git a/utils/kill.cpp b/utils/kill.c similarity index 98% rename from utils/kill.cpp rename to utils/kill.c index af037558..5cd7bf4f 100644 --- a/utils/kill.cpp +++ b/utils/kill.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - kill.cpp + kill.c Terminate or signal processes. *******************************************************************************/ @@ -23,11 +23,12 @@ #include #include -#include #include #include #include +#include #include +#include #include #include #include @@ -67,7 +68,7 @@ static const char* signames[128] = }; __attribute__((constructor)) -static void signames_init() +static void signames_init(void) { static char sigrtnames[SIGRTMAX - SIGRTMIN + 1][10]; int rtnum = SIGRTMAX - SIGRTMIN + 1; @@ -192,7 +193,8 @@ int main(int argc, char* argv[]) signal = arg + 1; else if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'l': list = true; break; case 's': diff --git a/utils/ln.cpp b/utils/ln.c similarity index 97% rename from utils/ln.cpp rename to utils/ln.c index 6be2ca45..e2c58c7b 100644 --- a/utils/ln.cpp +++ b/utils/ln.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - ln.cpp + ln.c Create a hard or symbolic link. *******************************************************************************/ @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'f': force = true; break; case 's': symbolic = true; break; diff --git a/utils/ls.cpp b/utils/ls.c similarity index 99% rename from utils/ls.cpp rename to utils/ls.c index cdf5d66f..1e41095c 100644 --- a/utils/ls.cpp +++ b/utils/ls.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - ls.cpp + ls.c Lists directory contents. *******************************************************************************/ @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -915,7 +916,8 @@ int main(int argc, char** argv) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case '1': option_column = false; break; // TODO: Semantics? case 'a': option_all = DOTFILE_ALL; break; diff --git a/utils/memstat.cpp b/utils/memstat.c similarity index 90% rename from utils/memstat.cpp rename to utils/memstat.c index 1d8de9b6..1aa96e32 100644 --- a/utils/memstat.cpp +++ b/utils/memstat.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - memstat.cpp + memstat.c Prints system memory usage information. *******************************************************************************/ @@ -25,16 +25,16 @@ #include #include +#define BYTES 0 +#define KIBI 1 +#define MEBI 2 +#define GIBI 3 +#define TEBI 4 +#define PEBI 5 +#define EXBI 6 + void printbytes(unsigned long long bytes) { - const unsigned BYTES = 0; - const unsigned KIBI = 1; - const unsigned MEBI = 2; - const unsigned GIBI = 3; - const unsigned TEBI = 4; - const unsigned PEBI = 5; - const unsigned EXBI = 6; - unsigned unit = BYTES; if ( (bytes >> 10ULL) & 1023ULL ) { unit = KIBI; } if ( (bytes >> 20ULL) & 1023ULL ) { unit = MEBI; } @@ -63,7 +63,7 @@ void printbytes(unsigned long long bytes) } } -int main(int /*argc*/, char* /*argv*/[]) +int main(void) { size_t memused = 0; size_t memtotal = 0; diff --git a/utils/mkdir.cpp b/utils/mkdir.c similarity index 98% rename from utils/mkdir.cpp rename to utils/mkdir.c index 614b9ac6..90d8a081 100644 --- a/utils/mkdir.cpp +++ b/utils/mkdir.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - mkdir.cpp + mkdir.c Create a directory. *******************************************************************************/ @@ -26,9 +26,10 @@ #include #include #include +#include #include -#include #include +#include #include static bool is_octal_string(const char* str) @@ -247,7 +248,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'm': if ( !*(modespec = arg + 1) ) diff --git a/utils/mktemp.cpp b/utils/mktemp.c similarity index 98% rename from utils/mktemp.cpp rename to utils/mktemp.c index e9d03f90..3b18881f 100644 --- a/utils/mktemp.cpp +++ b/utils/mktemp.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - mktemp.cpp + mktemp.c Create temporary files and directories. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -112,7 +113,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'd': directory = true; break; case 'p': diff --git a/utils/mv.cpp b/utils/mv.c similarity index 98% rename from utils/mv.cpp rename to utils/mv.c index 4828a312..9a122ca2 100644 --- a/utils/mv.cpp +++ b/utils/mv.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - mv.cpp + mv.c Rename files and directories. *******************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -109,7 +110,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'f': flags &= ~FLAG_ASK_OVERWRITE; break; #if 0 diff --git a/utils/pager.cpp b/utils/pager.c similarity index 99% rename from utils/pager.cpp rename to utils/pager.c index 33aa731d..ad89d528 100644 --- a/utils/pager.cpp +++ b/utils/pager.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - pager.cpp + pager.c Displays files one page at a time. *******************************************************************************/ @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -654,7 +655,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'r': pager.flag_raw_control_chars = true; break; case 'R': pager.flag_color_sequences = true; break; diff --git a/utils/passwd.cpp b/utils/passwd.c similarity index 99% rename from utils/passwd.cpp rename to utils/passwd.c index 3abb78c6..dca17019 100644 --- a/utils/passwd.cpp +++ b/utils/passwd.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - passwd.cpp + passwd.c Password change. *******************************************************************************/ @@ -99,7 +99,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': if ( !*(cipher = arg + 1) ) diff --git a/utils/ps.cpp b/utils/ps.c similarity index 98% rename from utils/ps.cpp rename to utils/ps.c index f4c6e737..88f05573 100644 --- a/utils/ps.cpp +++ b/utils/ps.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - ps.cpp + ps.c Lists processes. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'a': select_all = true; break; case 'A': select_all = true; break; diff --git a/utils/pstree.cpp b/utils/pstree.c similarity index 98% rename from utils/pstree.cpp rename to utils/pstree.c index 1fd3a12a..e7805d00 100644 --- a/utils/pstree.cpp +++ b/utils/pstree.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - pstree.cpp + pstree.c Lists processes in a nice tree. *******************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -166,7 +167,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); diff --git a/utils/pwd.cpp b/utils/pwd.c similarity index 95% rename from utils/pwd.cpp rename to utils/pwd.c index 9cf24cab..62c6ce27 100644 --- a/utils/pwd.cpp +++ b/utils/pwd.c @@ -15,13 +15,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - pwd.cpp + pwd.c Prints the current working directory. *******************************************************************************/ #include #include +#include #include #include #include @@ -88,7 +89,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'L': physical = false; break; case 'P': physical = true; break; @@ -116,9 +118,10 @@ int main(int argc, char* argv[]) // The get_current_dir_name function will use the PWD variable if it is // accurate, so we'll need to unset it if it is inappropriate to use it. - if ( const char* pwd = getenv("PWD") ) + const char* pwd_env; + if ( (pwd_env = getenv("PWD")) ) { - if ( physical || !is_path_absolute(pwd) ) + if ( physical || !is_path_absolute(pwd_env) ) unsetenv("PWD"); } diff --git a/utils/realpath.cpp b/utils/realpath.c similarity index 97% rename from utils/realpath.cpp rename to utils/realpath.c index aac2ee93..23bbabc8 100644 --- a/utils/realpath.cpp +++ b/utils/realpath.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - realpath.cpp + realpath.c Canonicalize filesystem paths. *******************************************************************************/ @@ -70,7 +70,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'z': eol = '\0'; default: diff --git a/utils/rm.cpp b/utils/rm.c similarity index 95% rename from utils/rm.cpp rename to utils/rm.c index 119e9ea2..6c899b52 100644 --- a/utils/rm.cpp +++ b/utils/rm.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - rm.cpp + rm.c Remove files or directories. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -87,16 +88,17 @@ bool RemoveRecursively(int dirfd, const char* full, const char* rel, return false; } bool ret = true; - while ( struct dirent* entry = readdir(dir) ) + struct dirent* entry; + while ( (entry = readdir(dir)) ) { const char* name = entry->d_name; if ( strcmp(name, ".") == 0 || strcmp(name, "..") == 0 ) continue; - char* newfull = new char[strlen(full) + 1 + strlen(entry->d_name) + 1]; + char* newfull = (char*) malloc(strlen(full) + 1 + strlen(entry->d_name) + 1); bool addslash = !full[0] || full[strlen(full)-1] != '/'; stpcpy(stpcpy(stpcpy(newfull, full), addslash ? "/" : ""), name); bool ok = RemoveRecursively(targetfd, newfull, name, false, verbose); - delete[] newfull; + free(newfull); rewinddir(dir); if ( !ok ) { ret = false; break; } } @@ -163,7 +165,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'f': force = true; break; case 'r': recursive = true; break; diff --git a/utils/rmdir.cpp b/utils/rmdir.c similarity index 97% rename from utils/rmdir.cpp rename to utils/rmdir.c index 56bcbaa2..58c390b1 100644 --- a/utils/rmdir.cpp +++ b/utils/rmdir.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - rmdir.cpp + rmdir.c Remove an empty directory. *******************************************************************************/ @@ -24,9 +24,10 @@ #include #include +#include #include -#include #include +#include #include #include @@ -73,7 +74,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'p': parents = true; break; case 'v': verbose = true; break; diff --git a/utils/sleep.cpp b/utils/sleep.c similarity index 98% rename from utils/sleep.cpp rename to utils/sleep.c index 5211d7a0..09c0058f 100644 --- a/utils/sleep.cpp +++ b/utils/sleep.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - sleep.cpp + sleep.c Suspend execution for an interval of time. *******************************************************************************/ @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -215,7 +216,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); diff --git a/utils/sort.cpp b/utils/sort.c similarity index 98% rename from utils/sort.cpp rename to utils/sort.c index 9b593d5e..9c23fafd 100644 --- a/utils/sort.cpp +++ b/utils/sort.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - sort.cpp + sort.c Sort, merge, or sequence check text files. *******************************************************************************/ @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -168,7 +169,8 @@ char** read_input_stream_lines(size_t* result_num_lines, size_t lines_used = 0; size_t lines_length = 0; - while ( char* line = read_input_stream_line(is, delim) ) + char* line; + while ( (line = read_input_stream_line(is, delim)) ) { if ( lines_used == lines_length ) { @@ -318,7 +320,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': check = true; break; case 'C': check = check_quiet = false; break; @@ -413,7 +416,7 @@ int main(int argc, char* argv[]) struct input_stream is; memset(&is, 0, sizeof(is)); - is.files = argv + 1; + is.files = (const char* const*) (argv + 1); is.files_current = 0; is.files_length = argc - 1; is.result_status = true; @@ -422,7 +425,8 @@ int main(int argc, char* argv[]) { int needed_relation = unique ? 1 : 0; char* prev_line = NULL; - while ( char* line = read_input_stream_line(&is, delim) ) + char* line; + while ( (line = read_input_stream_line(&is, delim)) ) { if ( prev_line && compare(line, prev_line) < needed_relation ) { diff --git a/utils/stat.cpp b/utils/stat.c similarity index 98% rename from utils/stat.cpp rename to utils/stat.c index e78f27ea..5741c78d 100644 --- a/utils/stat.cpp +++ b/utils/stat.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - stat.cpp + stat.c Display file status. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -165,7 +166,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'L': dereference = true; break; default: diff --git a/utils/tail.cpp b/utils/tail.c similarity index 97% rename from utils/tail.cpp rename to utils/tail.c index 3b964a87..ce9da2c2 100644 --- a/utils/tail.cpp +++ b/utils/tail.c @@ -15,19 +15,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - tail.cpp + tail.c Output the last part of files. *******************************************************************************/ #include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include #ifdef HEAD #define TAIL false @@ -59,10 +60,7 @@ bool processfp(const char* inputname, FILE* fp) char** buffer = NULL; if ( specialtrailing ) - { - buffer = new char*[abslines]; - memset(buffer, 0, sizeof(char*) * abslines); - } + buffer = (char**) calloc(1, sizeof(char*) * abslines); long linenum; for ( linenum = 0; true; linenum++ ) @@ -110,7 +108,7 @@ bool processfp(const char* inputname, FILE* fp) } } - delete[] buffer; + free(buffer); return true; } @@ -158,7 +156,8 @@ int main(int argc, char* argv[]) nlinesstr = arg + 1; else if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'n': if ( !*(nlinesstr = arg + 1) ) diff --git a/utils/time.cpp b/utils/time.c similarity index 99% rename from utils/time.cpp rename to utils/time.c index c3894c62..a0bdcdcb 100644 --- a/utils/time.cpp +++ b/utils/time.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - time.cpp + time.c Measure process running time. *******************************************************************************/ diff --git a/utils/touch.cpp b/utils/touch.c similarity index 99% rename from utils/touch.cpp rename to utils/touch.c index ce9c6beb..d6ee7ce7 100644 --- a/utils/touch.cpp +++ b/utils/touch.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/utils/tr.cpp b/utils/tr.c similarity index 99% rename from utils/tr.cpp rename to utils/tr.c index 1a40cf78..e79fadc3 100644 --- a/utils/tr.cpp +++ b/utils/tr.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - tr.cpp + tr.c Translate, squeeze and/or delete characters. *******************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -540,7 +541,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': flag_complement = true; break; case 'C': flag_complement = true; break; diff --git a/utils/true.cpp b/utils/true.c similarity index 98% rename from utils/true.cpp rename to utils/true.c index 71a78fdc..79e77904 100644 --- a/utils/true.cpp +++ b/utils/true.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - true.cpp + true.c Exit with a status code indicating success. *******************************************************************************/ diff --git a/utils/type.cpp b/utils/type.c similarity index 97% rename from utils/type.cpp rename to utils/type.c index 666619da..82370ab8 100644 --- a/utils/type.cpp +++ b/utils/type.c @@ -15,19 +15,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - type.cpp + type.c Lets you move the tty cursor around and easily issue ANSI escape codes. *******************************************************************************/ #include #include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include static void help(FILE* fp, const char* argv0) { @@ -57,7 +58,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); diff --git a/utils/uname.cpp b/utils/uname.c similarity index 97% rename from utils/uname.cpp rename to utils/uname.c index fd3c8684..b6f34d79 100644 --- a/utils/uname.cpp +++ b/utils/uname.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - uname.cpp + uname.c Print system information. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -90,9 +91,10 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { - case 'a': flags |= LONG_MAX; break; + case 'a': flags |= INT_MAX; break; case 's': flags |= PRINT_KERNELNAME; break; case 'n': flags |= PRINT_NODENAME; break; case 'r': flags |= PRINT_KERNELREL; break; diff --git a/utils/uniq.cpp b/utils/uniq.c similarity index 98% rename from utils/uniq.cpp rename to utils/uniq.c index 82ccd65c..1d384c77 100644 --- a/utils/uniq.cpp +++ b/utils/uniq.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - uniq.cpp + uniq.c Report or filter out repeated lines in a file *******************************************************************************/ @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -126,7 +127,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': count = true; break; case 'd': delete_singulars = true; break; diff --git a/utils/unmount.cpp b/utils/unmount.c similarity index 97% rename from utils/unmount.cpp rename to utils/unmount.c index c5f1a75c..49aa3f7e 100644 --- a/utils/unmount.cpp +++ b/utils/unmount.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - unmount.cpp + unmount.c Unmount a filesystem. *******************************************************************************/ @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -79,7 +80,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'f': force = true; break; case 'l': lazy = true; break; diff --git a/utils/uptime.cpp b/utils/uptime.c similarity index 97% rename from utils/uptime.cpp rename to utils/uptime.c index a613005a..ce7d9617 100644 --- a/utils/uptime.cpp +++ b/utils/uptime.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - uptime.cpp + uptime.c Tell how long the system has been running. *******************************************************************************/ @@ -56,7 +56,7 @@ void PrintElement(size_t num, const char* single, const char* multiple) prefix = ", "; } -int main(int /*argc*/, char* /*argv*/[]) +int main(void) { struct timespec uptime; if ( clock_gettime(CLOCK_BOOT, &uptime) < 0 ) diff --git a/utils/wc.cpp b/utils/wc.c similarity index 95% rename from utils/wc.cpp rename to utils/wc.c index 838219e8..f506e484 100644 --- a/utils/wc.cpp +++ b/utils/wc.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - wc.cpp + wc.c Counts bytes, characters, words and lines. *******************************************************************************/ @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -35,14 +36,13 @@ #include #include -const int FLAG_PRINT_NUM_BYTES = 1 << 0; -const int FLAG_PRINT_NUM_CHARACTERS = 1 << 1; -const int FLAG_PRINT_NUM_WORDS = 1 << 2; -const int FLAG_PRINT_NUM_LINES = 1 << 3; -const int FLAG_PRINT_COMPACT = 1 << 4; +#define FLAG_PRINT_NUM_BYTES (1 << 0) +#define FLAG_PRINT_NUM_CHARACTERS (1 << 1) +#define FLAG_PRINT_NUM_WORDS (1 << 2) +#define FLAG_PRINT_NUM_LINES (1 << 3) +#define FLAG_PRINT_COMPACT (1 << 4) -const int DEFAULT_FLAGS = - FLAG_PRINT_NUM_BYTES | FLAG_PRINT_NUM_WORDS | FLAG_PRINT_NUM_LINES; +#define DEFAULT_FLAGS (FLAG_PRINT_NUM_BYTES | FLAG_PRINT_NUM_WORDS | FLAG_PRINT_NUM_LINES) struct word_count { @@ -257,7 +257,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'c': flags |= FLAG_PRINT_NUM_BYTES; break; case 'l': flags |= FLAG_PRINT_NUM_LINES; break; diff --git a/utils/which.cpp b/utils/which.c similarity index 97% rename from utils/which.cpp rename to utils/which.c index 141bb8e9..eb5e62a7 100644 --- a/utils/which.cpp +++ b/utils/which.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - which.cpp + which.c Locate a program in the PATH. *******************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ // as the logic in these files: // * kernel/process.cpp // * libc/unistd/execvpe.c -// * utils/which.cpp +// * utils/which.c // NOTE: See comments in execvpe() for algorithmic commentary. bool Which(const char* filename, const char* path, bool all) @@ -160,7 +161,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { case 'a': all = true; break; default: diff --git a/utils/xinstall.cpp b/utils/xinstall.c similarity index 96% rename from utils/xinstall.cpp rename to utils/xinstall.c index 27f9605f..cfe150ad 100644 --- a/utils/xinstall.cpp +++ b/utils/xinstall.c @@ -15,10 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - xinstall.cpp + xinstall.c Installs files into system directories. *******************************************************************************/ #define CP_PRETEND_TO_BE_INSTALL -#include "cp.cpp" +#include "cp.c" diff --git a/utils/yes.cpp b/utils/yes.c similarity index 97% rename from utils/yes.cpp rename to utils/yes.c index 4c554165..ded6fe00 100644 --- a/utils/yes.cpp +++ b/utils/yes.c @@ -15,11 +15,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - yes.cpp + yes.c Repeatedly output a line. *******************************************************************************/ +#include #include #include #include @@ -68,7 +69,8 @@ int main(int argc, char* argv[]) break; if ( arg[1] != '-' ) { - while ( char c = *++arg ) switch ( c ) + char c; + while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c);