Mail Archives: djgpp-workers/1999/06/09/16:04:27
Bonjour
I was playing with djgpp this afternoon and notice snprintf()
was missing. It's not ANSI not even POSIX, I beleive. But more and
more apps use it because of the security that it provides, sprintf() and
vsprintf() provide no buffer checks.
I think it's define in Unix98 and most modern OS will have it.
Well at least the 3 sitting in front of me (Solaris, Linux, QNX/NTO).
If you decide to use it and need the *.txh equivalent let me know.
stdio.h:
int vsnprintf(char *s, size_t n, const char *format, va_list ap);
int snprintf(char *s, size_t n, const char *format, ...);
----------------------------------------
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <limits.h>
#include <libc/file.h>
int
snprintf(char *str, size_t n, const char *fmt, ...)
{
FILE _strbuf;
int len;
if ((int)n < 1)
return EOF;
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = n - 1;
len = _doprnt(fmt, &(fmt)+1, &_strbuf);
*_strbuf._ptr = 0;
return len;
}
----------------------------------------
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <libc/file.h>
int
vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
{
FILE f;
int len;
if ((int)n < 1)
return (EOF);
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = n - 1;
len = _doprnt(fmt, ap, &f);
*f._ptr = 0;
return len;
}
------------------------------------------------
--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!
- Raw text -