libtar: use libtar tag in logging

Change-Id: I292366a237f9c8464f791d4d3cddaffc0d854577
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
(cherry picked from commit 566ef6bcaab4b038956ccff73876876aedda65eb)
diff --git a/libtar/block.c b/libtar/block.c
index b46d55a..91342c2 100755
--- a/libtar/block.c
+++ b/libtar/block.c
@@ -72,7 +72,7 @@
 	int num_zero_blocks = 0;
 
 #ifdef DEBUG
-	printf("==> th_read_internal(TAR=\"%s\")\n", t->pathname);
+	LOG("==> th_read_internal(TAR=\"%s\")\n", t->pathname);
 #endif
 
 	while ((i = tar_block_read(t, &(t->th_buf))) == T_BLOCKSIZE)
@@ -93,7 +93,7 @@
 		    && strncmp(t->th_buf.magic, TMAGIC, TMAGLEN - 1) != 0)
 		{
 #ifdef DEBUG
-			puts("!!! unknown magic value in tar header");
+			LOG("!!! unknown magic value in tar header");
 #endif
 			return -2;
 		}
@@ -102,7 +102,7 @@
 		    && strncmp(t->th_buf.version, TVERSION, TVERSLEN) != 0)
 		{
 #ifdef DEBUG
-			puts("!!! unknown version value in tar header");
+			LOG("!!! unknown version value in tar header");
 #endif
 			return -2;
 		}
@@ -112,7 +112,7 @@
 		    && !th_crc_ok(t))
 		{
 #ifdef DEBUG
-			puts("!!! tar header checksum error");
+			LOG("!!! tar header checksum error");
 #endif
 			return -2;
 		}
@@ -121,7 +121,7 @@
 	}
 
 #ifdef DEBUG
-	printf("<== th_read_internal(): returning %d\n", i);
+	LOG("<== th_read_internal(): returning %d\n", i);
 #endif
 	return i;
 }
@@ -136,7 +136,7 @@
 	char *ptr;
 
 #ifdef DEBUG
-	printf("==> th_read(t=0x%p)\n", (void *)t);
+	LOG("==> th_read(t=0x%p)\n", (void *)t);
 #endif
 
 	if (t->th_buf.gnu_longname != NULL)
@@ -183,7 +183,7 @@
 			return -1;
 		}
 #ifdef DEBUG
-		printf("    th_read(): GNU long linkname detected "
+		LOG("    th_read(): GNU long linkname detected "
 		       "(%zu bytes, %zu blocks)\n", sz, blocks);
 #endif
 		t->th_buf.gnu_longlink = (char *)malloc(blocks * T_BLOCKSIZE);
@@ -194,7 +194,7 @@
 		     j++, ptr += T_BLOCKSIZE)
 		{
 #ifdef DEBUG
-			printf("    th_read(): reading long linkname "
+			LOG("    th_read(): reading long linkname "
 			       "(%zu blocks left, ptr == %p)\n", blocks-j, (void *) ptr);
 #endif
 			i = tar_block_read(t, ptr);
@@ -205,11 +205,11 @@
 				return -1;
 			}
 #ifdef DEBUG
-			printf("    th_read(): read block == \"%s\"\n", ptr);
+			LOG("    th_read(): read block == \"%s\"\n", ptr);
 #endif
 		}
 #ifdef DEBUG
-		printf("    th_read(): t->th_buf.gnu_longlink == \"%s\"\n",
+		LOG("    th_read(): t->th_buf.gnu_longlink == \"%s\"\n",
 		       t->th_buf.gnu_longlink);
 #endif
 
@@ -233,7 +233,7 @@
 			return -1;
 		}
 #ifdef DEBUG
-		printf("    th_read(): GNU long filename detected "
+		LOG("    th_read(): GNU long filename detected "
 		       "(%zu bytes, %zu blocks)\n", sz, blocks);
 #endif
 		t->th_buf.gnu_longname = (char *)malloc(blocks * T_BLOCKSIZE);
@@ -244,7 +244,7 @@
 		     j++, ptr += T_BLOCKSIZE)
 		{
 #ifdef DEBUG
-			printf("    th_read(): reading long filename "
+			LOG("    th_read(): reading long filename "
 			       "(%zu blocks left, ptr == %p)\n", blocks-j, (void *) ptr);
 #endif
 			i = tar_block_read(t, ptr);
@@ -255,11 +255,11 @@
 				return -1;
 			}
 #ifdef DEBUG
-			printf("    th_read(): read block == \"%s\"\n", ptr);
+			LOG("    th_read(): read block == \"%s\"\n", ptr);
 #endif
 		}
 #ifdef DEBUG
-		printf("    th_read(): t->th_buf.gnu_longname == \"%s\"\n",
+		LOG("    th_read(): t->th_buf.gnu_longname == \"%s\"\n",
 		       t->th_buf.gnu_longname);
 #endif
 
@@ -280,7 +280,7 @@
 		if(sz >= T_BLOCKSIZE) // Not supported
 		{
 #ifdef DEBUG
-			printf("    th_read(): Extended header is too long!\n");
+			LOG("    th_read(): Extended header is too long!\n");
 #endif
 		}
 		else
@@ -306,7 +306,7 @@
 				memcpy(&t->th_buf.cap_data, start, sizeof(struct vfs_cap_data));
 				t->th_buf.has_cap_data = 1;
 #ifdef DEBUG
-				printf("    th_read(): Posix capabilities detected\n");
+				LOG("    th_read(): Posix capabilities detected\n");
 #endif
 			} // end posix capabilities
 			// selinux contexts
@@ -319,7 +319,7 @@
 				{
 					t->th_buf.selinux_context = strndup(start, end-start);
 #ifdef DEBUG
-					printf("    th_read(): SELinux context xattr detected: %s\n", t->th_buf.selinux_context);
+					LOG("    th_read(): SELinux context xattr detected: %s\n", t->th_buf.selinux_context);
 #endif
 				}
 			} // end selinux contexts
@@ -329,7 +329,7 @@
 			{
 				t->th_buf.has_user_default = 1;
 #ifdef DEBUG
-				printf("    th_read(): android user.default xattr detected\n");
+				LOG("    th_read(): android user.default xattr detected\n");
 #endif
 			} // end android user.default xattr
 			// android user.inode_cache xattr
@@ -338,7 +338,7 @@
 			{
 				t->th_buf.has_user_cache = 1;
 #ifdef DEBUG
-				printf("    th_read(): android user.inode_cache xattr detected\n");
+				LOG("    th_read(): android user.inode_cache xattr detected\n");
 #endif
 			} // end android user.inode_cache xattr
 			// android user.inode_code_cache xattr
@@ -347,7 +347,7 @@
 			{
 				t->th_buf.has_user_code_cache = 1;
 #ifdef DEBUG
-				printf("    th_read(): android user.inode_code_cache xattr detected\n");
+				LOG("    th_read(): android user.inode_code_cache xattr detected\n");
 #endif
 			} // end android user.inode_code_cache xattr
 
@@ -360,7 +360,7 @@
 				t->th_buf.fep = (struct fscrypt_policy_v2*)malloc(sizeof(struct fscrypt_policy_v2));
 #endif
 				if (!t->th_buf.fep) {
-					printf("malloc failed for fscrypt policy\n");
+					LOG("malloc failed for fscrypt policy\n");
 					return -1;
 				}
 				start += FSCRYPT_TAG_LEN;
@@ -372,14 +372,14 @@
 					char *newline_check = start + sizeof(struct fscrypt_policy_v2);
 #endif
 					if (*newline_check != '\n')
-						printf("did not find newline char in expected location, continuing anyway...\n");
+						LOG("did not find newline char in expected location, continuing anyway...\n");
 #ifdef USE_FSCRYPT_POLICY_V1
 					memcpy(t->th_buf.fep, start, sizeof(struct fscrypt_policy_v1));
 #else
 					memcpy(t->th_buf.fep, start, sizeof(struct fscrypt_policy_v2));
 #endif
 #ifdef DEBUG
-					printf("    th_read(): FSCrypt policy detected: %i %i %i %i %s\n",
+					LOG("    th_read(): FSCrypt policy detected: %i %i %i %i %s\n",
 						(int)t->th_buf.fep->version,
 						(int)t->th_buf.fep->contents_encryption_mode,
 						(int)t->th_buf.fep->filenames_encryption_mode,
@@ -392,7 +392,7 @@
 #endif
 				}
 				else {
-					printf("     invalid fscrypt header found\n");
+					LOG("     invalid fscrypt header found\n");
 				}
 			}
 #endif // USE_FSCRYPT
@@ -467,14 +467,14 @@
 	char buf[T_BLOCKSIZE];
 
 #ifdef DEBUG
-	printf("==> th_write(TAR=\"%s\")\n", t->pathname);
+	LOG("==> th_write(TAR=\"%s\")\n", t->pathname);
 	th_print(t);
 #endif
 
 	if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
 	{
 #ifdef DEBUG
-		printf("th_write(): using gnu_longlink (\"%s\")\n",
+		LOG("th_write(): using gnu_longlink (\"%s\")\n",
 		       t->th_buf.gnu_longlink);
 #endif
 		/* save old size and type */
@@ -525,7 +525,7 @@
 	if ((t->options & TAR_GNU) && t->th_buf.gnu_longname != NULL)
 	{
 #ifdef DEBUG
-		printf("th_write(): using gnu_longname (\"%s\")\n",
+		LOG("th_write(): using gnu_longname (\"%s\")\n",
 		       t->th_buf.gnu_longname);
 #endif
 		/* save old size and type */
@@ -579,7 +579,7 @@
 	if((t->options & TAR_STORE_SELINUX) && t->th_buf.selinux_context != NULL)
 	{
 #ifdef DEBUG
-		printf("th_write(): using selinux_context (\"%s\")\n",
+		LOG("th_write(): using selinux_context (\"%s\")\n",
 		       t->th_buf.selinux_context);
 #endif
 		/* setup size - EXT header has format "*size of this whole tag as ascii numbers* *space* *content* *newline* */
@@ -599,10 +599,10 @@
 	{
 #ifdef DEBUG
 #ifdef USE_FSCRYPT_POLICY_V1
-		printf("th_write(): using fscrypt_policy %s\n",
+		LOG("th_write(): using fscrypt_policy %s\n",
 		       t->th_buf.fep->master_key_descriptor);
 #else
-		printf("th_write(): using fscrypt_policy %s\n",
+		LOG("th_write(): using fscrypt_policy %s\n",
 		       t->th_buf.fep->master_key_identifier);
 #endif
 #endif
@@ -642,7 +642,7 @@
 	if((t->options & TAR_STORE_POSIX_CAP) && t->th_buf.has_cap_data)
 	{
 #ifdef DEBUG
-		printf("th_write(): has a posix capability\n");
+		LOG("th_write(): has a posix capability\n");
 #endif
 		sz = CAPABILITIES_TAG_LEN + sizeof(struct vfs_cap_data) + 3 + 1;
 
@@ -669,7 +669,7 @@
 	{
 		if (t->th_buf.has_user_default) {
 #ifdef DEBUG
-			printf("th_write(): has android user.default xattr\n");
+			LOG("th_write(): has android user.default xattr\n");
 #endif
 			sz = ANDROID_USER_DEFAULT_TAG_LEN + 3 + 1;
 
@@ -690,7 +690,7 @@
 		}
 		if (t->th_buf.has_user_cache) {
 #ifdef DEBUG
-			printf("th_write(): has android user.inode_cache xattr\n");
+			LOG("th_write(): has android user.inode_cache xattr\n");
 #endif
 			sz = ANDROID_USER_CACHE_TAG_LEN + 3 + 1;
 
@@ -711,7 +711,7 @@
 		}
 		if (t->th_buf.has_user_code_cache) {
 #ifdef DEBUG
-			printf("th_write(): has android user.inode_code_cache xattr\n");
+			LOG("th_write(): has android user.inode_code_cache xattr\n");
 #endif
 			sz = ANDROID_USER_CODE_CACHE_TAG_LEN + 3 + 1;
 
@@ -750,7 +750,7 @@
 	}
 
 #ifdef DEBUG
-	puts("th_write(): returning 0");
+	LOG("th_write(): returning 0");
 #endif
 	return 0;
 }