{"id":18929171,"url":"https://github.com/jwillikers/strlen","last_synced_at":"2025-04-15T15:30:49.217Z","repository":{"id":104839558,"uuid":"315364454","full_name":"jwillikers/strlen","owner":"jwillikers","description":"A sample implementation of the standard C library’s strlen function","archived":true,"fork":false,"pushed_at":"2024-10-12T14:23:27.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T21:52:14.361Z","etag":null,"topics":["c","cmake","cpp","demo"],"latest_commit_sha":null,"homepage":"https://codeberg.org/jwillikers/strlen","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwillikers.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.adoc","code_of_conduct":"CODE_OF_CONDUCT.adoc","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-23T15:51:09.000Z","updated_at":"2024-10-12T14:24:35.000Z","dependencies_parsed_at":"2023-07-19T22:16:22.331Z","dependency_job_id":null,"html_url":"https://github.com/jwillikers/strlen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwillikers%2Fstrlen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwillikers%2Fstrlen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwillikers%2Fstrlen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwillikers%2Fstrlen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwillikers","download_url":"https://codeload.github.com/jwillikers/strlen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097786,"owners_count":21212352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cmake","cpp","demo"],"created_at":"2024-11-08T11:30:40.797Z","updated_at":"2025-04-15T15:30:49.206Z","avatar_url":"https://github.com/jwillikers.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"= strlen\nJordan Williams \u003cjordan@jwillikers.com\u003e\n:experimental:\n:icons: font\nifdef::env-github[]\n:tip-caption: :bulb:\n:note-caption: :information_source:\n:important-caption: :heavy_exclamation_mark:\n:caution-caption: :fire:\n:warning-caption: :warning:\nendif::[]\n\nA sample implementation of the standard C library's https://en.cppreference.com/w/cpp/string/byte/strlen[`strlen`] function.\n\n== Getting Started\n\nThis sections describes how to setup the build environment required by the project.\nThis project has been tested with the {cpp} compilers from GCC 10 and Clang 11 on https://ubuntu.com/[Ubuntu] 20.10.\nInstall at least one of these compilers with the following commands.\n\nGCC 10::\n+\n[,sh]\n----\nsudo apt -y install gcc g++\n----\n\nClang 11::\n+\n[,sh]\n----\nsudo apt -y install clang-11 lld\n----\n\n=== asdf\n\nThe preferred method of installing build dependencies is with https://asdf-vm.com/[asdf].\nThis ensures that the proper versions of the necessary tools are installed.\nPipenv is used to manage Python tools.\nCombining asdf and Pipenv with https://direnv.net/[direnv] allows automatically configuring and loading a Python virtual environment upon entering the project directory.\n\nThe steps below will create an environment for building the project.\nThese steps assume you are on Ubuntu and familiar with the Linux command-line and https://git-scm.com/[Git].\nInstructions are provided for the https://www.gnu.org/software/bash/[Bash], https://fishshell.com/[fish], and https://www.zsh.org/[ZSH] shells.\n\n. Clone the project's repository from GitHub.\n+\n[,sh]\n----\ngit clone https://codeberg.org/jwillikers/strlen.git\n----\n\n. Change into the project's directory.\n+\n[,sh]\n----\ncd strlen\n----\n\n. Install the dependencies needed for asdf.\n+\n[,sh]\n----\nsudo apt -y install curl git\n----\n\n. Pull down the https://github.com/asdf-vm/asdf[asdf repository] in to your home directory.\n+\n[,sh]\n----\ngit clone https://github.com/asdf-vm/asdf.git ~/.asdf\nCloning into '/home/ubuntu/.asdf'...\nremote: Enumerating objects: 145, done.\nremote: Counting objects: 100% (145/145), done.\nremote: Compressing objects: 100% (85/85), done.\nremote: Total 5782 (delta 76), reused 93 (delta 59), pack-reused 5637\nReceiving objects: 100% (5782/5782), 1.09 MiB | 6.01 MiB/s, done.\nResolving deltas: 100% (3293/3293), done.\n----\n\n. Checkout the latest version of asdf.\n+\n--\n_fish_::\n+\n[,sh]\n----\ngit -C ~/.asdf switch --detach (git -C ~/.asdf describe --abbrev=0 --tags)\nHEAD is now at c6145d0 Update version to 0.8.0\n----\n\n_Bash / ZSH_::\n+\n[source,bash]\n----\ngit -C ~/.asdf switch --detach $(git -C ~/.asdf describe --abbrev=0 --tags)\nHEAD is now at c6145d0 Update version to 0.8.0\n----\n--\n\n. Enable asdf in your shell.\n+\n--\n_fish_::\n+\n[,sh]\n----\nmkdir -p ~/.config/fish/conf.d; and echo \"source ~/.asdf/asdf.fish\" \u003e ~/.config/fish/conf.d/asdf.fish\n----\n\n_Bash_::\n+\n[source,bash]\n----\necho '. $HOME/.asdf/asdf.sh' \u003e\u003e ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\necho '. $HOME/.asdf/asdf.sh' \u003e\u003e ~/.zshrc\n----\n--\n\n. Install shell completions for asdf.\n+\n--\n_fish_::\n+\n[,sh]\n----\nmkdir -p ~/.config/fish/completions; and ln -s ~/.asdf/completions/asdf.fish ~/.config/fish/completions\n----\n\n_Bash_::\n+\n[source,bash]\n----\necho '. $HOME/.asdf/completions/asdf.bash' \u003e\u003e ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\necho -e 'fpath=(${ASDF_DIR}/completions $fpath)\\nautoload -Uz compinit\\ncompinit' \u003e\u003e ~/.zshrc\n----\n--\n\n. Reload fish to make asdf available.\n+\n--\n_fish_::\n+\n[,sh]\n----\nexec fish\n----\n\n_Bash_::\n+\n[source,bash]\n----\nsource ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\nsource ~/.zshrc\n----\n--\n\n. Add the https://github.com/danhper/asdf-python[Python plugin] to asdf.\n+\n[,sh]\n----\nasdf plugin add python\ninitializing plugin repository...\nCloning into '/home/ubuntu/.asdf/repository'...\nremote: Enumerating objects: 2450, done.\nremote: Total 2450 (delta 0), reused 0 (delta 0), pack-reused 2450\nReceiving objects: 100% (2450/2450), 553.27 KiB | 3.57 MiB/s, done.\nResolving deltas: 100% (1140/1140), done.\n----\n\n. Install the necessary dependencies to build Python which are helpfully documented in the https://github.com/pyenv/pyenv/wiki#suggested-build-environment[Pyenv Wiki].\n+\n[,sh]\n----\nsudo apt -y install make build-essential libssl-dev zlib1g-dev libbz2-dev \\\n  libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils \\\n  tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev\n----\n\n. Before installing Pipenv, configure the default _global_ Python version for the user.\n+\n--\nYou can use the system version of Python by default or another version of your choice.\n\nIMPORTANT: Whenever the user's global version of Python is updated, Pipenv must be reinstalled which may require that all virtual environments be rebuilt.\n--\n\n** Use the system's Python as the default.\n\n... Ubuntu installs Python as either `python2` or `python3` on the system.\n+\n--\nThis means that asdf won't be able to detect the system version of python.\nInstall the Python package `python-is-python3` to install a `python` executable for the system which uses `python3`.\n\n[,sh]\n----\nsudo apt -y install python-is-python3\n----\n--\n\n... Install pip and venv because they are not installed by default on Ubuntu.\n+\n[,sh]\n----\nsudo apt -y install python3-pip python3-venv\n----\n\n... Set the user's Python to the system-wide version.\n+\n[,sh]\n----\nasdf global python system\n----\n\n** Or, you can use another version of Python for your user such as the latest and greatest version.\n\n... Build and install the latest version of Python.\n+\n[,sh]\n----\nasdf install python latest\n----\n\n... Set the user's Python to the latest version available at this time.\n+\n--\n_fish_::\n+\n[,sh]\n----\nasdf global python (asdf latest python)\n----\n\n_Bash / ZSH_::\n+\n[source,bash]\n----\nasdf global python $(asdf latest python)\n----\n--\n\n. Install https://pipxproject.github.io/pipx/[pipx] for installing Pipenv in an isolated environment.\n+\n[,sh]\n----\npython -m pip install --user pipx\nCollecting pipx\n  Downloading pipx-0.15.6.0-py3-none-any.whl (43 kB)\n     |████████████████████████████████| 43 kB 636 kB/s\nCollecting argcomplete\u003c2.0,\u003e=1.9.4\n  Downloading argcomplete-1.12.1-py2.py3-none-any.whl (38 kB)\nCollecting packaging\u003e=20.0\n  Downloading packaging-20.4-py2.py3-none-any.whl (37 kB)\nCollecting userpath\u003e=1.4.1\n  Downloading userpath-1.4.1-py2.py3-none-any.whl (14 kB)\nCollecting pyparsing\u003e=2.0.2\n  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)\n     |████████████████████████████████| 67 kB 1.4 MB/s\nRequirement already satisfied: six in /usr/lib/python3/dist-packages (from packaging\u003e=20.0-\u003epipx) (1.14.0)\nRequirement already satisfied: click in /usr/lib/python3/dist-packages (from userpath\u003e=1.4.1-\u003epipx) (7.0)\nRequirement already satisfied: distro; platform_system == \"Linux\" in /usr/lib/python3/dist-packages (from userpath\u003e=1.4.1-\u003epipx) (1.4.0)\nInstalling collected packages: argcomplete, pyparsing, packaging, userpath, pipx\n  WARNING: The script userpath is installed in '/home/ubuntu/.local/bin' which is not on PATH.\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\n  WARNING: The script pipx is installed in '/home/ubuntu/.local/bin' which is not on PATH.\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\nSuccessfully installed argcomplete-1.12.1 packaging-20.4 pipx-0.15.6.0 pyparsing-2.4.7 userpath-1.4.1\n----\n\n. Add the directory where pip installs executables for the local user to `PATH`.\n+\n[,sh]\n----\npython -m pipx ensurepath\nSuccess! Added /home/ubuntu/.local/bin to the PATH environment\n    variable.\n/home/ubuntu/.local/bin has been been added to PATH, but you need to\n    open a new terminal or re-login for this PATH change to take\n    effect.\n\nConsider adding shell completions for pipx. Run 'pipx completions' for\ninstructions.\n\nYou will need to open a new terminal or re-login for the PATH changes\nto take effect.\n\nOtherwise pipx is ready to go! ✨ 🌟 ✨\n----\n\n. To make executables installed by pipx available, reload your shell.\n+\n--\n_fish_::\n+\n[,sh]\n----\nexec fish\n----\n\n_Bash_::\n+\n[source,bash]\n----\nsource ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\nsource ~/.zshrc\n----\n--\n\n. Install Pipenv.\n+\n[,sh]\n----\npython -m pipx install pipenv\n  installed package pipenv 2020.8.13, Python 3.8.5\n  These apps are now globally available\n    - pipenv\n    - pipenv-resolver\ndone! ✨ 🌟 ✨\n----\n\n. Add completions for Pipenv to your shell.\n+\n--\n_fish_::\n+\n[,sh]\n----\necho \"eval (pipenv --completion)\" \u003e ~/.config/fish/completions/pipenv.fish\n----\n\n_Bash_::\n+\n[source,bash]\n----\necho 'eval \"$(pipenv --completion)\"' \u003e\u003e ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\necho 'eval \"$(pipenv --completion)\"' \u003e\u003e ~/.zshrc\n----\n--\n\n. Add the asdf ccache plugin.\n+\n[,sh]\n----\nasdf plugin add ccache\n----\n\n. Add the asdf CMake plugin.\n+\n[,sh]\n----\nasdf plugin add cmake\n----\n\n. Add the asdf direnv plugin.\n+\n[,sh]\n----\nasdf plugin add direnv\n----\n\n. Add the asdf Ninja plugin.\n+\n[,sh]\n----\nasdf plugin add ninja\n----\n\n. Integrate direnv with your shell.\n+\n--\n_fish_::\n+\n[,sh]\n----\nmkdir -p ~/.config/fish/conf.d; \\\n  and echo \"asdf exec direnv hook fish | source\" \u003e ~/.config/fish/conf.d/direnv.fish\n----\n\n_Bash_::\n+\n[source,bash]\n----\necho 'eval \"$(asdf exec direnv hook bash)\"' \u003e\u003e ~/.bashrc\n----\n\n_ZSH_::\n+\n[source,zsh]\n----\necho 'eval \"$(asdf exec direnv hook zsh)\"' \u003e\u003e ~/.zshrc\n----\n--\n\n. Make the asdf feature, i.e. the command `use asdf`, available in direnv.\n+\n--\n_fish_::\n+\n[,sh]\n----\nmkdir -p ~/.config/direnv; \\\n  and echo 'source \"$(asdf direnv hook asdf)\"' \u003e\u003e ~/.config/direnv/direnvrc\n----\n\n_Bash / ZSH_::\n+\n[source,bash]\n----\nmkdir -p ~/.config/direnv; \\\n  echo 'source \"$(asdf direnv hook asdf)\"' \u003e\u003e ~/.config/direnv/direnvrc\n----\n\nNOTE: The `direnvrc` file should only use Bash syntax.\n--\n\n. Install the project's asdf dependencies.\n+\n[,sh]\n----\nasdf install\n----\n\n. Allow direnv to alter the environment for the project directory.\n+\n[,sh]\n----\ndirenv allow\n----\n\n== Build\n\nWhen using a single configuration generator with CMake, set the appropriate build type when configuring the build.\nLikely, this build type will be either _Debug_ or _Release_, both of which are enumerated below in addition to using either GCC 10 or Clang 11.\nThese examples also enable several helpful options to improve performance of the build and the resulting binaries.\nThese examples assume you are in the top-level directory of the project.\n\nRelease::\n+\n--\nConfigure a release build in the aptly named _build_ directory like so.\n\nGCC::\n+\n[,sh]\n----\ncmake \\\n  -GNinja \\\n  -DCMAKE_BUILD_TYPE=Release \\\n  -DCMAKE_UNITY_BUILD=yes \\\n  -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_MODULE_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_SHARED_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=yes \\\n  -B build -S .\n----\n\nClang 11::\n+\n--\n[,sh]\n----\ncmake \\\n  -GNinja \\\n  -DCMAKE_C_COMPILER=/usr/bin/clang-11 \\\n  -DCMAKE_CXX_COMPILER=/usr/bin/clang++-11 \\\n  -DCMAKE_BUILD_TYPE=Release \\\n  -DCMAKE_UNITY_BUILD=yes \\\n  -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_MODULE_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_SHARED_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=yes \\\n  -B build -S .\n----\n\nNOTE: On Ubuntu 20.10, Clang 11 compiler front-ends are installed with the suffix `-11`.\n--\n--\n\nDebug::\n+\n--\nTo build in debug mode, set the build type appropriately, and enable `-gsplit-dwarf` while you're at it.\n\nGCC::\n+\n[,sh]\n----\ncmake \\\n  -GNinja \\\n  -DCMAKE_BUILD_TYPE=Debug \\\n  -DCMAKE_UNITY_BUILD=yes \\\n  -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_MODULE_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_SHARED_LINKER_FLAGS=\"-fuse-ld=gold\" \\\n  -DCMAKE_C_FLAGS_DEBUG=\"-gsplit-dwarf\" \\\n  -DCMAKE_CXX_FLAGS_DEBUG=\"-gsplit-dwarf\" \\\n  -B build -S .\n----\n\nClang 11::\n+\n[,sh]\n----\ncmake \\\n  -GNinja \\\n  -DCMAKE_C_COMPILER=/usr/bin/clang-11 \\\n  -DCMAKE_CXX_COMPILER=/usr/bin/clang++-11 \\\n  -DCMAKE_BUILD_TYPE=Debug \\\n  -DCMAKE_UNITY_BUILD=yes \\\n  -DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_MODULE_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_SHARED_LINKER_FLAGS=\"-fuse-ld=lld\" \\\n  -DCMAKE_C_FLAGS_DEBUG=\"-gsplit-dwarf\" \\\n  -DCMAKE_CXX_FLAGS_DEBUG=\"-gsplit-dwarf\" \\\n  -B build -S .\n----\n--\n\nThen build.\n\n[,sh]\n----\ncmake --build build\n----\n\n=== Google Sanitizers\n\nSupport for Google Sanitizers is provided by the https://github.com/StableCoder/cmake-scripts[cmake-scripts] project.\nSet the `USE_SANITIZER` CMake variable to an appropriate value as documented https://github.com/StableCoder/cmake-scripts#sanitizer-builds-sanitizerscmake[here].\n\nUse the Address sanitizer like so.\n\n[,sh]\n----\ncmake -DUSE_SANITIZER=Address -B build -S .\n----\n\n== Test\n\nUnit tests use https://github.com/boost-ext/ut[[Boost::ext\\].μt] and are written in {cpp}.\nThe unit tests can be run with https://cmake.org/cmake/help/latest/module/CTest.html[CTest].\n\n. Change in to the build directory.\n+\n[,sh]\n----\ncd build\n----\n\n. Run the tests by executing the `ctest` executable.\n\n[,sh]\n----\nctest\n----\n\n== Format\n\nThe https://clang.llvm.org/docs/ClangFormat.html[clang-format] and https://cmake-format.readthedocs.io/en/latest/cmake-format.html[cmake-format] tools are used to format the source code files.\nThe https://github.com/TheLartians/Format.cmake[Format.cmake] module provides build targets to simplify the use of these tools.\n\nFormat the all source files by building the CMake target `fix-format`.\n\n[,sh]\n----\ncmake --build build --target fix-format\n----\n\n== Contributing\n\nContributions in the form of issues, feedback, and even pull requests are welcome.\nMake sure to adhere to the project's link:CODE_OF_CONDUCT.adoc[Code of Conduct].\n\n== Open Source Software\n\nThis project is built on the hard work of countless open source contributors.\nSeveral of these projects are enumerated below.\n\n* https://asciidoctor.org/[Asciidoctor]\n* https://asdf-vm.com/#/[asdf]\n* https://github.com/asdf-community/asdf-direnv[asdf-direnv]\n* https://github.com/boost-ext/ut[[Boost::ext\\].μt]\n* https://ccache.dev/[ccache]\n* https://github.com/TheLartians/Ccache.cmake[Ccache.cmake]\n* https://clang.llvm.org/extra/clang-tidy/[Clang-Tidy]\n* https://clang.llvm.org/docs/ClangFormat.html[ClangFormat]\n* https://cmake.org/[CMake]\n* https://cmake-format.readthedocs.io/en/latest/index.html[cmakelang]\n* https://github.com/StableCoder/cmake-scripts[CMake Scripts]\n* https://direnv.net/[direnv]\n* https://git-scm.com/[Git]\n* https://github.com/TheLartians/ModernCppStarter[ModernCppStarter]\n* https://ninja-build.org/[Ninja]\n* https://rouge.jneen.net/[Rouge]\n* https://www.ruby-lang.org/en/[Ruby]\n\n== Code of Conduct\n\nThe project's Code of Conduct is available in the link:CODE_OF_CONDUCT.adoc[] file.\n\n== License\n\nThis repository is licensed under the https://www.gnu.org/licenses/gpl-3.0.html[GPLv3], available in the link:LICENSE.adoc[] file.\n\n© 2020-2024 Jordan Williams\n\n== Authors\n\nmailto:{email}[{author}]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwillikers%2Fstrlen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwillikers%2Fstrlen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwillikers%2Fstrlen/lists"}