#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
static bool
{
if (flags & (SOL_FD_FLAGS_ERR | SOL_FD_FLAGS_HUP)) {
fprintf(stderr, "ERROR: Something wrong happened with file descriptor: %d\n", fd);
goto err;
}
if (flags & SOL_FD_FLAGS_IN) {
int err;
if (err < 0) {
goto err;
}
puts("no data on stdin, quitting.");
} else {
printf("Now serving %zd bytes:\n--BEGIN--\n%.*s\n--END--\n",
}
}
return true;
err:
return false;
}
static int
{
int r;
};
if (r < 0)
fprintf(stderr, "ERROR: Could not set the 'Content-Type' header\n");
return r;
}
static void
{
static const struct option opts[] = {
{ "port", required_argument, NULL, 'p' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
while ((c = getopt_long(argc, argv, "p:h", opts, &opt_idx)) != -1) {
switch (c) {
case 'p':
port = atoi(optarg);
break;
case 'h':
default:
fprintf(stderr,
"Usage:\n\t%s [-p <port >]\n", argv[0]);
return;
}
}
fprintf(stderr, "ERROR: cannot set stdin to non-block.\n");
goto err_watch;
}
SOL_FD_FLAGS_IN | SOL_FD_FLAGS_HUP | SOL_FD_FLAGS_ERR,
on_stdin, NULL);
fprintf(stderr, "ERROR: Failed to watch stdin\n");
goto err_watch;
}
if (c < 0) {
fprintf(stderr, "ERROR: Failed to set buffer's value\n");
goto err_buffer;
}
});
fprintf(stderr, "ERROR: Failed to create the server\n");
goto err_server;
}
fprintf(stderr, "ERROR: Failed to register the handler\n");
goto err_handler;
}
printf("HTTP server at port %d.\nDefault reply set to '%.*s'\n",
return;
err_handler:
err_server:
err_buffer:
err_watch:
}
static void
{
}