mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-07-14 12:57:10 +02:00
bin
cmake
module
Base
Core
Entity
Library
Misc
Vendor
AES256
B64
Hash
MDBC
cmake
examples
include
libmariadb
CMakeLists.txt
acinclude.m4
array.c
bchange.c
bmove.c
bmove_upp.c
charset.c
client_plugin.c
dbug.c
default.c
errmsg.c
errors.c
get_password.c
getopt.c
getopt1.c
hash.c
int2str.c
is_prefix.c
libmariadb.c
list.c
llstr.c
longlong2str.c
ma_dtoa.c
ma_dyncol.c
ma_secure.c
ma_time.c
mf_dirname.c
mf_fn_ext.c
mf_format.c
mf_loadpath.c
mf_pack.c
mf_path.c
mf_unixpath.c
mf_wcomp.c
mulalloc.c
my_alloc.c
my_auth.c
my_charset.c
my_compress.c
my_context.c
my_div.c
my_error.c
my_fopen.c
my_fstream.c
my_getwd.c
my_init.c
my_lib.c
my_loaddata.c
my_malloc.c
my_messnc.c
my_net.c
my_once.c
my_open.c
my_port.c
my_pthread.c
my_read.c
my_realloc.c
my_seek.c
my_static.c
my_static.h
my_stmt.c
my_stmt_codec.c
my_symlink.c
my_thr_init.c
my_vsnprintf.c
my_write.c
mysql_async.c
mysys_priv.h
net.c
password.c
sha1.c
str2int.c
strcend.c
strcont.c
strend.c
strfill.c
string.c
strinstr.c
strmake.c
strmov.c
strnlen.c
strnmov.c
strto.c
strtoll.c
strtoull.c
strxmov.c
strxnmov.c
thr_mutex.c
typelib.c
violite.c
mariadb_config
plugins
win
win-iconv
zlib
CMakeLists.txt
COPYING.LIB
README
MaxmindDB
PUGIXML
SQLite
SimpleIni
TinyDir
Whirlpool
CMakeLists.txt
CMakeLists.txt
Core.cpp
Core.hpp
Logger.cpp
Logger.hpp
Main.cpp
Register.cpp
SqBase.hpp
sdk
sqrat
squirrel
vcmp
.gitignore
CMakeLists.txt
LICENSE
README.md
120 lines
3.2 KiB
C
120 lines
3.2 KiB
C
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; if not, write to the Free
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
MA 02111-1301, USA */
|
|
|
|
#include "mysys_priv.h"
|
|
#include "mysys_err.h"
|
|
#include <m_string.h>
|
|
#include <stdarg.h>
|
|
#include <m_ctype.h>
|
|
|
|
|
|
int my_snprintf(char* to, size_t n, const char* fmt, ...)
|
|
{
|
|
int result;
|
|
va_list args;
|
|
va_start(args,fmt);
|
|
result= my_vsnprintf(to, n, fmt, args);
|
|
va_end(args);
|
|
return result;
|
|
}
|
|
|
|
|
|
int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
|
|
{
|
|
char *start=to, *end=to+n-1;
|
|
for (; *fmt ; fmt++)
|
|
{
|
|
if (fmt[0] != '%')
|
|
{
|
|
if (to == end) /* End of buffer */
|
|
break;
|
|
*to++= *fmt; /* Copy ordinary char */
|
|
continue;
|
|
}
|
|
/* Skipp if max size is used (to be compatible with printf) */
|
|
fmt++;
|
|
while (isdigit(*fmt) || *fmt == '.' || *fmt == '-')
|
|
fmt++;
|
|
if (*fmt == 'l')
|
|
fmt++;
|
|
if (*fmt == 's') /* String parameter */
|
|
{
|
|
reg2 char *par = va_arg(ap, char *);
|
|
uint plen;
|
|
if (!par) par = (char*)"(null)";
|
|
plen = (uint) strlen(par);
|
|
if ((uint) (end-to) > plen) /* Replace if possible */
|
|
{
|
|
to=strmov(to,par);
|
|
continue;
|
|
}
|
|
}
|
|
else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
|
|
{
|
|
register int iarg;
|
|
if ((uint) (end-to) < 16)
|
|
break;
|
|
iarg = va_arg(ap, int);
|
|
if (*fmt == 'd')
|
|
to=int10_to_str((long) iarg,to, -10);
|
|
else
|
|
to=int10_to_str((long) (uint) iarg,to,10);
|
|
continue;
|
|
}
|
|
/* We come here on '%%', unknown code or too long parameter */
|
|
if (to == end)
|
|
break;
|
|
*to++='%'; /* % used as % or unknown code */
|
|
}
|
|
*to='\0'; /* End of errmessage */
|
|
return (uint) (to - start);
|
|
}
|
|
|
|
|
|
#ifdef MAIN
|
|
static void my_printf(const char * fmt, ...)
|
|
{
|
|
char buf[32];
|
|
int n;
|
|
va_list ar;
|
|
va_start(ar, fmt);
|
|
n = my_vsnprintf(buf, sizeof(buf),fmt, ar);
|
|
printf(buf);
|
|
printf("n=%d, strlen=%d\n", n, strlen(buf));
|
|
va_end(ar);
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
|
|
my_printf("Hello\n");
|
|
my_printf("Hello int, %d\n", 1);
|
|
my_printf("Hello string '%s'\n", "I am a string");
|
|
my_printf("Hello hack hack hack hack hack hack hack %d\n", 1);
|
|
my_printf("Hello %d hack %d\n", 1, 4);
|
|
my_printf("Hello %d hack hack hack hack hack %d\n", 1, 4);
|
|
my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack");
|
|
my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1);
|
|
my_printf("Hello %u\n", 1);
|
|
my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\
|
|
`%-.64s' (%-.64s)", 1, 0,0,0,0);
|
|
return 0;
|
|
}
|
|
#endif
|
|
|