Use getopt_long() to reject flags w/usage output

This commit is contained in:
XANTRONIX Development 2020-09-10 20:25:15 -04:00 committed by XANTRONIX Industrial
parent bb118be462
commit cc530fcccc

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -36,6 +37,10 @@ static void usage(int argc, char **argv, const char *message, ...) {
int main(int argc, char **argv) {
patty_client *client;
struct option opts[] = {
{ NULL, 0, NULL, 0 }
};
uint8_t buf[4096];
ssize_t readlen;
@ -45,6 +50,12 @@ int main(int argc, char **argv) {
struct stat st;
int ch;
if ((ch = getopt_long(argc, argv, "", opts, NULL)) >= 0) {
usage(argc, argv, NULL);
}
if (argc < 2) {
usage(argc, argv, "Not enough arguments provided");
}