{"id":20726645,"url":"https://github.com/embeddedartistry/c-linked-list","last_synced_at":"2025-10-15T06:28:34.101Z","repository":{"id":84101212,"uuid":"523428434","full_name":"embeddedartistry/c-linked-list","owner":"embeddedartistry","description":"Header-only Linked List implementation in C","archived":false,"fork":false,"pushed_at":"2023-12-07T21:39:24.000Z","size":75,"stargazers_count":11,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T02:23:12.736Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/embeddedartistry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","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":"2022-08-10T17:02:58.000Z","updated_at":"2025-03-17T18:42:53.000Z","dependencies_parsed_at":"2024-11-22T08:31:10.283Z","dependency_job_id":null,"html_url":"https://github.com/embeddedartistry/c-linked-list","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"embeddedartistry/project-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Fc-linked-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Fc-linked-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Fc-linked-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Fc-linked-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/embeddedartistry","download_url":"https://codeload.github.com/embeddedartistry/c-linked-list/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250493860,"owners_count":21439884,"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":[],"created_at":"2024-11-17T04:26:28.124Z","updated_at":"2025-10-15T06:28:29.067Z","avatar_url":"https://github.com/embeddedartistry.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Header-only Linked List in C\n\nThis is a header-only linked list library written in C.\n\n## Table of Contents\n\n1. [About the Project](#about-the-project)\n2. [Project Status](#project-status)\n3. [Getting Started](#getting-started)\n    1. [Requirements](#requirements)\n        1. [git-lfs](#git-lfs)\n        1. [Meson Build System](#meson-build-system)\n    2. [Getting the Source](#getting-the-source)\n    3. [Building](#building)\n4. [Configuration Options](#configuration-options)\n5. [Documentation](#documentation)\n6. [Need Help?](#need-help)\n7. [Contributing](#contributing)\n8. [Further Reading](#further-reading)\n9. [Authors](#authors)\n10. [License](#license)\n11. [Acknowledgments](#acknowledgements)\n\n# About the Project\n\nThis is a header-only linked list library implemented in C. This code has been carried with me and improved over the years. With some research it seems that the implementation that passed into my hands was based on the Linux Kernel's implementation.\n\nYou can copy this header to your own projects, or you can consume this repository as a Meson subproject. With Meson, the header can be added to the relevant build components with the `c_linked_list_dep` variable.\n\nTo use this library, embed an `ll_t` element in a structure:\n\n```c\ntypedef struct\n{\n    ll_t node;\n    size_t size;\n    char* block;\n} alloc_node_t;\n```\n\nYou then need to declare a linked list variable using the `LIST_INIT` macro:\n\n```c\nLIST_INIT(free_list);\n```\n\nOperations on the list primarily operate through your `ll_t` `struct` element.\n\nTo add a new element to the list, you can use `list_add` (or `list_add_tail`, or `list_insert`) to add the `ll_t` element to the desired list variable.\n\n```c\n// Note the pointer to the node element!\nlist_add(\u0026new_memory_block-\u003enode, \u0026free_list);\n```\n\nRemoving an element only requires the `node` variable:\n\n```c\nlist_del(\u0026found_block-\u003enode);\n```\n\nFunctions for iterating over the list are also provided:\n\n```c\n// Declare a variable to hold a pointer to the current element \n// in the processing loop\nalloc_node_t* current_block = NULL;\n\n// Iterate over each element in the list\n// First param is a variable in your struct type\n// Second param is the list to iterate over\n// Third param is the ll_t element in your struct type.\nlist_for_each_entry(current_block, \u0026free_list, node)\n{\n    // perform an operation on current_block\n}\n```\n\nFull documentation and a complete list of available functions can be found in the `ll.h` file.\n\nFor a full example of this library in action, see [embeddedartistry/libmemory](https://github.com/embeddedartistry/libmemory) and the [\"freelist\" implementation](https://github.com/embeddedartistry/libmemory/blob/master/src/malloc_freelist.c).\n\n**[Back to top](#table-of-contents)**\n\n# Project Status\n\nThis header implementation has been constant for years.\n\nSince the header is now in a standalone repository, I would like to add test cases.\n\n**[Back to top](#table-of-contents)**\n\n## Getting Started\n\n### Requirements\n\nThis project uses [Embedded Artistry's standard Meson build system](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/), and dependencies are described in detail [on our website](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/).\n\nAt a minimum you will need:\n\n* [`git-lfs`](https://git-lfs.github.com), which is used to store binary files in this repository\n* [Meson](#meson-build-system) is the build system\n* Some kind of compiler for your target system.\n    - This repository has been tested with:\n        - gcc-7, gcc-8, gcc-9\n        - arm-none-eabi-gcc\n        - Apple clang\n        - Mainline clang\n\n#### git-lfs\n\nThis project stores some files using [`git-lfs`](https://git-lfs.github.com).\n\nTo install `git-lfs` on Linux:\n\n```\nsudo apt install git-lfs\n```\n\nTo install `git-lfs` on OS X:\n\n```\nbrew install git-lfs\n```\n\nAdditional installation instructions can be found on the [`git-lfs` website](https://git-lfs.github.com).\n\n#### Meson Build System\n\nThe [Meson](https://mesonbuild.com) build system depends on `python3` and `ninja-build`.\n\nTo install on Linux:\n\n```\nsudo apt-get install python3 python3-pip ninja-build\n```\n\nTo install on OSX:\n\n```\nbrew install python3 ninja\n```\n\nMeson can be installed through `pip3`:\n\n```\npip3 install meson\n```\n\nIf you want to install Meson globally on Linux, use:\n\n```\nsudo -H pip3 install meson\n```\n\n**[Back to top](#table-of-contents)**\n\n### Getting the Source\n\nThis project uses [`git-lfs`](https://git-lfs.github.com), so please install it before cloning. If you cloned prior to installing `git-lfs`, simply run `git lfs pull` after installation.\n\nThis project is hosted on GitHub. You can clone the project directly using this command:\n\n```\ngit clone --recursive https://github.com/embeddedartistry/c-linked-list\n```\n\nIf you don't clone recursively, be sure to run the following command in the repository or your build will fail:\n\n```\ngit submodule update --init\n```\n\n**[Back to top](#table-of-contents)**\n\n### Building\n\nIf Make is installed, the library can be built by issuing the following command:\n\n```\nmake\n```\n\nThis will build all targets for your current architecture.\n\nYou can clean builds using:\n\n```\nmake clean\n```\n\nYou can eliminate the generated `buildresults` folder using:\n\n```\nmake distclean\n```\n\nYou can also use  `meson` directly for compiling.\n\nCreate a build output folder:\n\n```\nmeson buildresults\n```\n\nAnd build all targets by running\n\n```\nninja -C buildresults\n```\n\n**Full instructions for working with the build system, including topics like using alternate toolchains and running supporting tooling, are documented in [Embedded Artistry's Standardized Meson Build System](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/) on our website.**\n\n**[Back to top](#table-of-contents)**\n\n## Configuration Options\n\nThe following meson project options can be set for this library when creating the build results directory with `meson`, or by using `meson configure`:\n\n* `disable-builtins` will tell the compiler not to generate built-in function\n* `disable-stack-protection` will tell the compiler not to insert stack protection calls\n* `enable-pedantic`: Turn on `pedantic` warnings\n* `enable-pedantic-error`: Turn on `pedantic` warnings and errors\n\nOptions can be specified using `-D` and the option name:\n\n```\nmeson buildresults -Ddisable-builtins=false\n```\n\nThe same style works with `meson configure`:\n\n```\ncd buildresults\nmeson configure -Ddisable-builtins=false\n```\n\n**[Back to top](#table-of-contents)**\n\n## Documentation\n\nDocumentation can be built locally by running the following command:\n\n```\nmake docs\n```\n\nDocumentation can be found in `buildresults/docs`, and the root page is `index.html`.\n\n**[Back to top](#table-of-contents)**\n\n## Need help?\n\nIf you need further assistance or have any questions, please file a GitHub issue or send us an email using the [Embedded Artistry Contact Form](http://embeddedartistry.com/contact).\n\nYou can also [reach out on Twitter: mbeddedartistry](https://twitter.com/mbeddedartistry/).\n\n## Contributing\n\nIf you are interested in contributing to this project, please read our [contributing guidelines](docs/CONTRIBUTING.md).\n\n## Authors\n\n* **[Phillip Johnston](https://github.com/phillipjohnston)**\n\n## License\n\nCopyright © 2022 Embedded Artistry LLC\n\nSee the [LICENSE](LICENSE) file for licensing details.\n\n**[Back to top](#table-of-contents)**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembeddedartistry%2Fc-linked-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fembeddedartistry%2Fc-linked-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembeddedartistry%2Fc-linked-list/lists"}