1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

Standardize on MAXPGPATH as the size of a file pathname buffer,

eliminating some wildly inconsistent coding in various parts of the
system.  I set MAXPGPATH = 1024 in config.h.in.  If anyone is really
convinced that there ought to be a configure-time test to set the
value, go right ahead ... but I think it's a waste of time.
This commit is contained in:
Tom Lane
1999-10-25 03:08:03 +00:00
parent 8a17ed6335
commit 51f62d505e
22 changed files with 183 additions and 193 deletions

View File

@@ -7,14 +7,10 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.12 1999/07/17 20:18:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.13 1999/10/25 03:08:03 tgl Exp $
*
* NOTES
* XXX eventually, should be able to handle version identifiers
* of length != 4.
*
* STANDALONE CODE - do not use error routines as this code is linked with
* stuff that does not cinterface.a
* STANDALONE CODE - do not use error routines as this code is not linked
* with any...
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
@@ -41,7 +37,7 @@ PathSetVersionFilePath(const char *path, char *filepathbuf)
Destructively change "filepathbuf" to contain the concatenation of "path"
and the name of the version file name.
----------------------------------------------------------------------------*/
if (strlen(path) > (MAXPGPATH - sizeof(PG_VERFILE) - 1))
if ((strlen(path) + 1 + strlen(PG_VERFILE)) >= MAXPGPATH)
*filepathbuf = '\0';
else
sprintf(filepathbuf, "%s%c%s", path, SEP_CHAR, PG_VERFILE);
@@ -61,44 +57,45 @@ ValidatePgVersion(const char *path, char **reason_p)
we can't tell), and return a pointer to that space as <*reason_p>.
-----------------------------------------------------------------------------*/
int fd;
char version[4];
char full_path[MAXPGPATH + 1];
int nread;
char myversion[32];
char version[32];
char full_path[MAXPGPATH];
PathSetVersionFilePath(path, full_path);
sprintf(myversion, "%s.%s\n", PG_RELEASE, PG_VERSION);
#ifndef __CYGWIN32__
if ((fd = open(full_path, O_RDONLY, 0)) == -1)
#else
if ((fd = open(full_path, O_RDONLY | O_BINARY, 0)) == -1)
#endif
{
*reason_p = malloc(200);
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p, "File '%s' does not exist or no read permission.", full_path);
}
else
{
if (read(fd, version, 4) < 4 ||
!isascii(version[0]) || !isdigit(version[0]) ||
version[1] != '.' ||
!isascii(version[2]) || !isdigit(version[2]) ||
version[3] != '\n')
nread = read(fd, version, sizeof(version)-1);
if (nread < 4 ||
!isdigit(version[0]) ||
version[nread-1] != '\n')
{
*reason_p = malloc(200);
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p, "File '%s' does not have a valid format "
"for a PG_VERSION file.", full_path);
}
else
{
if (version[2] != PG_VERSION[0] ||
version[0] != PG_RELEASE[0])
version[nread] = '\0';
if (strcmp(version, myversion) != 0)
{
*reason_p = malloc(200);
*reason_p = malloc(200 + strlen(full_path));
sprintf(*reason_p,
"Version number in file '%s' should be %s.%s, "
"not %c.%c.",
full_path,
PG_RELEASE, PG_VERSION, version[0], version[2]);
"Version number in file '%s' should be %s, "
"not %s.",
full_path, myversion, version);
}
else
*reason_p = NULL;
@@ -120,11 +117,13 @@ SetPgVersion(const char *path, char **reason_p)
return *reason_p = NULL.
---------------------------------------------------------------------------*/
int fd;
char version[4];
char full_path[MAXPGPATH + 1];
char version[32];
char full_path[MAXPGPATH];
PathSetVersionFilePath(path, full_path);
sprintf(version, "%s.%s\n", PG_RELEASE, PG_VERSION);
#ifndef __CYGWIN32__
fd = open(full_path, O_WRONLY | O_CREAT | O_EXCL, 0666);
#else
@@ -141,12 +140,8 @@ SetPgVersion(const char *path, char **reason_p)
{
int rc; /* return code from some function we call */
version[0] = PG_RELEASE[0];
version[1] = '.';
version[2] = PG_VERSION[0];
version[3] = '\n';
rc = write(fd, version, 4);
if (rc != 4)
rc = write(fd, version, strlen(version));
if (rc != strlen(version))
{
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p,