diff options
author | Robert Haas <rhaas@postgresql.org> | 2023-08-01 13:50:42 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2023-08-01 13:50:42 -0400 |
commit | 6050b6a92d1e6b5a234e96382ea711683e67d280 (patch) | |
tree | d65fe86fe5ff5e09b3e3d025f266014e458fa7c7 /src/bin/pg_dump/pg_backup_tar.c | |
parent | deae1657ee6dd6f7b3effab3d44429d5434f5bbf (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/bin/pg_dump/pg_backup_tar.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_tar.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index db5fb43bae8..aad88ad559f 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -975,20 +975,20 @@ isValidTarHeader(char *header) int sum; int chk = tarChecksum(header); - sum = read_tar_number(&header[148], 8); + sum = read_tar_number(&header[TAR_OFFSET_CHECKSUM], 8); if (sum != chk) return false; /* POSIX tar format */ - if (memcmp(&header[257], "ustar\0", 6) == 0 && - memcmp(&header[263], "00", 2) == 0) + if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar\0", 6) == 0 && + memcmp(&header[TAR_OFFSET_VERSION], "00", 2) == 0) return true; /* GNU tar format */ - if (memcmp(&header[257], "ustar \0", 8) == 0) + if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar \0", 8) == 0) return true; /* not-quite-POSIX format written by pre-9.3 pg_dump */ - if (memcmp(&header[257], "ustar00\0", 8) == 0) + if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar00\0", 8) == 0) return true; return false; @@ -1151,7 +1151,7 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) /* Calc checksum */ chk = tarChecksum(h); - sum = read_tar_number(&h[148], 8); + sum = read_tar_number(&h[TAR_OFFSET_CHECKSUM], 8); /* * If the checksum failed, see if it is a null block. If so, silently @@ -1175,9 +1175,9 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) } /* Name field is 100 bytes, might not be null-terminated */ - strlcpy(tag, &h[0], 100 + 1); + strlcpy(tag, &h[TAR_OFFSET_NAME], 100 + 1); - len = read_tar_number(&h[124], 12); + len = read_tar_number(&h[TAR_OFFSET_SIZE], 12); pg_log_debug("TOC Entry %s at %llu (length %llu, checksum %d)", tag, (unsigned long long) hPos, (unsigned long long) len, sum); |