summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorRobert Haas2023-08-01 17:50:42 +0000
committerRobert Haas2023-08-01 17:50:42 +0000
commit6050b6a92d1e6b5a234e96382ea711683e67d280 (patch)
treed65fe86fe5ff5e09b3e3d025f266014e458fa7c7 /src/port
parentdeae1657ee6dd6f7b3effab3d44429d5434f5bbf (diff)
Add and use symbolic constants for tar header offsets and file types.
Because symbolic constants in a header file are better than magic constants embedded in the code. Patch by me, reviewed by Tom Lane, Dagfinn Ilmari Mannsåker, and Tristan Partin. Discussion: http://postgr.es/m/CA+TgmoZNbLwhmCrNtkJAvi8FLkwFdMeVU3myV2HQQpA5bvbRZg@mail.gmail.com
Diffstat (limited to 'src/port')
-rw-r--r--src/port/tar.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/port/tar.c b/src/port/tar.c
index 4afe9f25334..592b4fb7b0f 100644
--- a/src/port/tar.c
+++ b/src/port/tar.c
@@ -120,10 +120,10 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
if (linktarget && strlen(linktarget) > 99)
return TAR_SYMLINK_TOO_LONG;
- memset(h, 0, 512); /* assume tar header size */
+ memset(h, 0, TAR_BLOCK_SIZE);
/* Name 100 */
- strlcpy(&h[0], filename, 100);
+ strlcpy(&h[TAR_OFFSET_NAME], filename, 100);
if (linktarget != NULL || S_ISDIR(mode))
{
/*
@@ -139,68 +139,68 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
}
/* Mode 8 - this doesn't include the file type bits (S_IFMT) */
- print_tar_number(&h[100], 8, (mode & 07777));
+ print_tar_number(&h[TAR_OFFSET_MODE], 8, (mode & 07777));
/* User ID 8 */
- print_tar_number(&h[108], 8, uid);
+ print_tar_number(&h[TAR_OFFSET_UID], 8, uid);
/* Group 8 */
- print_tar_number(&h[116], 8, gid);
+ print_tar_number(&h[TAR_OFFSET_GID], 8, gid);
/* File size 12 */
if (linktarget != NULL || S_ISDIR(mode))
/* Symbolic link or directory has size zero */
- print_tar_number(&h[124], 12, 0);
+ print_tar_number(&h[TAR_OFFSET_SIZE], 12, 0);
else
- print_tar_number(&h[124], 12, size);
+ print_tar_number(&h[TAR_OFFSET_SIZE], 12, size);
/* Mod Time 12 */
- print_tar_number(&h[136], 12, mtime);
+ print_tar_number(&h[TAR_OFFSET_MTIME], 12, mtime);
/* Checksum 8 cannot be calculated until we've filled all other fields */
if (linktarget != NULL)
{
/* Type - Symbolic link */
- h[156] = '2';
+ h[TAR_OFFSET_TYPEFLAG] = TAR_FILETYPE_SYMLINK;
/* Link Name 100 */
- strlcpy(&h[157], linktarget, 100);
+ strlcpy(&h[TAR_OFFSET_LINKNAME], linktarget, 100);
}
else if (S_ISDIR(mode))
{
/* Type - directory */
- h[156] = '5';
+ h[TAR_OFFSET_TYPEFLAG] = TAR_FILETYPE_DIRECTORY;
}
else
{
/* Type - regular file */
- h[156] = '0';
+ h[TAR_OFFSET_TYPEFLAG] = TAR_FILETYPE_PLAIN;
}
/* Magic 6 */
- strcpy(&h[257], "ustar");
+ strcpy(&h[TAR_OFFSET_MAGIC], "ustar");
/* Version 2 */
- memcpy(&h[263], "00", 2);
+ memcpy(&h[TAR_OFFSET_VERSION], "00", 2);
/* User 32 */
/* XXX: Do we need to care about setting correct username? */
- strlcpy(&h[265], "postgres", 32);
+ strlcpy(&h[TAR_OFFSET_UNAME], "postgres", 32);
/* Group 32 */
/* XXX: Do we need to care about setting correct group name? */
- strlcpy(&h[297], "postgres", 32);
+ strlcpy(&h[TAR_OFFSET_GNAME], "postgres", 32);
/* Major Dev 8 */
- print_tar_number(&h[329], 8, 0);
+ print_tar_number(&h[TAR_OFFSET_DEVMAJOR], 8, 0);
/* Minor Dev 8 */
- print_tar_number(&h[337], 8, 0);
+ print_tar_number(&h[TAR_OFFSET_DEVMINOR], 8, 0);
/* Prefix 155 - not used, leave as nulls */
/* Finally, compute and insert the checksum */
- print_tar_number(&h[148], 8, tarChecksum(h));
+ print_tar_number(&h[TAR_OFFSET_CHECKSUM], 8, tarChecksum(h));
return TAR_OK;
}