d_snprintf 1.1.1

Port of C99-snprintf

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

This is a port of Holger Weiß' implementation of snprintf (available at http://www.jhweiss.de/software/snprintf.html). This version has no dependencies on other external libraries or the C standard library. It does use D's TypeInfo inorder to access varargs in a typesafe and convenient manner. All Code is nothrow and @nogc. BetteC: If D's TypeInfo ist not available the code will now use an opaque hash to identify types.

This library defines snprintf and vsnprintf as well as a few templates that allow you to easely define a version of (v)asprinf, (v)fprintf and (v)printf that use a specific function to allocate memory or write to a file. An example using C standard library functions (see d_snprintf/test.d):

import d_snprintf;
import core.stdc.stdio : FILE, stdout, fwrite;
import core.stdc.stdlib : malloc;

void write_file(void* p_file, ubyte[] data) {
    fwrite(data.ptr, 1, data.length, cast(FILE*)p_file);

void* alloc_func(size_t size) { // wrapper with D calling convention
    return malloc(size);

alias asprintf = rpl_asprintf!alloc_func;
alias vasprintf = rpl_vasprintf!alloc_func;

int fprintf(A...)(FILE* file, string format, A a) {
    mixin va_start!a;
    return rpl_vfprintf!write_file(cast(void*)file, format, va_args);

int vfprintf(FILE* file, string format, va_list ap) {
    return rpl_vfprintf!write_file(cast(void*)file, format, ap);

int printf(A...)(string format, A a) {
    mixin va_start!a;
    return rpl_vfprintf!write_file(cast(void*)stdout, format, va_args);

int vprintf(string format, va_list ap) {
    return rpl_vfprintf!write_file(cast(void*)stdout, format, ap);

You can define the version-flag "SNPRINTF_TEST" to test this version of snprintf against the C version of your system.

  • Kyto
1.1.1 2021-Jun-16
1.1.0 2021-Jan-17
1.0.1 2020-Jun-14
1.0.0 2020-Jun-12
~master 2021-Jun-16
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 85 downloads total

Short URL: