replacing with strcmp && Adding comments && adding helper when the command don't exist

This commit is contained in:
Lluciocc 2026-05-13 09:17:08 +02:00
parent 69d5f8feff
commit 29e1b362ff

View file

@ -5,17 +5,12 @@
#include "stdlib.h" #include "stdlib.h"
#include "syscall.h" #include "syscall.h"
// CMDLINE_MAX includes the trailing NUL, so at most 511 command-line bytes can
// be reconstructed here. Unchecked concatenation can overflow CMDLINE_MAX; all
// command-line construction in this file must go through the checked append
// helpers below.
#define CMDLINE_MAX 512 #define CMDLINE_MAX 512
static int sc_strcmp(const char *a, const char *b) {
while (*a && *a == *b) {
a++;
b++;
}
return (unsigned char)*a - (unsigned char)*b;
}
static int has_slash(const char *s) { static int has_slash(const char *s) {
while (s && *s) { while (s && *s) {
if (*s == '/') if (*s == '/')
@ -37,7 +32,7 @@ static int ends_with_elf(const char *s) {
if (len < 4) if (len < 4)
return 0; return 0;
return sc_strcmp(s + len - 4, ".elf") == 0; return strcmp(s + len - 4, ".elf") == 0;
} }
static void print_usage(void) { static void print_usage(void) {
@ -113,8 +108,8 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
if (sc_strcmp(argv[1], "-h") == 0 || if (strcmp(argv[1], "-h") == 0 ||
sc_strcmp(argv[1], "--help") == 0) { strcmp(argv[1], "--help") == 0) {
print_usage(); print_usage();
return 0; return 0;
} }
@ -135,7 +130,15 @@ int main(int argc, char **argv) {
printf("\n"); printf("\n");
printf("Command: %s\n", cmdline); printf("Command: %s\n", cmdline);
printf("Exit code: %d\n", ret); printf("Exit code: %d\n", ret);
if (ret == -1) {
printf("Command failed with non-zero exit code, not reporting time.\n");
return ret;
}
printf("Elapsed: %llu ms\n", elapsed); printf("Elapsed: %llu ms\n", elapsed);
sys_system(SYSTEM_CMD_SLEEP, 1, 0, 0, 0);
return ret; return ret;
} }