Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
71eea6ad
Commit
71eea6ad
authored
9 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add an asprintf() implementation for Win32. Not tested yet, but it should work
if I can reuse a va_list argument.
parent
887c5723
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/xpprintf.c
+41
-17
41 additions, 17 deletions
src/xpdev/xpprintf.c
with
41 additions
and
17 deletions
src/xpdev/xpprintf.c
+
41
−
17
View file @
71eea6ad
...
...
@@ -44,6 +44,24 @@
#include
"xpprintf.h"
#include
"gen_defs.h"
#if defined(_MSC_VER) || defined(__MSVCRT__)
int
asprintf
(
char
**
strptr
,
char
*
format
,
...)
{
va_list
va
;
int
ret
;
if
(
strptr
==
NULL
)
return
-
1
;
va_start
(
va
,
format
);
ret
=
_vscprintf
(
format
,
va
);
*
strptr
=
(
char
*
)
malloc
(
ret
+
1
);
if
(
*
strptr
==
NULL
)
return
-
1
;
ret
=
sprintf
(
*
strptr
,
format
,
va
);
va_end
(
va
);
}
#endif
/* MSVC Sucks - can't tell the required len of a *printf() */
#define MAX_ARG_LEN 1024
/* MAX_ARG_LEN is the maximum length
* possible as a result of a format
...
...
@@ -1154,37 +1172,37 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
}
}
/* The next char is now the type...
perform nativ
e
s
printf()
using it
*/
/* The next char is now the type...
check the length required to spore th
e printf()
ed string
*/
*
(
fmt
++
)
=*
p
;
*
fmt
=
0
;
entry
=
entry_buf
;
entry
=
NULL
;
switch
(
type
)
{
case
XP_PRINTF_TYPE_CHAR
:
/* Also includes char and short */
case
XP_PRINTF_TYPE_INT
:
/* Also includes char and short */
j
=
sprintf
(
entry
,
this_format
,
i
);
j
=
a
sprintf
(
&
entry
,
this_format
,
i
);
break
;
case
XP_PRINTF_TYPE_UINT
:
/* Also includes char and short */
j
=
sprintf
(
entry
,
this_format
,
ui
);
j
=
a
sprintf
(
&
entry
,
this_format
,
ui
);
break
;
case
XP_PRINTF_TYPE_LONG
:
j
=
sprintf
(
entry
,
this_format
,
l
);
j
=
a
sprintf
(
&
entry
,
this_format
,
l
);
break
;
case
XP_PRINTF_TYPE_ULONG
:
j
=
sprintf
(
entry
,
this_format
,
ul
);
j
=
a
sprintf
(
&
entry
,
this_format
,
ul
);
break
;
#if defined(XP_PRINTF_TYPE_LONGLONG)
case
XP_PRINTF_TYPE_LONGLONG
:
j
=
sprintf
(
entry
,
this_format
,
ll
);
j
=
a
sprintf
(
&
entry
,
this_format
,
ll
);
break
;
case
XP_PRINTF_TYPE_ULONGLONG
:
j
=
sprintf
(
entry
,
this_format
,
ull
);
j
=
a
sprintf
(
&
entry
,
this_format
,
ull
);
break
;
#endif
case
XP_PRINTF_TYPE_CHARP
:
if
(
cp
==
NULL
)
j
=
sprintf
(
entry
,
this_format
,
"<null>"
);
j
=
a
sprintf
(
&
entry
,
this_format
,
"<null>"
);
else
{
s
=
strlen
(
cp
);
/*
s=strlen(cp);
if(s<width)
s=width;
if(s<precision)
...
...
@@ -1192,26 +1210,31 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
if(s>=MAX_ARG_LEN)
entry=(char *)alloca(s+1);
if(entry==NULL)
return
(
NULL
);
j
=
sprintf
(
entry
,
this_format
,
cp
);
return(NULL);
*/
j
=
a
sprintf
(
&
entry
,
this_format
,
cp
);
}
break
;
case
XP_PRINTF_TYPE_DOUBLE
:
j
=
sprintf
(
entry
,
this_format
,
d
);
j
=
a
sprintf
(
&
entry
,
this_format
,
d
);
break
;
case
XP_PRINTF_TYPE_LONGDOUBLE
:
j
=
sprintf
(
entry
,
this_format
,
ld
);
j
=
a
sprintf
(
&
entry
,
this_format
,
ld
);
break
;
case
XP_PRINTF_TYPE_VOIDP
:
j
=
sprintf
(
entry
,
this_format
,
pntr
);
j
=
a
sprintf
(
&
entry
,
this_format
,
pntr
);
break
;
case
XP_PRINTF_TYPE_SIZET
:
j
=
sprintf
(
entry
,
this_format
,
s
);
j
=
asprintf
(
&
entry
,
this_format
,
s
);
break
;
default:
j
=
-
1
;
entry
=
NULL
;
break
;
}
if
(
j
<
0
)
{
strcpy
(
entry
,
"<error>"
);
FREE_AND_NULL
(
entry
);
entry
=
strdup
(
"<error>"
);
j
=
strlen
(
entry
);
}
...
...
@@ -1235,6 +1258,7 @@ char* DLLCALL xp_asprintf_next(char *format, int type, ...)
}
else
p
=
format
+
offset
+
this_format_len
;
FREE_AND_NULL
(
entry
);
*
(
size_t
*
)(
format
+
sizeof
(
size_t
))
=
format_len
-
this_format_len
+
j
-
sizeof
(
size_t
)
*
2
-
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment