• Stars
    star
    606
  • Rank 73,958 (Top 2 %)
  • Language
    C
  • License
    Other
  • Created over 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection of miscellaneous portable C snippets.

Portable Snippets

This is a collection of public domain (CC0) code snippets written in C for performing various common tasks which are typically OS, architecture, and/or compiler-dependent. Basically, our goal is to move those annoying preprocessor conditionals from your code to ours.

Modules have no fixed target (such as C89) since that would preclude some functionality; instead, we simply try to provide the widest support we can for each module. If you have a platform which isn't supported for a particular feature but could be, please let us know; we'd be happy to try to work out a way to support it.

Everything is tested continuously with various versions of GCC, Clang, and PGI (on Travis CI), MSVC (on AppVeyor), and Emscripten (on Codefresh):

Travis CI status AppVeyor status Codefresh status

Currently ready-to-use modules include:

  • builtin โ€” use compiler built-ins/intrinsics, or fall back on standard C
  • endian โ€” endianness detection and swapping
  • atomic โ€” common atomic synchronization operations
  • safe-math โ€” overflow-safe integer functions
  • exact-int โ€” exact-width integer types (think <stdint.h>)
  • clock โ€” cross-platform wall clock, CPU time, and monotonic time

There are also modules which may not yet be ready for widespread use, but would benefit greatly from testing:

  • unaligned โ€” fast unaligned loads & stores
  • once โ€” one-time initialization
  • random โ€” random number generation (3 flavors: cryptographic, reproducible, and fast)
  • debug-trap โ€” debugging traps and assertions
  • check โ€” assertion checking

Modules can be used in isolation, though some do work better together, so if you can keep the whole repository together instead of just copying a single file we recommend you do so.

Please don't be shy about filing issues about any of these; if you have problems it's likely others will, as well, so we would like to fix them.

If you have something you would like to contribute, please file an issue or pull request. If you'd like to help out by writing something new, take a look at the "enhancement" issues in our issue tracker for ideas.

Some things don't really fit this repository, so here are a few small-ish projects for doing things portably which you may be interested in:

  • Hedley โ€” macros to enable compiler-specific features which make your code easier to use, harder to misuse, safer, faster, and more portable.
  • parg โ€” Argument parsing similar to getopt/getopt_long. Public domain.
  • TinyCThread โ€” Implements the C11 threads API on top of pthreads and the Windows API. zlib license.
  • win-iconv โ€” Windows implementation of the iconv API (character set conversion).
  • mman-win32 โ€” mman.h (mmap(), etc.) implementation for Windows.

If there is a project you'd like to see added to the list, please file an issue or pull request.

More Repositories

1

hedley

A C/C++ header to help move #ifdefs out of your code
C++
706
star
2

munit

ยตnit is a small testing framework for C
C
579
star
3

configure-cmake

Autotools-style configure script wrapper around CMake
83
star
4

icc-travis

Directions for installing ICC compiler on Travis CI
Shell
49
star
5

vala-extra-vapis

This repository is no longer active; please use https://gitlab.gnome.org/GNOME/vala-extra-vapis instead.
Vala
43
star
6

salieri

Source-code annotation language (SAL) compatibility header
C++
39
star
7

lzo

Unofficial mirror of LZO
C
36
star
8

vala-girs

Collection of GIRs and VAPIs for the Vala toolchain
Vala
28
star
9

liblzf

Git mirror of the liblzf CVS repository.
C
21
star
10

compfuzz

Fuzzing compression libraries
C
19
star
11

gnome-cmake

CMake modules for various GNOME components
CMake
17
star
12

pgi-travis

Install PGI Community Edition on Travis CI
Shell
16
star
13

pre-defined-macros

Lists of pre-defined macros for various C/C++ compilers
C
16
star
14

squash-corpus

Designing a new corpus for lossless general-purpose compression
15
star
15

wav

Type-safe C/C++ API for WASM SIMD.
C
12
star
16

lzjb

LZJB implementation forked from FreeBSD
C
10
star
17

lzmat

git mirror of LZMAT (http://www.matcode.com/lzmat.htm)
C
7
star
18

ftdi-eeprom

Tool for writing to the EEPROM of FTDI devices.
C
6
star
19

bump

Concurrency management for GObject/GIO based projects, especially those written in Vala.
Vala
6
star
20

bzip2

NO LONGER ACTIVE; please use the new official bzip2 repository at https://gitlab.com/federicomenaquintero/bzip2. This was an unofficial mirror of bzip2, including the historical releases I could find.
C
5
star
21

wasm-simd-data

Performance data for WASM SIMD instructions.
C
5
star
22

doboz

git mirror of https://bitbucket.org/attila_afra/doboz
C
5
star
23

sqlheavy

Automatically exported from code.google.com/p/sqlheavy
Vala
4
star
24

nemequ.github.io

HTML
3
star
25

lz4x

An optimized LZ4 compressor
C
3
star
26

attic

Miscellaneous code I don't (yet?) have a better place for but don't want to throw away.
C++
3
star
27

tornado

Unofficial mirror of Tornado
C++
2
star
28

waspr

WebAssembly SIMD Programming Reference
TypeScript
2
star
29

ti-compiler-install-travis

Script to install Texas Instruments' compilers on Travis CI
Shell
2
star
30

safe-math

Portable overflow-safe math. Moved into https://github.com/nemequ/portable-snippets
C
2
star
31

ci-noise

Commits I want to test in CI without generateing noise in other repos. Project will completely change depending on what needs testing.
C
1
star
32

ternarylogic-compiler-test

C++
1
star
33

planet-vala

Configuration for Planet Vala
1
star