aboutsummaryrefslogtreecommitdiff
path: root/core (follow)
Commit message (Collapse)AuthorAgeFilesLines
* core/ed.c: Prototype printUsage and print_errorRunxi Yu2024-07-271-2/+2
| | | | | | | | | print_error() was declared as "void print_error();" but defined with parameters "const char *error, int help_mode". Declarations without prototypes are unsupported. printUsage also gains "void" as its prototype in this commit, just to be explicit.
* core/touch.c: Set _XOPEN_SOURCE to 700Runxi Yu2024-07-271-1/+1
| | | | See feature_test_macros(7)
* core/ls.c: Cast before printfRunxi Yu2024-07-271-2/+2
| | | | | | Some of these types cannot assumed to be unsigned long, etc. Those type differences cause build failures on OpenBSD. This commit casts them properly.
* core/more.c: Initialize read_file = 1 and success = 0Runxi Yu2024-07-271-2/+1
| | | | | | | | | success is always set anyway, so moving it up is simply a matter of code style. read_file could be uninitalized when used, which leads to UB. Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/tail.c: Initialize *file to NULL, and lines to 10Runxi Yu2024-07-271-5/+2
| | | | | | | | | | C doesn't initialize uninitalized variables to a "zero value" by default. if (!lines) lines = 10; wouldn't work if lines contains garbage values (which it almost always does). Kinda similar for file. Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/touch.c: Fix param loop condition, and print usage on unknown flagsRunxi Yu2024-07-271-2/+6
| | | | | | | | i < 256 && (param[i] = 0) as a loop condition doesn't work because the value of assignments is the rvalue, which means that the loop will not run. Initialization using a for loop should be unnecessary anyway. Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/ed.c: Initialize filedes to -1Runxi Yu2024-07-271-4/+4
| | | | Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/tail.c: Initialize "files_lines"Runxi Yu2024-07-271-1/+1
| | | | | | | | file_lines used to be uninitialized, which causes UB whenever file_lines++ is used; nothing happens before that so it's not even an edge case. Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/basename.c: Initialize "status"Runxi Yu2024-07-271-1/+1
| | | | | | | | "status" used to be uninitialized when the if (argc == 3 ...) block is entered. If strlen(argv[2]) is 0, i.e. if argv[2] is an empty string, undefined behavior occurs. Signed-off-by: Runxi Yu <me@runxiyu.org>
* ln: Count arguments after parsing optionsRunxi Yu2024-07-251-5/+5
| | | | | | | | | Previously, argc is always expected to be 3 (program name, source, destination), without regard for any arguments. This check was done before parsing options, so effectively, the usage of any options would cause the check to fail. This commit causes argument counting to happen after options parsing.
* basename: handle empty argumentsRunxi Yu2024-07-251-1/+7
| | | | | | | | | | | | check that the suffix is non-empty: If strlen(argv[2]) < 1, the for loop would not run, and the status would be uninitialized. This commit causes the suffix to be ignored if it is empty. print empty line when input name is empty: If basename(3) receives an empty string or a null pointer, it returns the string ".", but we want basename(1) to just output an empty line when the input is empty.
* core/cmp: exit loop on EOF rather than null bytesRunxi Yu2024-07-251-4/+2
| | | | Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/cmp: compare fgetc to EOF and use int not charRunxi Yu2024-07-251-2/+3
| | | | | | | | | | | | | | | | Thie solves: box_tmp/cmp_box.c: In function ‘cmp_main’: box_tmp/cmp_box.c:41:25: error: comparison is always false due to limited range of data type [-Werror=type-limits] 41 | if (ch1 == EOF || ch2 == EOF) { | ^~ box_tmp/cmp_box.c:41:39: error: comparison is always false due to limited range of data type [-Werror=type-limits] 41 | if (ch1 == EOF || ch2 == EOF) { | ^~ cc1: all warnings being treated as errors make: *** [Makefile:42: box] Error 1 Signed-off-by: Runxi Yu <me@runxiyu.org>
* core/: tputFerass El Hafidi2023-04-141-0/+40
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/tty: fix compiler errorFerass El Hafidi2023-04-111-1/+2
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/wc: rewind(file) won't work with stdinFerass El Hafidi2023-04-101-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* treewide: readd copyrightsFerass El Hafidi2023-04-1030-0/+95
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: return errnoFerass El Hafidi2023-04-091-2/+1
| | | | | Reported-by: Leah Rowe <leah@libreboot.org> Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: only support 2 arguments (not counting argv[0] before getopt())Ferass El Hafidi2023-04-091-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: get rid of useless for loopFerass El Hafidi2023-04-091-15/+13
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/utilities.csv: remove, not neededFerass El Hafidi2023-04-091-2/+0
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/: get rid of viFerass El Hafidi2023-04-081-210/+0
| | | | | | | It's poorly implemented and ugly, it segfaults and doesn't compile with -Werr. The time is now! Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: fix error handling!Ferass El Hafidi2023-04-081-3/+3
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: don't use *paramsFerass El Hafidi2023-04-081-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: get rid of *params, uselessFerass El Hafidi2023-04-081-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: handle errors when calling remove()Ferass El Hafidi2023-04-081-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* */Makefile: reduce duplicationFerass El Hafidi2023-04-081-20/+2
| | | | | | | Both core/Makefile and extras/Makefile were almost identical. This commit unifies the identical parts in one file. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/Makefile: remove test suiteFerass El Hafidi2023-04-081-17/+0
| | | | | | It's useless Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/uname: fix argument parsingFerass El Hafidi2023-03-311-2/+2
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/rm: argv[0] -> argv0 (typo)Ferass El Hafidi2023-03-311-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/more: don't exit on EOFFerass El Hafidi2023-03-312-4/+2
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ln: TODO -- fix error handlingFerass El Hafidi2023-03-312-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/chown: fix argv handlingFerass El Hafidi2023-03-301-6/+5
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/*: Return errprint.Ferass El Hafidi2023-03-0413-13/+29
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/touch: Add missing 'return 0'Ferass El Hafidi2023-03-041-0/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/: touchFerass El Hafidi2023-03-041-0/+81
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/Makefile: Remove shell built-in utilsFerass El Hafidi2023-03-041-1/+1
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/head: Properly handle standard inputFerass El Hafidi2023-03-041-12/+9
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/head: Fix a tiny typo (that introduced a bug) and a segmentation faultFerass El Hafidi2023-03-031-2/+2
| | | | | | | | | | | | | | | | | | | | Those bugs were basically introduced by typos... First bug --------- `head` was checking if argc was less than 2, which is incorrect because after getopt() is ran, argc would be equal to 1 if ran this way: $ head file As such, it would read standard input, then the file, which is a bug. Second bug ---------- The file got closed after the first line was read. When trying to read the (now closed) file it returns a segmentation fault. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/[: Check argv[0], don't use basename()Ferass El Hafidi2023-03-031-2/+1
| | | | | | | | | | | | | | | POSIX says this: > Applications using the exec() family of functions to execute > these utilities shall ensure that the argument passed in arg0 > or argv[0] is '[' when executing the [ utility and has a > basename of "test" when executing the test utility. Which basically means (in pseudo-code if you will): if argv[0] is "[" -> behave like the POSIX [ else -> behave like the POSIX test [ used to compare with the basename of argv[0], which is POSIXly incorrect. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/[: Use lstat() instead of stat()Ferass El Hafidi2023-03-021-1/+1
| | | | | | | That fixes a bug where [/test always returns 1 when used with `-L` or `-h`. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/wc: Fix bug -- see descriptionFerass El Hafidi2023-03-021-1/+1
| | | | | | | | wc used to always return 'total %d %d %d %s\n' (in pseudo-printf here) regardless of if one or multiple files were specified. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/cat: Fix bug - see descriptionFerass El Hafidi2023-03-021-1/+2
| | | | | | | | | | | | `cat` used to not concatenate at all when ran like this: $ cat It did read standard input, but did not output anything to standard output. fdopen() was used on STDIN_FILENO when it shouldn't. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/uname: Fix argument parsingFerass El Hafidi2023-03-011-11/+7
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/: teeFerass El Hafidi2023-02-271-0/+53
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/: cmpFerass El Hafidi2023-02-211-0/+54
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/: ttyFerass El Hafidi2023-02-191-0/+21
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* all: use SPDX identifiers and add a new MAINTAINERS file.Ferass El Hafidi2023-02-1627-750/+27
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/ls: Use OPERANDS instead of (char *)params in getopt() and remove the ↵Ferass El Hafidi2023-01-281-8/+2
| | | | | | -R option. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
* core/common.*: Move them somewhere else so they can be used by non-POSIX utilsFerass El Hafidi2023-01-1123-142/+56
| | | | Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>