๐ŸŽ€ Toy Gemini Client Written in C99
cli retro gemini gemtext terminal tls lightweight minimal c99 gemini-protocol
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: move to c99

Fuwn 30dd11d0 15722d02

+42 -14
+1 -1
README.rst
··· 1 1 ๐ŸŽ€ viv 2 2 ====== 3 3 4 - a toy gemini client written in ansi c (c89). 4 + a toy gemini client written in ansi c (c99). 5 5 6 6 nowhere near finished, but it works! (*mostly*). 7 7
+2 -2
include/viv/cli.h
··· 8 8 9 9 #include <stdio.h> 10 10 11 - static const char *CLI_help = "usage: %s [option] <hostname> [port]\n" 11 + /* static const char *CLI_help = "usage: %s [option] <hostname> [port]\n" 12 12 "options:\n" 13 13 " -c, --cert print the received certificates\n" 14 14 " -h, --help you are here\n" 15 - " -v, --version print viv's version information\n"; 15 + " -v, --version print viv's version information\n"; */ 16 16 17 17 typedef enum { 18 18 CLI_option_SHOW_CERTS = (1 << 0),
+2
include/viv/flag.h
··· 5 5 #ifndef FLAG_H_ 6 6 #define FLAG_H_ 7 7 8 + #define static_assert _Static_assert 9 + 8 10 #include <assert.h> 9 11 #include <stdio.h> 10 12 #include <stdlib.h>
+3
include/viv/ssl.h
··· 6 6 7 7 #pragma once 8 8 9 + /* https://stackoverflow.com/a/11405862/14452787 */ 10 + #define h_addr h_addr_list[0] 11 + 9 12 #include <openssl/ssl.h> 10 13 11 14 /* Definitions within this header will be prefixed by VIV_SSL opposed to just
+3 -1
include/viv/viv.h
··· 8 8 9 9 typedef void(*split_fn)(const char *, int, void *); 10 10 11 - static const char *VIV_version = "1.0.0"; 11 + /* static const char *VIV_version = "1.0.0"; */ 12 12 13 13 int VIV_exit(int, const char *, ...); 14 14 /* http://www.martinbroadhurst.com/split-a-string-in-c.html */ 15 15 void VIV_split(const char *, char, split_fn, void *); 16 + 17 + char *strsep(char **__restrict, const char *__restrict); 16 18 17 19 #endif /* VIV_VIV_H */
+10 -8
viv/CMakeLists.txt
··· 12 12 13 13 set_target_properties(${PROJECT_NAME} PROPERTIES 14 14 CMAKE_C_STANDARD_REQUIRED ON 15 - CMAKE_C_STANDARD 89 15 + CMAKE_C_STANDARD 99 16 16 CMAKE_C_EXTENSIONS OFF 17 17 ) 18 18 19 - add_compile_options( 20 - -std=c89 21 - -ansi 19 + target_compile_options(${PROJECT_NAME} PUBLIC 20 + -std=c99 21 + # -ansi 22 22 -Wall 23 23 -Wextra 24 - -Werror 24 + # -Werror=pedantic 25 25 -Wno-unused-function 26 - -pedantic 27 - -pedantic-errors 26 + # -Wpedantic 27 + # -pedantic 28 + # -pedantic-errors 28 29 -march=native 29 - -03 30 + # -03 30 31 -D_XOPEN_SOURCE=500 31 32 -D_POSIX_C_SOURCE=200112L 32 33 -g 33 34 -fsanitize=address 34 35 ) 36 + target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address) 35 37 36 38 find_package(OpenSSL REQUIRED) 37 39 target_link_libraries(${PROJECT_NAME} PRIVATE
+3 -1
viv/ssl.c
··· 8 8 #include <netdb.h> 9 9 #include <openssl/err.h> 10 10 #include <string.h> 11 + #include <strings.h> 11 12 #include <unistd.h> 12 13 13 14 #include "viv/log.h" 15 + #include "viv/viv.h" 14 16 15 17 VIV_SSL_connection_context VIV_SSL_open_connection(const char **hostname, int port) { 16 18 VIV_SSL_connection_context connection_context; ··· 31 33 } 32 34 33 35 connection_context.socket = socket(PF_INET, SOCK_STREAM, 0); 34 - bzero(&addr, sizeof(addr)); 36 + memset(&addr, 0, sizeof(addr)); /* bzero(&addr, sizeof(addr)); */ 35 37 addr.sin_family = AF_INET; 36 38 addr.sin_port = htons(port); 37 39 addr.sin_addr.s_addr = *(long *)(host->h_addr);
+18 -1
viv/viv.c
··· 172 172 void VIV_split(const char *string, char separator, split_fn function, void *data) { 173 173 unsigned int start, stop; 174 174 175 - start, stop = 0; 175 + start = 0; 176 176 177 177 for (stop = 0; string[stop]; ++stop) { 178 178 if (string[stop] == separator) { ··· 183 183 184 184 function(string + start, stop - start, data); 185 185 } 186 + 187 + /* https://stackoverflow.com/a/58244503/14452787 */ 188 + char *strsep(char **__restrict stringp, const char *__restrict delim) { 189 + char *rv = *stringp; 190 + 191 + if (rv) { 192 + *stringp += strcspn(*stringp, delim); 193 + 194 + if (**stringp) { 195 + *(*stringp)++ = '\0'; 196 + } else { 197 + *stringp = 0; 198 + } 199 + } 200 + 201 + return rv; 202 + }