1
0
mirror of https://github.com/solemnwarning/ipxwrapper synced 2024-12-30 16:45:37 +01:00
ipxwrapper/include/snprintf.h
Daniel Collins 26f6511dee Replace snprintf() implementation used within DLLs.
It appears that some of the mswsock.dll functions get called on
Windows 98 in a context where calling any of the printf functions
provided by the CRT causes subtle memory corruption which doesn't
manifest until the process exits, triggering a page fault in
KERNEL32.DLL and making the system unusable.

1990s Windows makes me miss the sophistication of 1970s UNIX.
2024-07-04 21:31:17 +01:00

75 lines
2.2 KiB
C

// Copyright (C) 2019 Miroslaw Toton, mirtoto@gmail.com
#ifndef SNPRINTF_H_
#define SNPRINTF_H_
#include <stdarg.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @see snprintf() */
int mirtoto_vsnprintf(char *string, size_t length, const char *format, va_list args) __attribute__((format(printf, 3, 0)));
/**
* Implementation of snprintf() function which create @p string of maximum
* @p length - 1 according of instruction provided by @p format.
*
* # Supportted types
*
* Type | Description
* -------- | ----------------------------------------
* d / i | signed decimal integer
* u | unsigned decimal integer
* o | unsigned octal integer
* x | unsigned hexadecimal integer
* f / F | decimal floating point
* e / E | scientific (exponential) floating point
* g / G | scientific or decimal floating point
* c | character
* s | string
* p | pointer
* % | percent character
*
* # Supported lengths
*
* Length | Description
* -------- | ----------------------------------------
* hh | signed / unsigned char
* h | signed / unsigned short
* l | signed / unsigned long
* ll | signed / unsigned long long
*
* # Supported flags
*
* Flag | Description
* -------- | ----------------------------------------
* - | justify left
* + | justify right or put a plus if number
* # | prefix 0x, 0X for hex and 0 for octal
* * | width and/or precision is specified as an int argument
* 0 | for number padding with zeros instead of spaces
* (space) | leave a blank for number with no sign
*
* @param string Output buffer.
* @param length Size of output buffer @p string.
* @param format Format of input parameters.
* @param ... Input parameters according of @p format.
*
* @retval >=0 Amount of characters put in @p string.
* @retval -1 Output buffer size is too small.
*/
int mirtoto_snprintf(char *string, size_t length, const char *format, ...) __attribute__((format(printf, 3, 4)));
#ifdef __cplusplus
}
#endif
#endif // SNPRINTF_H_