Fix linter warnings (#114)

This commit is contained in:
Ozan Tezcan 2023-04-21 00:43:26 +03:00 committed by GitHub
parent 92b5455a2f
commit c2e8d56e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 54 additions and 99 deletions

View File

@ -8,7 +8,7 @@ Portable, stand-alone C libraries and data structures. (C99)
Each folder is stand-alone with a single header/source pair in it. There is no
build for libraries, just copy files you want.
e.g If you want the logger, copy sc_log.h and sc_log.c to your project.
e.g., If you want the logger, copy sc_log.h and sc_log.c to your project.
#### Features

View File

@ -164,14 +164,14 @@ uint64_t sc_buf_size(struct sc_buf *b);
void sc_buf_clear(struct sc_buf *b);
/**
* Compact buf, e.g if bytes in buffer at [3, 20], it will be moved to [0, 17].
* Compact buf, e.g., if bytes in buffer at [3, 9], it will be moved to [0, 6].
* @param buf buf
*/
void sc_buf_compact(struct sc_buf *b);
/**
* Advance read position, useful when you pass underlying array to another
* function which operates on void*. e.g socket write() call.
* function which operates on void*. e.g., socket write() call.
*
* @param buf buf
* @param len len
@ -180,7 +180,7 @@ void sc_buf_mark_read(struct sc_buf *b, uint64_t len);
/**
* Advance read position, useful when you pass underlying array to another
* function which operates on void*. e.g socket read() call.
* function which operates on void*. e.g., socket read() call.
*
* @param buf buf
* @param len len
@ -212,7 +212,7 @@ uint64_t sc_buf_wpos(struct sc_buf *b);
void sc_buf_set_wpos(struct sc_buf *b, uint64_t pos);
/**
* Get address of read position. Useful for e.g : write(fd, sc_buf_rbuf(buf) ..)
* Get address of read position. Useful for: write(fd, sc_buf_rbuf(buf) ..)
*
* @param b buffer
* @return read address
@ -220,7 +220,7 @@ void sc_buf_set_wpos(struct sc_buf *b, uint64_t pos);
void *sc_buf_rbuf(struct sc_buf *b);
/**
* Get address of write position. Useful for e.g : read(fd, sc_buf_wbuf(buf) ..)
* Get address of write position. Useful for: read(fd, sc_buf_wbuf(buf) ..)
*
* @param buf buf
* @return write address
@ -350,7 +350,7 @@ void sc_buf_put_fmt(struct sc_buf *b, const char *fmt, ...);
* Only useful if you want to append strings. It doesn't store string as length
* prefixed string. So, only valid use case is :
*
* e.g
* e.g.,
*
* char tmp[128];
* struct sc_buf buf = sc_buf_wrap(tmp, sizeof(tmp), SC_BUF_REF);

View File

@ -390,7 +390,7 @@ int sc_log_log(enum sc_log_level level, const char *fmt, ...)
int rc = 0;
va_list va;
// Use relaxed atomics to avoid locking cost, e.g DEBUG logs when
// Use relaxed atomics to avoid locking cost, e.g., DEBUG logs when
// level=INFO will get away without any synchronization on most
// platforms.
#ifdef SC_ATOMIC

View File

@ -106,7 +106,7 @@ void sc_log_set_stdout(bool enable);
/**
* Log files will be rotated. Latest logs will always be in the 'current_file'.
* e.g sc_log_set_file("/tmp/log.0.txt", "/tmp/log-latest.txt");
* e.g., sc_log_set_file("/tmp/log.0.txt", "/tmp/log-latest.txt");
* To disable logging into file : sc_log_set_file(NULL, NULL);
*
* @param prev file path for previous log file, 'NULL' to disable
@ -123,7 +123,7 @@ void sc_log_set_callback(void *arg,
int (*cb)(void *arg, enum sc_log_level level,
const char *fmt, va_list va));
// e.g : sc_log_error("Errno : %d, reason : %s", errno, strerror(errno));
// e.g., sc_log_error("Errno : %d, reason : %s", errno, strerror(errno));
#define sc_log_debug(...) (sc_log_log(SC_LOG_DEBUG, sc_log_ap(__VA_ARGS__, "")))
#define sc_log_info(...) (sc_log_log(SC_LOG_INFO, sc_log_ap(__VA_ARGS__, "")))
#define sc_log_warn(...) (sc_log_log(SC_LOG_WARN, sc_log_ap(__VA_ARGS__, "")))

View File

@ -75,9 +75,9 @@ struct sc_mmap {
*
* @param m mmap
* @param name file name
* @param file_flags flags for open(), e.g : O_RDWR | O_CREAT
* @param prot prot flags, e.g : PROT_READ | PROT_WRITE
* @param map_flags mmap flags, e.g : MAP_SHARED
* @param file_flags flags for open(), e.g., O_RDWR | O_CREAT
* @param prot prot flags, e.g., PROT_READ | PROT_WRITE
* @param map_flags mmap flags, e.g., MAP_SHARED
* @param offset offset
* @param len len
* @return '0' on success, negative on failure,

View File

@ -93,8 +93,6 @@ void test3(void)
void test4(void)
{
char *value;
int argc = 2;
char *argv[] = {"program", "key=value"};
struct sc_option opt = {.argv = argv,
@ -102,16 +100,8 @@ void test4(void)
sizeof(struct sc_option_item),
.options = options};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case '?':
break;
default:
assert(false);
break;
}
}
char c = sc_option_at(&opt, 1, &value);
assert(c == '?');
}
static struct sc_option_item options2[] = {{.letter = 's', .name = "sadsa"},
@ -121,8 +111,6 @@ static struct sc_option_item options2[] = {{.letter = 's', .name = "sadsa"},
void test5(void)
{
char *value;
int argc = 2;
char *argv[] = {"program", "--key=value"};
struct sc_option opt = {.argv = argv,
@ -130,22 +118,13 @@ void test5(void)
sizeof(struct sc_option_item),
.options = options2};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case '?':
break;
default:
assert(false);
break;
}
}
char c = sc_option_at(&opt, 1, &value);
assert(c == '?');
}
void test6(void)
{
char *value;
int argc = 2;
char *argv[] = {"program", "-s"};
struct sc_option opt = {.argv = argv,
@ -153,22 +132,13 @@ void test6(void)
sizeof(struct sc_option_item),
.options = options};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case 's':
break;
default:
assert(false);
break;
}
}
char c = sc_option_at(&opt, 1, &value);
assert(c == 's');
}
void test7(void)
{
char *value;
int argc = 2;
char *argv[] = {"program", "-j"};
struct sc_option opt = {.argv = argv,
@ -176,22 +146,13 @@ void test7(void)
sizeof(struct sc_option_item),
.options = options};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case '?':
break;
default:
assert(false);
break;
}
}
char c = sc_option_at(&opt, 1, &value);
assert(c == '?');
}
void test8(void)
{
char *value;
int argc = 2;
char *argv[] = {"program", "-sx"};
struct sc_option opt = {.argv = argv,
@ -199,16 +160,8 @@ void test8(void)
sizeof(struct sc_option_item),
.options = options};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case '?':
break;
default:
assert(false);
break;
}
}
char c = sc_option_at(&opt, 1, &value);
assert(c == '?');
}
int main(void)

View File

@ -53,7 +53,7 @@ struct sc_option {
* @param opt Already initialized sc_opt struct
* @param index Index for argv
* @param value [out] Value for the option if exists. It should be after '='
* sign. E.g : -key=value or -k=value. If value does not exists
* sign. e.g., -key=value or -k=value. If value does not exists
* (*value) will point to '\0' character. It won't be NULL itself.
*
* To check if option has value associated : if (*value != '\0')

View File

@ -48,7 +48,7 @@ struct sc_rand {
/**
* Pseudo random number generator - RC4
* e.g :
* e.g.,
* char buf[256], tmp1[16], tmp2[4];
*
* int fd = open("/dev/urandom", O_RDONLY);
@ -88,7 +88,7 @@ bool sc_is_pow2(uint64_t num);
uint64_t sc_to_pow2(uint64_t size);
/**
* Bytes to human readable form, e.g 1024 bytes to "1 KB".
* Bytes to human readable form, e.g., 1024 bytes to "1 KB".
*
* @param buf buf to write output
* @param len buf len
@ -98,7 +98,7 @@ uint64_t sc_to_pow2(uint64_t size);
char *sc_bytes_to_size(char *buf, size_t len, uint64_t val);
/**
* Human readable string to bytes, e.g "1 KB" to 1024 bytes.
* Human readable string to bytes, e.g., "1 KB" to 1024 bytes.
*
* @param buf buf to write output
* @return positive value on success, '-1' on error

View File

@ -27,13 +27,13 @@ void test1(void)
assert(sc_is_pow2(1) == true);
assert(sc_is_pow2(3) == false);
x = sc_to_pow2(0);
x = (int64_t) sc_to_pow2(0);
assert(x == 1);
assert(sc_is_pow2(x) == true);
x = sc_to_pow2(1);
x = (int64_t) sc_to_pow2(1);
assert(x == 1);
assert(sc_is_pow2(x) == true);
x = sc_to_pow2(1023);
x = (int64_t) sc_to_pow2(1023);
assert(x == 1024);
assert(sc_is_pow2(x) == true);

View File

@ -39,12 +39,12 @@
#define SC_SIGNAL_VERSION "2.0.0"
/**
* Set shutdown fd here. When shutdown signal is received e.g SIGINT, SIGTERM.
* Set shutdown fd here. When shutdown signal is received e.g., SIGINT, SIGTERM.
* Signal handler will write 1 byte to shutdown fd. So, your app can detect
* shutdown command received and shutdown properly (Assuming you observe this fd
* with select() like function). Before app shutdowns, if another shutdown
* signal is received, _Exit() is called without waiting.
* e.g CTRL+C to shutdown, twice CTRL+C means 'I don't want to wait anything'.
* e.g., CTRL+C to shutdown, twice CTRL+C means 'I don't want to wait anything'.
*/
#if defined(_WIN32)
#include <WinSock2.h>

View File

@ -1,4 +1,4 @@
### Socket and networking for Linux, BSDs, MacOS and Windows
### Socket and networking for Linux, BSDs, macOS and Windows
### Overview

View File

@ -255,7 +255,7 @@ void sc_sock_print(struct sc_sock *s, char *buf, size_t len);
/**
* Linux only. Helper function make your application a daemon with systemd.
* e.g
* e.g.,
* sc_sock_notify_systemd("READY=1\n"); // Tell systemd app started
* sc_sock_notify_systemd("STATUS=doing work\n"); // Tell systemd app doing sth
* sc_sock_notify_systemd("STOPPING=1\n") ; // Tell systemd app will stop
@ -425,7 +425,7 @@ int sc_sock_poll_del(struct sc_sock_poll *p, struct sc_sock_fd *fdt,
enum sc_sock_ev events, void *data);
/**
* e.g
* e.g.,
* int n = sc_sock_poll_wait(poll, 100);
* for (int i = 0; i < n; i++) {
* void *user_data = sc_sock_poll_data(poll, i);

View File

@ -2,7 +2,7 @@
Length prefixed C strings, length is at the start of the allocated memory
e.g :
e.g.,
-----------------------------------------------
| 0 | 0 | 0 | 4 | 'T' | 'E' | 'S' | 'T' | '\0'|
-----------------------------------------------
@ -13,7 +13,7 @@ Length prefixed C strings, length is at the start of the allocated memory
### Pros
- User gets a null terminated `char*`, so it still works with c style string
functions, e.g printf, strcmp.
functions, e.g., printf, strcmp.
- This implementation is mostly about avoiding strlen() cost.
Provides a few more functions to make easier create/append/trim/substring
operations.

View File

@ -39,7 +39,7 @@
/**
* String with 'length' at the start of the allocated memory
* e.g :
* e.g.,
* -----------------------------------------------
* | 0 | 0 | 0 | 4 | 'T' | 'E' | 'S' | 'T' | '\0'|
* -----------------------------------------------

View File

@ -48,7 +48,7 @@
/**
* length prefixed C strings, length is at the start of the allocated memory
* e.g :
* e.g.,
* -----------------------------------------------
* | 0 | 0 | 0 | 4 | 'T' | 'E' | 'S' | 'T' | '\0'|
* -----------------------------------------------
@ -173,7 +173,7 @@ bool sc_str_replace(char **str, const char *rep, const char *with);
* but it is temporary. On each 'sc_str_token_begin' call, this function will
* place '\0' character at the end of a token and put delimiter at the end of
* the 'str'.
* e.g user1-user2\0 after first iteration will be user1\0user2-
* e.g., user1-user2\0 after first iteration will be user1\0user2-
*
* sc_str_token_end() will fix original string if necessary.
*

View File

@ -85,7 +85,8 @@ void sc_timer_clear(struct sc_timer *t);
* Add timer
* 'timeout' is relative to latest 'timestamp' value given to the 'timer'.
*
* e.g sc_timer_init(&timer, 1000); // Current timestamp is 1000.
* e.g.,
* sc_timer_init(&timer, 1000); // Current timestamp is 1000.
* sc_timer_add(&timer, arg, 10); // Timeout will be at 1010.
* sc_timer_timeout(&timer, 2000, arg, callback); // Timestamp is now 2000.
* sc_timer_add(&timer, arg, 10); // Timeout will be at 2010.
@ -93,7 +94,7 @@ void sc_timer_clear(struct sc_timer *t);
*
* @param t timer
* @param timeout timeout value, this is relative to 'sc_timer_init's timer.
* e.g sc_timer_init(&timer, 10); // say, start time is 10
* e.g., sc_timer_init(&timer, 10); // say, start time is 10
* milliseconds
* @param data user data to pass into callback on 'sc_timer_timeout' call.
* @param type user data to pass into callback on 'sc_timer_timeout' call.
@ -117,7 +118,8 @@ void sc_timer_cancel(struct sc_timer *t, uint64_t *id);
*
* Logical pattern is :
*
* e.g:
* e.g.,
*
* struct sc_timer timer;
* sc_timer_init(&timer, time_ms());
* sc_timer_add(&timer, data, 100);

View File

@ -51,8 +51,8 @@ void sleep_ms(uint64_t milliseconds)
int rc;
struct timespec t;
t.tv_sec = milliseconds / 1000;
t.tv_nsec = (milliseconds % 1000) * 1000000;
t.tv_sec = (time_t) milliseconds / 1000;
t.tv_nsec = (time_t) (milliseconds % 1000) * 1000000;
do {
rc = nanosleep(&t, NULL);
@ -96,7 +96,7 @@ void test1(void)
if (count == 0) {
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}
@ -120,7 +120,7 @@ void test1(void)
if (count == 0) {
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}
@ -153,7 +153,7 @@ void test2(void)
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}
@ -175,7 +175,7 @@ void test2(void)
if (count == 0) {
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}
@ -216,7 +216,7 @@ void test3(void)
if (count == 0) {
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}
@ -259,7 +259,7 @@ void test4(void)
if (count == 0) {
break;
}
t -= n;
t -= (int) n;
sleep_ms(n);
}

View File

@ -82,7 +82,7 @@ struct sc_uri {
* Internally, it does a single allocation but each part is also represented as
* NULL ended string.
*
* E.g :
* e.g.,
*
* struct sc_uri* uri;
*