Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libplist
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pwn
libplist
Commits
9834d85c
Commit
9834d85c
authored
9 years ago
by
Nikias Bassen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xplist: Get rid of setlocale() and use custom function to print floating point values
parent
9ca25d29
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
14 deletions
+32
-14
xplist.c
src/xplist.c
+32
-14
No files found.
src/xplist.c
View file @
9834d85c
...
...
@@ -29,7 +29,7 @@
#include <time.h>
#include <inttypes.h>
#include <
locale
.h>
#include <
math
.h>
#include <libxml/xmlIO.h>
#include <libxml/parser.h>
...
...
@@ -147,6 +147,36 @@ static struct node_t* new_uint_node(uint64_t value)
return
node_create
(
NULL
,
data
);
}
static
void
dtostr
(
char
*
buf
,
size_t
bufsize
,
double
realval
)
{
double
f
=
realval
;
double
ip
=
0
.
0
;
int64_t
v
;
size_t
len
;
size_t
p
;
f
=
modf
(
f
,
&
ip
);
len
=
snprintf
(
buf
,
bufsize
,
"%s%"
PRIi64
,
((
f
<
0
)
&&
(
ip
>=
0
))
?
"-"
:
""
,
(
int64_t
)
ip
);
if
(
len
>=
bufsize
)
{
return
;
}
if
(
f
<
0
)
{
f
*=
-
1
;
}
f
+=
0
.
0000004
;
p
=
len
;
buf
[
p
++
]
=
'.'
;
while
(
p
<
bufsize
&&
(
p
<=
len
+
6
))
{
f
=
modf
(
f
*
10
,
&
ip
);
v
=
(
int
)
ip
;
buf
[
p
++
]
=
(
v
+
0x30
);
}
buf
[
p
]
=
'\0'
;
}
static
void
node_to_xml
(
node_t
*
node
,
void
*
xml_struct
)
{
struct
xml_node
*
xstruct
=
NULL
;
...
...
@@ -194,7 +224,7 @@ static void node_to_xml(node_t* node, void *xml_struct)
case
PLIST_REAL
:
tag
=
XPLIST_REAL
;
val
=
(
char
*
)
malloc
(
64
);
(
void
)
snprintf
(
val
,
64
,
"%f"
,
node_data
->
realval
);
dtostr
(
val
,
64
,
node_data
->
realval
);
break
;
case
PLIST_STRING
:
...
...
@@ -529,14 +559,6 @@ PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
root_node
=
xmlDocGetRootElement
(
plist_doc
);
root
.
xml
=
root_node
;
char
*
current_locale
=
setlocale
(
LC_NUMERIC
,
NULL
);
char
*
saved_locale
=
NULL
;
if
(
current_locale
)
{
saved_locale
=
strdup
(
current_locale
);
}
if
(
saved_locale
)
{
setlocale
(
LC_NUMERIC
,
"POSIX"
);
}
node_to_xml
(
plist
,
&
root
);
xmlChar
*
tmp
=
NULL
;
...
...
@@ -552,10 +574,6 @@ PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
}
xmlFreeDoc
(
plist_doc
);
if
(
saved_locale
)
{
setlocale
(
LC_NUMERIC
,
saved_locale
);
free
(
saved_locale
);
}
/* free memory from parser initialization */
xmlCleanupCharEncodingHandlers
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment