d_snprintf 1.2.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 package provides sub packages which can be used individually:

d_snprintf:test - Programm to test our snprintf against the system's version

This is a port of Holger Weiß' implementation of snprintf (available at http://www.jhweiss.de/software/snprintf.html) as well as my own version of snscanf. 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 (v)snprintf and (v)snscanf 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 build the sub-package "d_snprintf:test" to test this version of snprintf against the C version of your system.

  • Kyto
Sub packages:
1.2.1 2023-Jan-22
1.2.0 2023-Jan-22
1.1.1 2021-Jun-16
1.1.0 2021-Jan-17
1.0.1 2020-Jun-14
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 4 downloads this week

  • 28 downloads this month

  • 280 downloads total

Short URL: