s-httpd

mildly suckless httpd
Log | Files | Refs | README | LICENSE

commit b6f3598ed617b708886c9d690aacd9c10d574ca1
parent fcadb42ac06e502ec8a887901799a2d1ee18d2f2
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Fri, 27 Mar 2026 19:11:42 +0100

cli: Add CLI

Diffstat:
Acli.c | 35+++++++++++++++++++++++++++++++++++
Acli.h | 8++++++++
Ms-httpd | 0
Ms-httpd.c | 18++++++++++++++----
Astate.h | 7+++++++
5 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/cli.c b/cli.c @@ -0,0 +1,35 @@ +/* + * cli.c -- cli + */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> /* for getopt() */ + +#include "cli.h" +#include "state.h" + +void +cli(int argc, char** argv) +{ + int c; + + while ((c = getopt(argc, argv, opts)) != -1) { + switch (c) { + case 'h': + printf("%s: usage: %s [-h] [-v] [-c file]\n", argv[0], argv[0]); + puts("See the s-httpd(8) manual page for more."); + break; + case 'v': + printf("s-httpd version %s\n", VERSION); + break; + case 'c': + strncpy(conffile, optarg, sizeof(conffile) - 1); + optarg[sizeof(conffile) - 1] = '\0'; /* null-terminate */ + + break; + /* getopt() handles the rest :) */ + } + } +} + diff --git a/cli.h b/cli.h @@ -0,0 +1,8 @@ +/* + * cli.h -- cli() and optstring + */ + +const char* opts = "hvc:"; + +void cli(int, char**); + diff --git a/s-httpd b/s-httpd Binary files differ. diff --git a/s-httpd.c b/s-httpd.c @@ -1,7 +1,17 @@ -int main(int argc, char** argv) +/* + * s-httpd.c -- main file + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "cli.h" + +int +main(int argc, char** argv) { - (void)argc; - (void)argv; - return 0; + cli(argc, argv); + + return EXIT_SUCCESS; } diff --git a/state.h b/state.h @@ -0,0 +1,7 @@ +/* + * state.h -- global state + */ + +/** The configuration file */ +char conffile[512]; +