Compare commits

...

22 Commits

Author SHA1 Message Date
Jordan Bancino 5d87da31cd j2s generated code is now C99.
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 12s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 17s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 20s Details
It also no longer requires on the now-defunct Int64.h.
2024-01-13 18:55:31 -05:00
Jordan Bancino 461357b526 Move headers from `src/include` to `include/Cytoplasm`.
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 12s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 12s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 18s Details
This makes it easier to build Cytoplasm as a component of another
program (for example, Telodendria), or as a standalone system library.
2024-01-13 18:40:31 -05:00
Jordan Bancino cd7df7bbb4 Enable higher optimization on fancy compilers.
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 18s Details
2024-01-13 18:22:37 -05:00
Jordan Bancino c489eff517 Set -Wextra on fancy compilers.
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 18s Details
2024-01-13 18:11:44 -05:00
Jordan Bancino 039a487bdf Merge branch 'master' of https://git.telodendria.io/Telodendria/Cytoplasm
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 12s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 12s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 16s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 20s Details
2024-01-13 17:57:31 -05:00
Jordan Bancino 31c9bc7f1c Update Cytoplasm license text for 2024. 2024-01-13 17:56:58 -05:00
Jordan Bancino 11e0a34c02 Update README.md
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 19s Details
2024-01-13 17:49:36 -05:00
Jordan Bancino 08166dd3a7 Don't use `install` because it is not POSIX.
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 18s Details
Closes #13.
2024-01-13 17:26:17 -05:00
Jordan Bancino c3429f035c Update CHANGELOG.md
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 19s Details
2024-01-13 17:18:17 -05:00
Jordan Bancino 662696ce12 C99 Compliance (#29)
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Failing after 8s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Failing after 10s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 9s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 13s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 11s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 14s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 17s Details
This pull request brings Cytoplasm up from C89 to C99, which makes it much more portable across platforms. In particular, this pull request solves a number of issues with 32-bit platforms.

Closes #28.
Closes #12.
Closes #20.

Reviewed-on: #29
2024-01-13 17:13:45 -05:00
Jordan Bancino d0969d0dd7 Add a simple CI workflow for compiling Cytoplasm. (#27)
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Successful in 19s Details
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Successful in 17s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Successful in 17s Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Successful in 16s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Successful in 15s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Successful in 19s Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Successful in 17s Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Successful in 21s Details
This will allow us to pick up compiler warnings from other systems, mainly 32-bit ones. 32-bit systems have different integer sizes that cause all kinds of warnings that we should really address.

Reviewed-on: #27
2024-01-13 11:08:44 -05:00
Jordan Bancino d7da8e0a54 Merge pull request 'Fix potential double-free issue in Cytoplasm' (#22) from lda/Cytoplasm:fix-router-issue into master
Reviewed-on: #22
2024-01-04 19:32:57 -05:00
lda 44b7f45bb7 [FIX] Fix other potential double-free
Was done "à la va-vite" since I can't really work on it directly right now.
2024-01-01 07:57:11 -05:00
lda 3788d044e6
[FIX] Fix potential double-free issue in Cytoplasm 2023-12-14 18:31:20 +01:00
Jordan Bancino 928e9c8223 Update CHANGELOG.md 2023-12-02 10:26:24 -05:00
lda 17f1a41519 `HttpRouter`: Decode path parts before matching. (#19)
Required by Telodendria/Telodendria#44.

Reviewed-on: #19
Co-authored-by: lda <lda@freetards.xyz>
Co-committed-by: lda <lda@freetards.xyz>
2023-12-02 10:25:28 -05:00
Jordan Bancino 29070c8f41 Fix memory leak in code generated by `j2s` code.
Closes #17.
2023-11-20 09:51:08 -05:00
Jordan Bancino bc67393036 Update CHANGELOG.md 2023-11-06 21:28:10 -05:00
Jordan Bancino ba1ac5b42b Add `JsonMerge()`.
Closes #15.
2023-11-06 19:59:46 -05:00
Jordan Bancino 01da37f7d7 Bump version number. 2023-11-06 14:20:42 -05:00
Jordan Bancino 618bcbbac3 `j2s`: Add 'extern' type and ignored fields.
Closes #14.
2023-11-06 14:19:49 -05:00
Jordan Bancino d242597e73 Allow customization of compiler used in configure. 2023-11-04 15:58:23 -04:00
74 changed files with 650 additions and 1805 deletions

View File

@ -0,0 +1,25 @@
name: Compile Cytoplasm
run-name: Compile Cytoplasm on ${{ gitea.actor }}
on: [push]
jobs:
"Compile Cytoplasm":
strategy:
matrix:
os: [debian-v12.4, alpine-v3.19, openbsd-v7.4, freebsd-v14.0, netbsd-v9.3]
arch: [x86, x86_64]
exclude:
# 32-bit OpenBSD does not behave well in QEMU. Even when using
# QEMU to emulate i386, it utilizes 100% of its CPU core and is
# still extremely sluggish. Thus, we don't have a working 32-bit
# OpenBSD runner, so exclude it from the matrix configuration.
- os: openbsd-v7.4
arch: x86
runs-on: ["${{ matrix.os }}", "${{ matrix.arch }}"]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Configure Cytoplasm
run: ./configure
- name: Build Cytoplasm
run: make

View File

@ -5,6 +5,21 @@ Cytoplasm. It is intended to be updated with every commit that makes a user-faci
change worth reporting in the change log. As such, it changes frequently between
releases. Final change log entries are published as [Releases](releases).
## v0.4.1
Cytoplasm is now a C99 library! Upgrading from C89 to C99 makes Cytoplasm more portable
than ever.
### New Features
- Added an option to `j2s` to allow additional fields in structures and ignore them in
encoding and decoding. Note that additional fields are totally untouched&mdash;they
are not even initialized to a default value.
- Fixed a memory leak that would occur in code generated by `j2s` under
specific circumstances.
- Added `JsonMerge()` to the JSON API to merge two JSON objects together.
- Make `HttpRouter` decode path parts before matching them on regular expressions.
## v0.4.0
**Released on November 1, 2023**

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,15 +1,15 @@
<p align="center"><img src="https://telodendria.io/assets/Cytoplasm.png"></p>
<p align="center"><img src="https://telodendria.io/user/themes/bancino/images/logo/Cytoplasm.png"></p>
<h1 align="center">Cytoplasm (<code>libcytoplasm</code>)</h1>
Cytoplasm is a general-purpose C library for creating high-level (particularly networked and multi-threaded) C applications. It allows applications to take advantage of the speed, flexibility, and simplicity of the C programming language, while providing helpful code to allow applications to perform various complex tasks with minimal effort. Cytoplasm provides high-level data structures, a basic logging facility, an HTTP client and server, and more. It also reports memory leaks, which can aid in debugging.
Cytoplasm is a general-purpose C library for creating high-level (particularly networked and multi-threaded) C applications. It allows applications to take advantage of the speed, flexibility, and simplicity of the C programming language, while providing helpful code to allow applications to perform various complex tasks with minimal effort. Cytoplasm provides high-level data structures, a basic logging facility, an HTTP client and server, and more. It also reports memory leaks, which can aid in debugging, particularly on systems that don't have advanced tools like `valgrind`.
Cytoplasm aims not to only do one thing well, but to do many things good enough. This is in contrast to other libraries, which only do one thing and thus require the developer to pull in many different libraries. The primary target of Cytoplasm is simple yet higher level C applications that have to perform relatively complex tasks, but don't want to depend on a large number of dependencies.
Cytoplasm aims not to only do one thing well, but to do many things good enough. This is in contrast to other libraries, which only do one thing and thus require the developer to pull in many different libraries for a broad range of functionality. The primary target of Cytoplasm is simple yet higher level C applications that have to perform relatively complex tasks, but don't want to depend on a large number of dependencies.
Cytoplasm is extremely opinionated on the way programs using it are written. It strives to create a comprehensive and tightly-integrated programming environment, while also maintaining C programming correctness. It doesn't do any macro magic or make C look like anything other than C. It is written entirely in C89, and depends only on a POSIX environment. This differentiates it from other general-purpose libraries that often require modern compilers and non-standard language and environment features. Cytoplasm is intended to be extremely portable and simple, while still providing some of the functionality expected in higher-level programming languages in a platform-agnostic manner. In the case of TLS, Cytoplasm wraps low-level TLS libraries to offer a single, unified interface to TLS so that programs do not have to care about the underlying implementation.
Cytoplasm is extremely opinionated on the way programs using it are written. It strives to create a comprehensive and tightly-integrated programming environment, while also maintaining C programming correctness. It doesn't do any macro magic or make C look like anything other than C. It is written entirely in C99, and depends only on a POSIX environment. This differentiates it from other general-purpose libraries that often require more modern compilers and non-standard language and environment features. Cytoplasm is intended to be extremely portable and simple, while still providing some of the functionality expected in higher-level programming languages in a platform-agnostic manner. In the case of TLS, Cytoplasm wraps low-level TLS libraries to offer a single, unified interface to TLS so that programs do not have to care about the underlying implementation.
Cytoplasm is probably not suitable for embedded programming. It makes liberal use of the heap, and while data structures are designed to conserve memory where possible and practical, minimal memory usage is not really a design goal for Cytoplasm, although Cytoplasm takes care not to use any more memory than it absolutely needs. Cytoplasm also wraps a few standard libraries with additional logic and checking. While this ensures better runtime safety, this inevitably adds a little overhead, which may be unsuitable for time- or space-critical tasks.
Originally a part of Telodendria (https://telodendria.io), a Matrix homeserver written in C, Cytoplasm was split off into its own project due to the desire of some Telodendria developers to use Telodendria's code in other projects. Cytoplasm is still an official Telodendria project, but it is designed specifically to be distributed and used totally independent of Telodendria.
Originally a part of Telodendria ([Website](https://telodendria.io), [Repo](/Telodendria/Telodendria)), a Matrix homeserver written in C, Cytoplasm was split off into its own project due to the desire of some Telodendria developers to use Telodendria's code in other projects. Cytoplasm is still an official Telodendria project, but it is designed specifically to be distributed and used totally independent of Telodendria.
The name "Cytoplasm" was chosen for a few reasons. It plays off the precedent set up by the Matrix organization in naming projects after the parts of a neuron. It also speaks to the function of Cytoplasm. The cytoplasm of a cell is the supporting material. It is what gives the cell its shape, and it facilitates the movement of materials to the other cell parts. Likewise, Cytoplasm aims to provide a support mechanism for C applications that have to perform complex tasks beyond what the C standard library provides.
@ -17,14 +17,7 @@ Cytoplasm also starts with a C, which I think is a nice touch for C libraries. I
## Requirements
Cytoplasm makes the following assumptions about the underlying hardware:
- It has words sizes that are powers of 2, and a native 32-bit integer type exists.
- Integers are represented using two's compliment for negatives.
The ANSI C standard requires an integer type of at least 32 bits, but does not require any more. If Cytoplasm is built on 32-bit platforms that don't provide a native 64-bit integer type, Cytoplasm emulates 64-bit integers. This can make it more portable.
Cytoplasm aims to have zero software dependencies beyond what is mandated by POSIX. You only need the standard math and pthread libraries to build it. TLS support can optionally be enabled with the configuration script. The supported TLS implementations are as follows:
Cytoplasm aims to have zero software dependencies beyond what is mandated by POSIX. You only need a standard C99 compiler, and the standard `math` and `pthread` libraries to build Cytoplasm. TLS support can optionally be enabled with the configuration script. The supported TLS implementations are as follows:
- OpenSSL
- LibreSSL
@ -60,14 +53,11 @@ The `configure` script has a number of optional flags, which are as follows:
- `--with-(openssl|libressl)`: Select the TLS implementation to use. OpenSSL is selected by default.
- `--disable-tls`: Disable TLS altogether.
- `--prefix=<path>`: Set the install prefix to set by default in the `Makefile`. This defaults to `/usr/local`, which should be appropriate for most Unix-like systems.
- `--(enable|disable)-ld-extra`: Control whether or not to enable additional linking flags that create a more optimized binary. For large compilers such as GCC and Clang, these flags should be enabled. However, if you are using a small or more obscure compiler, then these flags may not be supported, so you can disable them with this option.
- `--(enable|disable)-debug`: Control whether or not to enable debug mode. This sets the optimization level to 0 and builds with debug symbols. Useful for running with a debugger.
- `--static` and `--no-static`: Controls whether static binaries for tools are built by default. On BSD systems, `--static` is perfectly acceptable, but on GNU systems, `--no-static` is often desirable to silence warnings about static binaries emitted by the GNU linker.
Cytoplasm can be customized with the following options:
- `--lib-name=<name>`: The output name of the library. This defaults to `Cytoplasm` and should in most cases not be changed.
- `--lib-version=<version>`: The version string to embed in the library binaries. This can be used to indicate build customizations or non-release versions of Cytoplasm.
The following recipes are available in the generated `Makefile`:
@ -96,13 +86,13 @@ Cytoplasm provides the typical .so and .a files, which can be used to link progr
Here is the canonical Hello World written with Cytoplasm:
```c
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Log.h>
int Main(void)
{
Log(LOG_INFO, "Hello World!");
return 0;
}
int Main(void)
{
Log(LOG_INFO, "Hello World!");
return 0;
}
```
If this file is `Hello.c`, then you can compile it by doing this:

115
configure vendored
View File

@ -10,32 +10,64 @@ echo "-------------------"
BUILD="build"
OUT="out"
SRC="src"
INCLUDE="src/include"
INCLUDE="include/Cytoplasm"
TOOLS="tools"
CFLAGS="-Wall -Wextra -pedantic -std=c89 -O3 -pipe -D_DEFAULT_SOURCE -I${INCLUDE}"
LIBS="-lm -pthread"
# Default compiler flags. These must be supported by all POSIX C compilers.
# "Fancy" compilers that have additional options must be detected and set below.
CFLAGS="-O1 -D_DEFAULT_SOURCE -I${INCLUDE}"
LIBS="-lm -lpthread"
# Default args for all platforms.
SCRIPT_ARGS="--prefix=/usr/local --lib-name=Cytoplasm"
# Set default args for all platforms
SCRIPT_ARGS="--prefix=/usr/local --enable-ld-extra --lib-name=Cytoplasm --lib-version=0.4.0 --static $@"
# Set platform specific args
# Set SSL flags depending on the platform.
case "$(uname)" in
OpenBSD)
SCRIPT_ARGS="--with-libressl $SCRIPT_ARGS"
SCRIPT_ARGS="${SCRIPT_ARGS} --with-libressl"
;;
*)
SCRIPT_ARGS="--with-openssl $SCRIPT_ARGS"
SCRIPT_ARGS="${SCRIPT_ARGS} --with-openssl"
;;
esac
# Set compiler depending on the platform.
case "$(uname)" in
Linux|NetBSD)
# These systems typically use GCC.
SCRIPT_ARGS="${SCRIPT_ARGS} --cc=gcc"
;;
OpenBSD|FreeBSD)
# These systems typically use Clang.
SCRIPT_ARGS="${SCRIPT_ARGS} --cc=clang"
;;
*)
# Use default compiler which is required to be present on
# all POSIX-compliant systems.
SCRIPT_ARGS="${SCRIPT_ARGS} --cc=c99"
;;
esac
# Append any additional args specified by user
SCRIPT_ARGS="${SCRIPT_ARGS} $@"
echo "Processing options..."
echo "Ran with arguments: $SCRIPT_ARGS"
# Process all arguments
for arg in $SCRIPT_ARGS; do
case "$arg" in
--cc=*)
CC=$(echo "$arg" | cut -d '=' -f 2-)
case "${CC}" in
gcc*|clang*)
# "Fancy" compilers that support a plethora of additional flags we
# want to enable if present.
CFLAGS="-Wall -Wextra -Werror -pedantic -std=c99 -O3 ${CFLAGS}"
LDFLAGS="-flto -fdata-sections -ffunction-sections -s -Wl,-gc-sections"
;;
esac
;;
--with-openssl)
TLS_IMPL="TLS_OPENSSL"
TLS_LIBS="-lcrypto -lssl"
@ -51,37 +83,17 @@ for arg in $SCRIPT_ARGS; do
--prefix=*)
PREFIX=$(echo "$arg" | cut -d '=' -f 2-)
;;
--enable-ld-extra)
LD_EXTRA="-flto -fdata-sections -ffunction-sections -s -Wl,-gc-sections"
;;
--disable-ld-extra)
LD_EXTRA=""
;;
--lib-name=*)
LIB_NAME=$(echo "$arg" | cut -d '=' -f 2-)
;;
--lib-version=*)
LIB_VERSION=$(echo "$arg" | cut -d '=' -f 2-)
;;
--enable-debug)
DEBUG="-O0 -g"
echo "Notice: --enable-debug implies --disable-ld-extra and --no-static."
echo "You must explicitly provide --enable-ld-extra and/or --static after"
echo "specifying --enable-debug if you wish to enable these features in debug mode."
LD_EXTRA=""
STATIC=""
;;
--disable-debug)
DEBUG=""
;;
--static)
STATIC="-static -Wl,-static"
;;
--no-static)
STATIC=""
;;
*)
echo "Invalid argument: $1"
echo "Invalid argument: $arg"
exit 1
;;
esac
@ -92,8 +104,8 @@ if [ -n "$TLS_IMPL" ]; then
LIBS="${LIBS} ${TLS_LIBS}"
fi
CFLAGS="${CFLAGS} '-DLIB_NAME=\"${LIB_NAME}\"' '-DLIB_VERSION=\"${LIB_VERSION}\"' ${DEBUG}"
LDFLAGS="${LIBS} ${LD_EXTRA}"
CFLAGS="${CFLAGS} '-DLIB_NAME=\"${LIB_NAME}\"' ${DEBUG}"
LDFLAGS="${LIBS} ${LDFLAGS}"
#
# Makefile generation
@ -125,11 +137,27 @@ print_obj() {
printf '%s ' "$2"
}
get_deps() {
src="$1"
${CC} -I${INCLUDE} -E "$src" \
| grep '^#' \
| awk '{print $3}' \
| cut -d '"' -f 2 \
| sort \
| uniq \
| grep -v '^[/<]' \
| grep "^${SRC}/" \
| while IFS= read -r dep; do
printf "%s " "$dep"
done
}
compile_obj() {
src="$1"
obj="$2"
cc -I${INCLUDE} -MM -MT "${obj}" "${src}"
echo "${obj}: $(get_deps ${src})"
echo "${TAB}@mkdir -p $(dirname ${obj})"
echo "${TAB}\$(CC) \$(CFLAGS) -fPIC -c -o \"${obj}\" \"${src}\""
}
@ -140,16 +168,13 @@ compile_bin() {
echo "${out}: ${OUT}/lib/lib${LIB_NAME}.a ${OUT}/lib/lib${LIB_NAME}.so ${src}"
echo "${TAB}@mkdir -p ${OUT}/bin"
echo "${TAB}\$(CC) \$(CFLAGS) -o \"${out}\" \"${src}\" -L${OUT}/lib \$(LDFLAGS) -l${LIB_NAME} ${STATIC}"
echo "${TAB}\$(CC) \$(CFLAGS) -o \"${out}\" \"${src}\" -L${OUT}/lib \$(LDFLAGS) -l${LIB_NAME}"
}
compile_doc() {
src="$1"
out="$2"
if [ -z "${STATIC}" ]; then
pref="LD_LIBRARY_PATH=${OUT}/lib "
fi
pref="LD_LIBRARY_PATH=${OUT}/lib "
echo "${out}: ${OUT}/bin/hdoc ${src}"
echo "${TAB}@mkdir -p ${OUT}/man/man3"
@ -159,22 +184,28 @@ compile_doc() {
install_out() {
src="$1"
out="$2"
dir=$(dirname "$out")
echo "${TAB}install -D \"$src\" \"$out\""
echo "${TAB}mkdir -p \"$dir\""
echo "${TAB}cp \"$src\" \"$out\""
}
install_man() {
src="${OUT}/man/man3/${LIB_NAME}-$(basename $1 .h).3"
out="$2"
dir=$(dirname "$out")
echo "${TAB}install -D \"$src\" \"$out\""
echo "${TAB}mkdir -p \"$dir\""
echo "${TAB}cp \"$src\" \"$out\""
}
install_tool() {
src=${OUT}/bin/$(basename "$1" .c)
out="$2"
dir=$(dirname "$out")
echo "${TAB}install -D \"$src\" \"$out\""
echo "${TAB}mkdir -p \"$dir\""
echo "${TAB}cp \"$src\" \"$out\""
}
uninstall_out() {
@ -195,7 +226,7 @@ cat << EOF > Makefile
# Generated by '$0' on $(date).
# This file should generally not be manually edited.
CC = cc
CC = ${CC}
PREFIX = ${PREFIX}
CFLAGS = ${CFLAGS}
LDFLAGS = ${LDFLAGS}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -52,6 +52,7 @@
#include <stddef.h>
#include <stdarg.h>
#include <stdbool.h>
/**
* The functions in this API operate on an array structure which is
@ -98,7 +99,7 @@ extern void *ArrayGet(Array *, size_t);
* This function returns a boolean value indicating whether or not it
* suceeded.
*/
extern int ArrayInsert(Array *, size_t, void *);
extern bool ArrayInsert(Array *, size_t, void *);
/**
* Set the value at the specified index in the specified array to the
@ -115,7 +116,7 @@ extern void *ArraySet(Array *, size_t, void *);
* return value as
* .Fn ArrayInsert .
*/
extern int ArrayAdd(Array *, void *);
extern bool ArrayAdd(Array *, void *);
/**
* Remove the element at the specified index from the specified array.
@ -146,7 +147,7 @@ extern void ArraySort(Array *, int (*) (void *, void *));
* .P
* This is a relatively expensive operation. The array must first be
* duplicated. Then it is sorted, then it is iterated from beginning
* to end to remove duplicate entires. Note that the comparison
* to end to remove duplicate entries. Note that the comparison
* function is executed on each element at least twice.
*/
extern Array *ArrayUnique(Array *, int (*) (void *, void *));
@ -167,7 +168,7 @@ extern Array *ArrayReverse(Array *);
* array. This function is intended to be used by functions that return
* relatively read-only arrays that will be long-lived.
*/
extern int ArrayTrim(Array *);
extern bool ArrayTrim(Array *);
/**
* Convert a variadic arguments list into an Array. In most cases, the

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -39,6 +39,7 @@
*/
#include <stddef.h>
#include <stdbool.h>
/**
* This function computes the amount of bytes needed to store a message
@ -93,7 +94,7 @@ extern void
* this means it will only fail if a bigger string is necessary, but it
* could not be automatically allocated on the heap.
*/
extern int
extern bool
Base64Pad(char **, size_t);
#endif /* CYTOPLASM_BASE64_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -24,6 +24,8 @@
#ifndef CYTOPLASM_CRON_H
#define CYTOPLASM_CRON_H
#include <stdint.h>
/***
* @Nm Cron
* @Nd Basic periodic job scheduler.
@ -56,8 +58,6 @@
* by any means.
*/
#include "Int.h"
/**
* All functions defined here operate on a structure opaque to the
* caller.
@ -82,7 +82,7 @@ typedef void (JobFunc) (void *);
* .Pp
* This function takes the tick interval in milliseconds.
*/
extern Cron * CronCreate(UInt32);
extern Cron * CronCreate(uint64_t);
/**
* Schedule a one-off job to be executed only at the next tick, and
@ -110,7 +110,7 @@ extern void
* and a pointer to pass to that function when it is executed.
*/
extern void
CronEvery(Cron *, unsigned long, JobFunc *, void *);
CronEvery(Cron *, uint64_t, JobFunc *, void *);
/**
* Start ticking the clock and executing registered jobs.

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -24,6 +24,17 @@
#ifndef CYTOPLASM_CYTOPLASM_H
#define CYTOPLASM_CYTOPLASM_H
#define CYTOPLASM_VERSION_MAJOR 0
#define CYTOPLASM_VERSION_MINOR 4
#define CYTOPLASM_VERSION_PATCH 1
#define CYTOPLASM_VERSION ((CYTOPLASM_VERSION_MAJOR * 10000) + (CYTOPLASM_VERSION_MINOR * 100) + (CYTOPLASM_VERSION_PATCH))
#define CYTOPLASM_VERSION_ALPHA 1
#define CYTOPLASM_VERSION_BETA 0
#define CYTOPLASM_VERSION_STABLE (!CYTOPLASM_VERSION_ALPHA && !CYTOPLASM_VERSION_BETA)
#define STRINGIFY(x) #x
/***
* @Nm Cytoplasm
* @Nd A simple API that provides metadata on the library itself.
@ -34,18 +45,8 @@
* currently loaded library.
*/
/**
* Get the name that this library was compiled with. In most cases,
* this will be hard-coded to "Cytoplasm", but it may differ if, for
* some reason, there exists another ABI-compatible library that
* wishes to report its name.
*
* This function really only exists because the information is
* available along side of the version information so for
* consistency, it made sense to include both.
*/
extern char * CytoplasmGetName(void);
/** */
extern int CytoplasmGetVersion(void);
/**
* Get the library version. This will be useful mostly for printing
@ -55,6 +56,6 @@ extern char * CytoplasmGetName(void);
* This function returns a string, which should usually be able to be
* parsed using sscanf() if absolutely necessary.
*/
extern char * CytoplasmGetVersion(void);
extern const char * CytoplasmGetVersionStr(void);
#endif /* CYTOPLASM_CYTOPLASM_H */
#endif /* CYTOPLASM_CYTOPLASM_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -37,6 +37,7 @@
*/
#include <stddef.h>
#include <stdbool.h>
#include "HashMap.h"
#include "Array.h"
@ -113,7 +114,7 @@ extern DbRef * DbLock(Db *, size_t,...);
* This function assumes the object is not locked, otherwise undefined
* behavior will result.
*/
extern int DbDelete(Db *, size_t,...);
extern bool DbDelete(Db *, size_t,...);
/**
* Unlock an object and return it back to the database. This function
@ -121,7 +122,7 @@ extern int DbDelete(Db *, size_t,...);
* read cache; writes are always immediate to ensure data integrity in
* the event of a system failure.
*/
extern int DbUnlock(Db *, DbRef *);
extern bool DbUnlock(Db *, DbRef *);
/**
* Check the existence of the given database object in a more efficient
@ -130,7 +131,7 @@ extern int DbUnlock(Db *, DbRef *);
* This function does not lock the object, nor does it load it into
* memory if it exists.
*/
extern int DbExists(Db *, size_t,...);
extern bool DbExists(Db *, size_t,...);
/**
* List all of the objects at a given path. Unlike the other varargs
@ -164,6 +165,6 @@ extern HashMap * DbJson(DbRef *);
* replace it with new JSON. This is more efficient than duplicating
* a separate object into the database reference.
*/
extern int DbJsonSet(DbRef *, HashMap *);
extern bool DbJsonSet(DbRef *, HashMap *);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -150,7 +150,7 @@ extern void * HashMapDelete(HashMap *, const char *);
* insertions or deletions occur during the iteration. This
* functionality has not been tested, and will likely not work.
*/
extern int HashMapIterate(HashMap *, char **, void **);
extern bool HashMapIterate(HashMap *, char **, void **);
/**
* A reentrant version of
@ -163,7 +163,7 @@ extern int HashMapIterate(HashMap *, char **, void **);
* .Pp
* The cursor should be initialized to 0 at the start of iteration.
*/
extern int
extern bool
HashMapIterateReentrant(HashMap *, char **, void **, size_t *);
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -74,7 +74,7 @@ extern void HttpRouterFree(HttpRouter *);
* .Pa /some/path/(.*)/parts
* to work as one would expect.
*/
extern int HttpRouterAdd(HttpRouter *, char *, HttpRouteFunc *);
extern bool HttpRouterAdd(HttpRouter *, char *, HttpRouteFunc *);
/**
* Route the specified request path using the specified routing
@ -86,6 +86,6 @@ extern int HttpRouterAdd(HttpRouter *, char *, HttpRouteFunc *);
* how to handle, and the pointer to a void pointer is where the
* route function's response will be placed.
*/
extern int HttpRouterRoute(HttpRouter *, char *, void *, void **);
extern bool HttpRouterRoute(HttpRouter *, char *, void *, void **);
#endif /* CYTOPLASM_HTTPROUTER_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -47,6 +47,7 @@
*/
#include <stdio.h>
#include <stdbool.h>
#include "Http.h"
#include "HashMap.h"
@ -133,7 +134,7 @@ extern void HttpServerFree(HttpServer *);
* caller can continue working while the HTTP server is running in a
* separate thread and managing a pool of threads to handle responses.
*/
extern int HttpServerStart(HttpServer *);
extern bool HttpServerStart(HttpServer *);
/**
* Typically, at some point after calling

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -71,10 +71,10 @@
#include "HashMap.h"
#include "Array.h"
#include "Stream.h"
#include "Int64.h"
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#define JSON_DEFAULT -1
#define JSON_PRETTY 0
@ -152,7 +152,7 @@ extern char * JsonValueAsString(JsonValue *);
* Encode a number as a JSON value that can be added to an object or
* an array.
*/
extern JsonValue * JsonValueInteger(Int64);
extern JsonValue * JsonValueInteger(uint64_t);
/**
* Unwrap a JSON value that represents a number. This function will
@ -160,7 +160,7 @@ extern JsonValue * JsonValueInteger(Int64);
* misleading. Check the type of the value before making assumptions
* about its value.
*/
extern Int64 JsonValueAsInteger(JsonValue *);
extern uint64_t JsonValueAsInteger(JsonValue *);
/**
* Encode a floating point number as a JSON value that can be added
@ -181,7 +181,7 @@ extern double JsonValueAsFloat(JsonValue *);
* expressions as a JSON value that can be added to an object or an
* array.
*/
extern JsonValue * JsonValueBoolean(int);
extern JsonValue * JsonValueBoolean(bool);
/**
* Unwrap a JSON value that represents a boolean. This function will
@ -189,7 +189,7 @@ extern JsonValue * JsonValueBoolean(int);
* misleading. Check the type of the value before making assumptions
* about its type.
*/
extern int JsonValueAsBoolean(JsonValue *);
extern bool JsonValueAsBoolean(JsonValue *);
/**
* This is a special case that represents a JSON null. Because the
@ -253,7 +253,7 @@ extern void JsonFree(HashMap *);
* or if the stream is NULL, the number of bytes that would have
* been written.
*/
extern int JsonEncodeString(const char *, Stream *);
extern size_t JsonEncodeString(const char *, Stream *);
/**
* Serialize a JSON value as it would appear in JSON output. This is
@ -277,7 +277,7 @@ extern int JsonEncodeString(const char *, Stream *);
* or if the stream is NULL, the number of bytes that would have
* been written.
*/
extern int JsonEncodeValue(JsonValue *, Stream *, int);
extern size_t JsonEncodeValue(JsonValue *, Stream *, int);
/**
* Encode a JSON object as it would appear in JSON output, writing it
@ -289,7 +289,7 @@ extern int JsonEncodeValue(JsonValue *, Stream *, int);
* or if the stream is NULL, the number of bytes that would have
* been written.
*/
extern int JsonEncode(HashMap *, Stream *, int);
extern size_t JsonEncode(HashMap *, Stream *, int);
/**
* Decode a JSON object from the given input stream and parse it into
@ -320,4 +320,13 @@ extern JsonValue * JsonGet(HashMap *, size_t,...);
*/
extern JsonValue * JsonSet(HashMap *, JsonValue *, size_t,...);
/**
* Recursively merge two JSON objects. The second object is merged
* on top of the first; any keys present in the first object that are
* also present in the second object are replaced with those in the
* second object, and any keys present in the second object that are
* not present in the first object are copied to the first object.
*/
extern void JsonMerge(HashMap *, HashMap *);
#endif /* CYTOPLASM_JSON_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -76,6 +76,7 @@
* macros.
*/
#include <stddef.h>
#include <stdint.h>
/**
* These values are passed into the memory hook function to indicate

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -46,6 +46,7 @@
*/
#include <stddef.h>
#include <stdbool.h>
/**
* These functions operate on a queue structure that is opaque to the
@ -73,7 +74,7 @@ extern void QueueFree(Queue *);
* value indicating whether or not the push succeeded. Pushing items
* into the queue will fail if the queue is full.
*/
extern int QueuePush(Queue *, void *);
extern bool QueuePush(Queue *, void *);
/**
* Pop an element out of the queue. This function returns NULL if the
@ -95,11 +96,11 @@ extern void * QueuePeek(Queue *);
/**
* Determine whether or not the queue is full.
*/
extern int QueueFull(Queue *);
extern bool QueueFull(Queue *);
/**
* Determine whether or not the queue is empty.
*/
extern int QueueEmpty(Queue *);
extern bool QueueEmpty(Queue *);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -58,11 +58,13 @@
*/
#include <stddef.h>
#include <stdint.h>
/**
* Generate a single random integer between 0 and the passed value.
* Generate a single random 32-bit integer between 0 and the
* passed value.
*/
extern int RandInt(unsigned int);
extern uint32_t RandInt(uint32_t);
/**
* Generate the number of integers specified by the second argument
@ -76,6 +78,6 @@ extern int RandInt(unsigned int);
* has to lock and unlock a mutex. It is therefore better to obtain
* multiple random numbers in one pass if multiple are needed.
*/
extern void RandIntN(int *, size_t, unsigned int);
extern void RandIntN(uint32_t *, size_t, uint32_t);
#endif /* CYTOPLASM_RAND_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -39,21 +39,21 @@
* is a standard library header.
*/
#include "Int.h"
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/**
* Convert UTF-16 into a Unicode codepoint.
*/
extern UInt32 StrUtf16Decode(UInt16, UInt16);
extern uint32_t StrUtf16Decode(uint16_t, uint16_t);
/**
* Take a Unicode codepoint and encode it into a string buffer containing
* between 1 and 4 bytes. The string buffer is allocated on the heap,
* so it should be freed when it is no longer needed.
*/
extern char * StrUtf8Encode(UInt32);
extern char * StrUtf8Encode(uint32_t);
/**
* Duplicate a null-terminated string, returning a new string on the
@ -87,7 +87,7 @@ extern char * StrConcat(size_t,...);
* string consists only of blank characters, as determined by
* .Xr isblank 3 .
*/
extern int StrBlank(const char *str);
extern bool StrBlank(const char *str);
/**
* Generate a string of the specified length, containing random
@ -124,6 +124,6 @@ extern char * StrLower(char *);
* function returns a boolean value indicating whether or not
* strcmp() returned 0.
*/
extern int StrEquals(const char *, const char *);
extern bool StrEquals(const char *, const char *);
#endif /* CYTOPLASM_STR_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -39,6 +39,8 @@
#include "Io.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
/**
* An opaque structure analogous to C's FILE pointers.
@ -172,7 +174,7 @@ extern off_t StreamSeek(Stream *, off_t, int);
* .Xr feof 3
* function.
*/
extern int StreamEof(Stream *);
extern bool StreamEof(Stream *);
/**
* Test the stream for an error condition, returning a boolean value
@ -181,7 +183,7 @@ extern int StreamEof(Stream *);
* .Xr ferror 3
* function.
*/
extern int StreamError(Stream *);
extern bool StreamError(Stream *);
/**
* Clear the error condition associated with the given stream, allowing

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
* Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@ -43,7 +43,6 @@
#include <sys/types.h>
#include "Stream.h"
#include "UInt64.h"
/**
* Get the current timestamp in milliseconds since the Unix epoch. This
@ -61,7 +60,7 @@
* overflow before it even gets to this function, which will cause this
* function to produce unexpected results.
*/
extern UInt64 UtilServerTs(void);
extern uint64_t UtilTsMillis(void);
/**
* Use
@ -70,7 +69,7 @@ extern UInt64 UtilServerTs(void);
* was an error getting the last modified time of a file. This is
* primarily useful for caching file data.
*/
extern UInt64 UtilLastModified(char *);
extern uint64_t UtilLastModified(char *);
/**
* This function behaves just like the system call
@ -86,7 +85,7 @@ extern int UtilMkdir(const char *, const mode_t);
* .Xr nanosleep 2
* to make its usage much, much simpler.
*/
extern int UtilSleepMillis(UInt64);
extern int UtilSleepMillis(uint64_t);
/**
* This function works identically to the POSIX
@ -112,6 +111,6 @@ extern ssize_t UtilGetLine(char **, size_t *, Stream *);
* .Fn pthread_self
* to a number.
*/
extern UInt32 UtilThreadNo(void);
extern uint32_t UtilThreadNo(void);
#endif /* CYTOPLASM_UTIL_H */

View File

@ -1,5 +1,5 @@
/*