Call truncate through perl.

The binary is not available, and we can't pack it in otatools in AOSP,
have to use an alternative.

Bug: 27880501
Test: Generate a payload for boot.img which is not multiple of 4KiB.

Change-Id: I693e6cf441e3c9ea863d27704d6a31889c05cce6
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index fdb58da..ec31ddb 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -222,6 +222,18 @@
   echo "${default_value}"
 }
 
+# truncate_file <file_path> <file_size>
+#
+# Truncate the given |file_path| to |file_size| using perl.
+# The truncate binary might not be available.
+truncate_file() {
+  local file_path="$1"
+  local file_size="$2"
+  perl -e "open(FILE, \"+<\", \$ARGV[0]); \
+           truncate(FILE, ${file_size}); \
+           close(FILE);" "${file_path}"
+}
+
 # Create a temporary file in the work_dir with an optional pattern name.
 # Prints the name of the newly created file.
 create_tempfile() {
@@ -435,7 +447,7 @@
         echo "Rounding UP partition ${part}.img to a multiple of 4 KiB."
         : $(( filesize = (filesize + 4095) & -4096 ))
       fi
-      truncate --size="${filesize}" "${part_file}"
+      truncate_file "${part_file}" "${filesize}"
     fi
 
     eval "${partitions_array}[\"${part}\"]=\"${part_file}\""