aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-02-03 10:54:07 +0000
committerFuwn <[email protected]>2022-02-03 10:54:07 +0000
commit30dd11d0c9654ee890497aa249fca7e4e732fc47 (patch)
tree1dcaa6829dca46bb8ed9d61ad590582b643193a9
parentfeat(viv): implement `VIV_split` for future use (diff)
downloadviv-30dd11d0c9654ee890497aa249fca7e4e732fc47.tar.xz
viv-30dd11d0c9654ee890497aa249fca7e4e732fc47.zip
fix: move to c99
-rw-r--r--README.rst2
-rw-r--r--include/viv/cli.h4
-rw-r--r--include/viv/flag.h2
-rw-r--r--include/viv/ssl.h3
-rw-r--r--include/viv/viv.h4
-rw-r--r--viv/CMakeLists.txt18
-rw-r--r--viv/ssl.c4
-rw-r--r--viv/viv.c19
8 files changed, 42 insertions, 14 deletions
diff --git a/README.rst b/README.rst
index b2b8e2d..420eadc 100644
--- a/README.rst
+++ b/README.rst
@@ -1,7 +1,7 @@
🎀 viv
======
-a toy gemini client written in ansi c (c89).
+a toy gemini client written in ansi c (c99).
nowhere near finished, but it works! (*mostly*).
diff --git a/include/viv/cli.h b/include/viv/cli.h
index 727fa53..3445fcc 100644
--- a/include/viv/cli.h
+++ b/include/viv/cli.h
@@ -8,11 +8,11 @@
#include <stdio.h>
-static const char *CLI_help = "usage: %s [option] <hostname> [port]\n"
+/* static const char *CLI_help = "usage: %s [option] <hostname> [port]\n"
"options:\n"
" -c, --cert print the received certificates\n"
" -h, --help you are here\n"
- " -v, --version print viv's version information\n";
+ " -v, --version print viv's version information\n"; */
typedef enum {
CLI_option_SHOW_CERTS = (1 << 0),
diff --git a/include/viv/flag.h b/include/viv/flag.h
index b52f941..cdd7c16 100644
--- a/include/viv/flag.h
+++ b/include/viv/flag.h
@@ -5,6 +5,8 @@
#ifndef FLAG_H_
#define FLAG_H_
+#define static_assert _Static_assert
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/include/viv/ssl.h b/include/viv/ssl.h
index 6d4ace2..8e11d39 100644
--- a/include/viv/ssl.h
+++ b/include/viv/ssl.h
@@ -6,6 +6,9 @@
#pragma once
+/* https://stackoverflow.com/a/11405862/14452787 */
+#define h_addr h_addr_list[0]
+
#include <openssl/ssl.h>
/* Definitions within this header will be prefixed by VIV_SSL opposed to just
diff --git a/include/viv/viv.h b/include/viv/viv.h
index 82c7583..bbb608c 100644
--- a/include/viv/viv.h
+++ b/include/viv/viv.h
@@ -8,10 +8,12 @@
typedef void(*split_fn)(const char *, int, void *);
-static const char *VIV_version = "1.0.0";
+/* static const char *VIV_version = "1.0.0"; */
int VIV_exit(int, const char *, ...);
/* http://www.martinbroadhurst.com/split-a-string-in-c.html */
void VIV_split(const char *, char, split_fn, void *);
+char *strsep(char **__restrict, const char *__restrict);
+
#endif /* VIV_VIV_H */
diff --git a/viv/CMakeLists.txt b/viv/CMakeLists.txt
index 8437c10..cdafc26 100644
--- a/viv/CMakeLists.txt
+++ b/viv/CMakeLists.txt
@@ -12,26 +12,28 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include
set_target_properties(${PROJECT_NAME} PROPERTIES
CMAKE_C_STANDARD_REQUIRED ON
- CMAKE_C_STANDARD 89
+ CMAKE_C_STANDARD 99
CMAKE_C_EXTENSIONS OFF
)
-add_compile_options(
- -std=c89
- -ansi
+target_compile_options(${PROJECT_NAME} PUBLIC
+ -std=c99
+ # -ansi
-Wall
-Wextra
- -Werror
+ # -Werror=pedantic
-Wno-unused-function
- -pedantic
- -pedantic-errors
+ # -Wpedantic
+ # -pedantic
+ # -pedantic-errors
-march=native
- -03
+ # -03
-D_XOPEN_SOURCE=500
-D_POSIX_C_SOURCE=200112L
-g
-fsanitize=address
)
+target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE
diff --git a/viv/ssl.c b/viv/ssl.c
index 0b4868a..cb8854d 100644
--- a/viv/ssl.c
+++ b/viv/ssl.c
@@ -8,9 +8,11 @@
#include <netdb.h>
#include <openssl/err.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include "viv/log.h"
+#include "viv/viv.h"
VIV_SSL_connection_context VIV_SSL_open_connection(const char **hostname, int port) {
VIV_SSL_connection_context connection_context;
@@ -31,7 +33,7 @@ VIV_SSL_connection_context VIV_SSL_open_connection(const char **hostname, int po
}
connection_context.socket = socket(PF_INET, SOCK_STREAM, 0);
- bzero(&addr, sizeof(addr));
+ memset(&addr, 0, sizeof(addr)); /* bzero(&addr, sizeof(addr)); */
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *(long *)(host->h_addr);
diff --git a/viv/viv.c b/viv/viv.c
index 8759408..33fd427 100644
--- a/viv/viv.c
+++ b/viv/viv.c
@@ -172,7 +172,7 @@ int VIV_exit(int exit_code, const char *format, ...) {
void VIV_split(const char *string, char separator, split_fn function, void *data) {
unsigned int start, stop;
- start, stop = 0;
+ start = 0;
for (stop = 0; string[stop]; ++stop) {
if (string[stop] == separator) {
@@ -183,3 +183,20 @@ void VIV_split(const char *string, char separator, split_fn function, void *data
function(string + start, stop - start, data);
}
+
+/* https://stackoverflow.com/a/58244503/14452787 */
+char *strsep(char **__restrict stringp, const char *__restrict delim) {
+ char *rv = *stringp;
+
+ if (rv) {
+ *stringp += strcspn(*stringp, delim);
+
+ if (**stringp) {
+ *(*stringp)++ = '\0';
+ } else {
+ *stringp = 0;
+ }
+ }
+
+ return rv;
+}