Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ TESTS = \
ostep-strings.test \
ostep-comments.test \
ostep-invalid-types.test \
xml_behavior.test
xml_behavior.test \
plistutil-streams.test

EXTRA_DIST = \
$(TESTS) \
Expand Down Expand Up @@ -136,7 +137,8 @@ EXTRA_DIST = \
data/o1.ostep \
data/o2.ostep \
data/o3.ostep \
data/test.strings
data/test.strings \
data/streams.plist

TESTS_ENVIRONMENT = \
top_srcdir=$(top_srcdir) \
Expand Down
5 changes: 5 additions & 0 deletions test/data/streams.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<data>DQoa</data>
</plist>
34 changes: 34 additions & 0 deletions test/plistutil-streams.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## -*- sh -*-
set -e

DATASRC=$top_srcdir/test/data
DATAOUT=$top_builddir/test/data
PLISTUTIL=$top_builddir/tools/plistutil
TESTFILE=$DATAOUT/plistutil-streams.test

mkdir -p "$DATAOUT"

# The data contains CR, LF and Ctrl-Z, which Windows text streams translate.
"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin -o "$TESTFILE.bin"
"$PLISTUTIL" -i "$TESTFILE.bin" -f xml -o "$TESTFILE.xml"

echo "Checking binary stdout"
"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin > "$TESTFILE.stdout.out"
cmp "$TESTFILE.bin" "$TESTFILE.stdout.out"
"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin -o - > "$TESTFILE.stdout.out"
cmp "$TESTFILE.bin" "$TESTFILE.stdout.out"

echo "Checking binary stdin"
"$PLISTUTIL" -f xml -o "$TESTFILE.stdin.out" < "$TESTFILE.bin"
cmp "$TESTFILE.xml" "$TESTFILE.stdin.out"
cat "$TESTFILE.bin" | "$PLISTUTIL" -i - -f xml -o "$TESTFILE.stdin.out"
cmp "$TESTFILE.xml" "$TESTFILE.stdin.out"

echo "Checking binary stdin in print mode"
"$PLISTUTIL" -p "$TESTFILE.bin" > "$TESTFILE.print.out"
cat "$TESTFILE.bin" | "$PLISTUTIL" -p - > "$TESTFILE.stdin.out"
cmp "$TESTFILE.print.out" "$TESTFILE.stdin.out"

echo "Checking XML stdout"
"$PLISTUTIL" -i "$TESTFILE.bin" -f xml > "$TESTFILE.stdout.out"
cmp "$TESTFILE.xml" "$TESTFILE.stdout.out"
13 changes: 12 additions & 1 deletion tools/plistutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <sys/stat.h>
#include <getopt.h>
#include <errno.h>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
#ifndef _MSC_VER
#include <unistd.h>
#endif
Expand Down Expand Up @@ -263,6 +267,9 @@ int main(int argc, char *argv[])

if (!options->in_file || !strcmp(options->in_file, "-"))
{
#ifdef _WIN32
_setmode(_fileno(stdin), _O_BINARY);
#endif
read_size = 0;
plist_entire = malloc(sizeof(char) * read_capacity);
if(plist_entire == NULL)
Expand Down Expand Up @@ -472,8 +479,12 @@ int main(int argc, char *argv[])
fclose(oplist);
}
// if no output file specified, write to stdout
else
else {
#ifdef _WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
fwrite(plist_out, size, sizeof(char), stdout);
}

free(plist_out);
}
Expand Down