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

@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.6 1999/10/24 20:42:27 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.7 1999/10/25 03:07:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -33,8 +33,8 @@ void StartupXLOG(void);
void ShutdownXLOG(void); void ShutdownXLOG(void);
void CreateCheckPoint(bool shutdown); void CreateCheckPoint(bool shutdown);
char XLogDir[MAXPGPATH+1]; char XLogDir[MAXPGPATH];
char ControlFilePath[MAXPGPATH+1]; char ControlFilePath[MAXPGPATH];
uint32 XLOGbuffers = 0; uint32 XLOGbuffers = 0;
XLogRecPtr MyLastRecPtr = {0, 0}; XLogRecPtr MyLastRecPtr = {0, 0};
bool StopIfError = false; bool StopIfError = false;
@ -147,8 +147,8 @@ typedef struct CheckPoint
#define XLogFileSize (XLogLastSeg * XLogSegSize) #define XLogFileSize (XLogLastSeg * XLogSegSize)
#define XLogFileName(path, log, seg) \ #define XLogFileName(path, log, seg) \
sprintf(path, "%.*s%c%08X%08X", \ snprintf(path, MAXPGPATH, "%s%c%08X%08X", \
MAXPGPATH, XLogDir, SEP_CHAR, log, seg) XLogDir, SEP_CHAR, log, seg)
#define PrevBufIdx(curridx) \ #define PrevBufIdx(curridx) \
((curridx == 0) ? XLogCtl->XLogCacheBlck : (curridx - 1)) ((curridx == 0) ? XLogCtl->XLogCacheBlck : (curridx - 1))
@ -718,7 +718,7 @@ XLogWrite(char *buffer)
static int static int
XLogFileInit(uint32 log, uint32 seg) XLogFileInit(uint32 log, uint32 seg)
{ {
char path[MAXPGPATH+1]; char path[MAXPGPATH];
int fd; int fd;
XLogFileName(path, log, seg); XLogFileName(path, log, seg);
@ -760,7 +760,7 @@ tryAgain:
static int static int
XLogFileOpen(uint32 log, uint32 seg, bool econt) XLogFileOpen(uint32 log, uint32 seg, bool econt)
{ {
char path[MAXPGPATH+1]; char path[MAXPGPATH];
int fd; int fd;
XLogFileName(path, log, seg); XLogFileName(path, log, seg);
@ -1067,7 +1067,7 @@ next_record_is_invalid:;
readId++; readId++;
} }
{ {
char path[MAXPGPATH+1]; char path[MAXPGPATH];
XLogFileName(path, readId, readSeg); XLogFileName(path, readId, readSeg);
unlink(path); unlink(path);

View File

@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.69 1999/10/06 21:58:02 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.70 1999/10/25 03:07:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -333,8 +333,10 @@ BootstrapMain(int argc, char *argv[])
*/ */
if (IsUnderPostmaster || xloginit) if (IsUnderPostmaster || xloginit)
{ {
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR); snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR); DataDir, SEP_CHAR);
snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
DataDir, SEP_CHAR);
} }
if (IsUnderPostmaster && xloginit) if (IsUnderPostmaster && xloginit)

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.41 1999/09/24 00:24:17 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.42 1999/10/25 03:07:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -38,9 +38,9 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
{ {
Oid db_id; Oid db_id;
int4 user_id; int4 user_id;
char buf[512]; char buf[MAXPGPATH + 100];
char *lp, char *lp,
loc[512]; loc[MAXPGPATH];
/* /*
* If this call returns, the database does not exist and we're allowed * If this call returns, the database does not exist and we're allowed
@ -56,7 +56,7 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
{ {
if (*(dbpath + strlen(dbpath) - 1) == SEP_CHAR) if (*(dbpath + strlen(dbpath) - 1) == SEP_CHAR)
*(dbpath + strlen(dbpath) - 1) = '\0'; *(dbpath + strlen(dbpath) - 1) = '\0';
snprintf(loc, 512, "%s%c%s", dbpath, SEP_CHAR, dbname); snprintf(loc, sizeof(loc), "%s%c%s", dbpath, SEP_CHAR, dbname);
} }
else else
strcpy(loc, dbname); strcpy(loc, dbname);
@ -71,11 +71,11 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
if (mkdir(lp, S_IRWXU) != 0) if (mkdir(lp, S_IRWXU) != 0)
elog(ERROR, "Unable to create database directory '%s'", lp); elog(ERROR, "Unable to create database directory '%s'", lp);
snprintf(buf, 512, "%s %s%cbase%ctemplate1%c* %s", snprintf(buf, sizeof(buf), "%s %s%cbase%ctemplate1%c* '%s'",
COPY_CMD, DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, lp); COPY_CMD, DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, lp);
system(buf); system(buf);
snprintf(buf, 512, snprintf(buf, sizeof(buf),
"insert into pg_database (datname, datdba, encoding, datpath)" "insert into pg_database (datname, datdba, encoding, datpath)"
" values ('%s', '%d', '%d', '%s');", dbname, user_id, encoding, " values ('%s', '%d', '%d', '%s');", dbname, user_id, encoding,
loc); loc);
@ -89,8 +89,8 @@ destroydb(char *dbname, CommandDest dest)
int4 user_id; int4 user_id;
Oid db_id; Oid db_id;
char *path, char *path,
dbpath[MAXPGPATH + 1], dbpath[MAXPGPATH],
buf[MAXPGPATH + 50]; buf[MAXPGPATH + 100];
Relation pgdbrel; Relation pgdbrel;
HeapScanDesc pgdbscan; HeapScanDesc pgdbscan;
ScanKeyData key; ScanKeyData key;
@ -233,7 +233,7 @@ check_permissions(char *command,
bool use_super; bool use_super;
char *userName; char *userName;
text *dbtext; text *dbtext;
char path[MAXPGPATH + 1]; char path[MAXPGPATH];
userName = GetPgUserName(); userName = GetPgUserName();
utup = SearchSysCacheTuple(USENAME, utup = SearchSysCacheTuple(USENAME,
@ -332,7 +332,7 @@ static void
stop_vacuum(char *dbpath, char *dbname) stop_vacuum(char *dbpath, char *dbname)
{ {
#ifdef NOT_USED #ifdef NOT_USED
char filename[MAXPGPATH + 1]; char filename[MAXPGPATH];
FILE *fp; FILE *fp;
int pid; int pid;

View File

@ -28,7 +28,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pqcomm.c,v 1.85 1999/10/23 03:13:22 tgl Exp $ * $Id: pqcomm.c,v 1.86 1999/10/25 03:07:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -155,7 +155,8 @@ pq_close(void)
* Stream functions are used for vanilla TCP connection protocol. * Stream functions are used for vanilla TCP connection protocol.
*/ */
static char sock_path[MAXPGPATH + 1] = ""; static char sock_path[MAXPGPATH];
/* StreamDoUnlink() /* StreamDoUnlink()
* Shutdown routine for backend connection * Shutdown routine for backend connection

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.126 1999/10/08 05:36:58 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.127 1999/10/25 03:07:45 tgl Exp $
* *
* NOTES * NOTES
* *
@ -179,7 +179,7 @@ static time_t tnow;
/* /*
* Default Values * Default Values
*/ */
static char Execfile[MAXPATHLEN] = ""; static char Execfile[MAXPGPATH];
static int ServerSock_INET = INVALID_SOCK; /* stream socket server */ static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
@ -195,7 +195,7 @@ static SSL_CTX *SSL_context = NULL; /* Global SSL context */
/* /*
* Set by the -o option * Set by the -o option
*/ */
static char ExtraOptions[MAXPATHLEN] = ""; static char ExtraOptions[MAXPGPATH];
/* /*
* These globals control the behavior of the postmaster in case some * These globals control the behavior of the postmaster in case some
@ -294,10 +294,10 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
} }
else else
{ {
char path[MAXPATHLEN]; char path[MAXPGPATH];
FILE *fp; FILE *fp;
sprintf(path, "%s%cbase%ctemplate1%cpg_class", snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR); DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
#ifndef __CYGWIN32__ #ifndef __CYGWIN32__
fp = AllocateFile(path, "r"); fp = AllocateFile(path, "r");
@ -446,7 +446,7 @@ PostmasterMain(int argc, char *argv[])
case 'b': case 'b':
/* Set the backend executable file to use. */ /* Set the backend executable file to use. */
if (!ValidateBinary(optarg)) if (!ValidateBinary(optarg))
strcpy(Execfile, optarg); StrNCpy(Execfile, optarg, MAXPGPATH);
else else
{ {
fprintf(stderr, "%s: invalid backend \"%s\"\n", fprintf(stderr, "%s: invalid backend \"%s\"\n",
@ -1698,7 +1698,7 @@ DoBackend(Port *port)
{ {
char *av[ARGV_SIZE * 2]; char *av[ARGV_SIZE * 2];
int ac = 0; int ac = 0;
char execbuf[MAXPATHLEN]; char execbuf[MAXPGPATH];
char debugbuf[ARGV_SIZE]; char debugbuf[ARGV_SIZE];
char protobuf[ARGV_SIZE]; char protobuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE]; char dbbuf[ARGV_SIZE];
@ -1749,7 +1749,7 @@ DoBackend(Port *port)
* ---------------- * ----------------
*/ */
StrNCpy(execbuf, Execfile, MAXPATHLEN); StrNCpy(execbuf, Execfile, MAXPGPATH);
av[ac++] = execbuf; av[ac++] = execbuf;
/* /*
@ -2013,7 +2013,7 @@ SSDataBase(bool startup)
{ {
char *av[ARGV_SIZE * 2]; char *av[ARGV_SIZE * 2];
int ac = 0; int ac = 0;
char execbuf[MAXPATHLEN]; char execbuf[MAXPGPATH];
char nbbuf[ARGV_SIZE]; char nbbuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE]; char dbbuf[ARGV_SIZE];
@ -2024,7 +2024,7 @@ SSDataBase(bool startup)
StreamClose(ServerSock_UNIX); StreamClose(ServerSock_UNIX);
#endif #endif
StrNCpy(execbuf, Execfile, MAXPATHLEN); StrNCpy(execbuf, Execfile, MAXPGPATH);
av[ac++] = execbuf; av[ac++] = execbuf;
av[ac++] = "-d"; av[ac++] = "-d";

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.56 1999/10/06 06:38:04 inoue Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.57 1999/10/25 03:07:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -591,7 +591,7 @@ mdblindwrt(char *dbstr,
else else
/* this is work arround only !!! */ /* this is work arround only !!! */
{ {
char dbpath[MAXPGPATH + 1]; char dbpath[MAXPGPATH];
Oid id; Oid id;
char *tmpPath; char *tmpPath;
@ -628,7 +628,7 @@ mdblindwrt(char *dbstr,
else else
/* this is work arround only !!! */ /* this is work arround only !!! */
{ {
char dbpath[MAXPGPATH + 1]; char dbpath[MAXPGPATH];
Oid id; Oid id;
char *tmpPath; char *tmpPath;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.135 1999/10/23 03:13:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.136 1999/10/25 03:07:48 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -92,7 +92,6 @@
* ---------------- * ----------------
*/ */
/*static bool EnableRewrite = true; , never changes why have it*/
CommandDest whereToSendOutput = Debug; CommandDest whereToSendOutput = Debug;
/* Define status buffer needed by PS_SET_STATUS */ /* Define status buffer needed by PS_SET_STATUS */
@ -114,8 +113,6 @@ int dontExecute = 0;
static int ShowStats; static int ShowStats;
static bool IsEmptyQuery = false; static bool IsEmptyQuery = false;
char relname[80]; /* current relation name */
/* note: these declarations had better match tcopprot.h */ /* note: these declarations had better match tcopprot.h */
DLLIMPORT sigjmp_buf Warn_restart; DLLIMPORT sigjmp_buf Warn_restart;
@ -126,7 +123,7 @@ extern int NBuffers;
static bool EchoQuery = false; /* default don't echo */ static bool EchoQuery = false; /* default don't echo */
time_t tim; time_t tim;
char pg_pathname[256]; char pg_pathname[MAXPGPATH];
FILE *StatFp; FILE *StatFp;
/* ---------------- /* ----------------
@ -1359,8 +1356,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
proc_exit(1); proc_exit(1);
} }
BaseInit(); BaseInit();
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR); snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR); DataDir, SEP_CHAR);
snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
DataDir, SEP_CHAR);
StartupXLOG(); StartupXLOG();
} }
@ -1372,6 +1371,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
SetCharSet(); SetCharSet();
#endif #endif
/* On some systems our dynloader code needs the executable's pathname */
if (FindExec(pg_pathname, argv[0], "postgres") < 0) if (FindExec(pg_pathname, argv[0], "postgres") < 0)
elog(FATAL, "%s: could not locate executable, bailing out...", elog(FATAL, "%s: could not locate executable, bailing out...",
argv[0]); argv[0]);
@ -1494,7 +1494,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.135 $ $Date: 1999/10/23 03:13:22 $\n"); puts("$Revision: 1.136 $ $Date: 1999/10/25 03:07:48 $\n");
} }
/* /*

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.22 1999/07/17 20:17:55 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.23 1999/10/25 03:07:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -31,7 +31,7 @@ filename_in(char *file)
* (shexpand) * (shexpand)
*/ */
str = (char *) palloc(MAXPATHLEN * sizeof(*str)); str = (char *) palloc(MAXPGPATH);
str[0] = '\0'; str[0] = '\0';
if (file[0] == '~') if (file[0] == '~')
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.50 1999/10/25 03:07:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -415,7 +415,6 @@ DebugFileOpen(void)
if (OutputFileName[0]) if (OutputFileName[0])
{ {
OutputFileName[MAXPGPATH - 1] = '\0';
if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY,
0666)) < 0) 0666)) < 0)
elog(FATAL, "DebugFileOpen: open of %s: %m", elog(FATAL, "DebugFileOpen: open of %s: %m",
@ -448,7 +447,8 @@ DebugFileOpen(void)
fd = fileno(stderr); fd = fileno(stderr);
if (fcntl(fd, F_GETFD, 0) < 0) if (fcntl(fd, F_GETFD, 0) < 0)
{ {
sprintf(OutputFileName, "%s/pg.errors.%d", DataDir, (int) MyProcPid); snprintf(OutputFileName, MAXPGPATH, "%s%cpg.errors.%d",
DataDir, SEP_CHAR, (int) MyProcPid);
fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, 0666); fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, 0666);
} }
if (fd < 0) if (fd < 0)

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.51 1999/10/06 21:58:10 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.52 1999/10/25 03:07:51 tgl Exp $
* *
* NOTES * NOTES
* InitPostgres() is the function called from PostgresMain * InitPostgres() is the function called from PostgresMain
@ -100,7 +100,7 @@ static void
InitMyDatabaseInfo(char *name) InitMyDatabaseInfo(char *name)
{ {
char *path, char *path,
myPath[MAXPGPATH + 1]; myPath[MAXPGPATH];
SetDatabaseName(name); SetDatabaseName(name);
GetRawDatabaseInfo(name, &MyDatabaseId, myPath); GetRawDatabaseInfo(name, &MyDatabaseId, myPath);
@ -143,10 +143,9 @@ static void
VerifySystemDatabase() VerifySystemDatabase()
{ {
char *reason; char *reason;
/* Failure reason returned by some function. NULL if no failure */ /* Failure reason returned by some function. NULL if no failure */
int fd; int fd;
char errormsg[1000]; char errormsg[MAXPGPATH+100];
errormsg[0] = '\0'; errormsg[0] = '\0';
@ -155,20 +154,21 @@ VerifySystemDatabase()
#else #else
if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1) if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1)
#endif #endif
sprintf(errormsg, "Database system does not exist. " snprintf(errormsg, sizeof(errormsg),
"PGDATA directory '%s' not found.\n\tNormally, you " "Database system does not exist. "
"create a database system by running initdb.", "PGDATA directory '%s' not found.\n\tNormally, you "
DataDir); "create a database system by running initdb.",
DataDir);
else else
{ {
close(fd); close(fd);
ValidatePgVersion(DataDir, &reason); ValidatePgVersion(DataDir, &reason);
if (reason != NULL) if (reason != NULL)
sprintf(errormsg, snprintf(errormsg, sizeof(errormsg),
"InitPostgres could not validate that the database" "InitPostgres could not validate that the database"
" system version is compatible with this level of" " system version is compatible with this level of"
" Postgres.\n\tYou may need to run initdb to create" " Postgres.\n\tYou may need to run initdb to create"
" a new database system.\n\t%s", reason); " a new database system.\n\t%s", reason);
} }
if (errormsg[0] != '\0') if (errormsg[0] != '\0')
elog(FATAL, errormsg); elog(FATAL, errormsg);
@ -185,7 +185,7 @@ VerifyMyDatabase()
/* Failure reason returned by some function. NULL if no failure */ /* Failure reason returned by some function. NULL if no failure */
char *reason; char *reason;
int fd; int fd;
char errormsg[1000]; char errormsg[MAXPGPATH+100];
name = DatabaseName; name = DatabaseName;
myPath = DatabasePath; myPath = DatabasePath;
@ -195,26 +195,26 @@ VerifyMyDatabase()
#else #else
if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1) if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1)
#endif #endif
sprintf(errormsg, snprintf(errormsg, sizeof(errormsg),
"Database '%s' does not exist." "Database '%s' does not exist."
"\n\tWe know this because the directory '%s' does not exist." "\n\tWe know this because the directory '%s' does not exist."
"\n\tYou can create a database with the SQL command" "\n\tYou can create a database with the SQL command"
" CREATE DATABASE.\n\tTo see what databases exist," " CREATE DATABASE.\n\tTo see what databases exist,"
" look at the subdirectories of '%s/base/'.", " look at the subdirectories of '%s/base/'.",
name, myPath, DataDir); name, myPath, DataDir);
else else
{ {
close(fd); close(fd);
ValidatePgVersion(myPath, &reason); ValidatePgVersion(myPath, &reason);
if (reason != NULL) if (reason != NULL)
sprintf(errormsg, snprintf(errormsg, sizeof(errormsg),
"InitPostgres could not validate that the database" "InitPostgres could not validate that the database"
" version is compatible with this level of Postgres" " version is compatible with this level of Postgres"
"\n\teven though the database system as a whole" "\n\teven though the database system as a whole"
" appears to be at a compatible level." " appears to be at a compatible level."
"\n\tYou may need to recreate the database with SQL" "\n\tYou may need to recreate the database with SQL"
" commands DROP DATABASE and CREATE DATABASE." " commands DROP DATABASE and CREATE DATABASE."
"\n\t%s", reason); "\n\t%s", reason);
else else
{ {
@ -229,10 +229,10 @@ VerifyMyDatabase()
rc = chdir(myPath); rc = chdir(myPath);
if (rc < 0) if (rc < 0)
sprintf(errormsg, snprintf(errormsg, sizeof(errormsg),
"InitPostgres unable to change " "InitPostgres unable to change "
"current directory to '%s', errno = %s (%d).", "current directory to '%s', errno = %s (%d).",
myPath, strerror(errno), errno); myPath, strerror(errno), errno);
else else
errormsg[0] = '\0'; errormsg[0] = '\0';
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.30 1999/09/24 00:25:04 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.31 1999/10/25 03:07:52 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -30,7 +30,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
{ {
Oid dbowner, Oid dbowner,
dbid; dbid;
char dbpath[MAXPGPATH + 1]; char dbpath[MAXPGPATH];
text *dbtext; text *dbtext;
Relation dbrel; Relation dbrel;
@ -86,8 +86,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
owner = palloc(sizeof(Oid)); owner = palloc(sizeof(Oid));
*owner = dbowner; *owner = dbowner;
path = palloc(strlen(dbpath) + 1); path = pstrdup(dbpath); /* doesn't do the right thing! */
strcpy(path, dbpath);
return FALSE; return FALSE;
} /* GetDatabaseInfo() */ } /* GetDatabaseInfo() */
@ -97,46 +96,53 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
char * char *
ExpandDatabasePath(char *dbpath) ExpandDatabasePath(char *dbpath)
{ {
char *path; char buf[MAXPGPATH];
char *cp; char *cp;
char buf[MAXPGPATH + 1]; char *envvar;
int len;
if (strlen(dbpath) >= MAXPGPATH)
return NULL; /* ain't gonna fit nohow */
/* leading path delimiter? then already absolute path */ /* leading path delimiter? then already absolute path */
if (*dbpath == SEP_CHAR) if (*dbpath == SEP_CHAR)
{ {
#ifdef ALLOW_ABSOLUTE_DBPATHS #ifdef ALLOW_ABSOLUTE_DBPATHS
cp = strrchr(dbpath, SEP_CHAR); cp = strrchr(dbpath, SEP_CHAR);
strncpy(buf, dbpath, (cp - dbpath)); len = cp - dbpath;
sprintf(&buf[cp - dbpath], "%cbase%c%s", SEP_CHAR, SEP_CHAR, (cp + 1)); strncpy(buf, dbpath, len);
snprintf(&buf[len], MAXPGPATH-len, "%cbase%c%s",
SEP_CHAR, SEP_CHAR, (cp + 1));
#else #else
return NULL; return NULL;
#endif #endif
} }
/* path delimiter somewhere? then has leading environment variable */ /* path delimiter somewhere? then has leading environment variable */
else if (strchr(dbpath, SEP_CHAR) != NULL) else if ((cp = strchr(dbpath, SEP_CHAR)) != NULL)
{ {
cp = strchr(dbpath, SEP_CHAR); len = cp - dbpath;
strncpy(buf, dbpath, (cp - dbpath)); strncpy(buf, dbpath, len);
buf[cp - dbpath] = '\0'; buf[len] = '\0';
path = getenv(buf); envvar = getenv(buf);
/* /*
* problem getting environment variable? let calling routine * problem getting environment variable? let calling routine
* handle it * handle it
*/ */
if (path == NULL) if (envvar == NULL)
return path; return envvar;
sprintf(buf, "%s%cbase%c%s", path, SEP_CHAR, SEP_CHAR, (cp + 1)); snprintf(buf, sizeof(buf), "%s%cbase%c%s",
envvar, SEP_CHAR, SEP_CHAR, (cp + 1));
} }
/* no path delimiter? then add the default path prefixes */
else else
sprintf(buf, "%s%cbase%c%s", DataDir, SEP_CHAR, SEP_CHAR, dbpath); {
/* no path delimiter? then add the default path prefix */
snprintf(buf, sizeof(buf), "%s%cbase%c%s",
DataDir, SEP_CHAR, SEP_CHAR, dbpath);
}
path = palloc(strlen(buf) + 1); return pstrdup(buf);
strcpy(path, buf);
return path;
} /* ExpandDatabasePath() */ } /* ExpandDatabasePath() */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.193 1999/10/23 01:31:32 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.194 1999/10/25 03:07:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -19,7 +19,6 @@
#include <windows.h> #include <windows.h>
#include <io.h> #include <io.h>
#else #else
#include <sys/param.h> /* for MAXPATHLEN */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -76,7 +75,6 @@
#define open(x,y,z) _open(x,y,z) #define open(x,y,z) _open(x,y,z)
#define strcasecmp(x,y) stricmp(x,y) #define strcasecmp(x,y) stricmp(x,y)
#define pqsignal(x,y) #define pqsignal(x,y)
#define MAXPATHLEN MAX_PATH
#define R_OK 0 #define R_OK 0
/* getopt is not in the standard includes on Win32 */ /* getopt is not in the standard includes on Win32 */
@ -1495,7 +1493,7 @@ do_copy(const char *args, PsqlSettings *pset)
bool from; bool from;
/* The direction of the copy is from a file to a table. */ /* The direction of the copy is from a file to a table. */
char file[MAXPATHLEN + 1]; char file[MAXPGPATH];
/* The pathname of the file from/to which we copy */ /* The pathname of the file from/to which we copy */
char table[NAMEDATALEN]; char table[NAMEDATALEN];

View File

@ -203,6 +203,18 @@
/* #define NO_SECURITY */ /* #define NO_SECURITY */
/* #define OLD_REWRITE */ /* #define OLD_REWRITE */
/*
* MAXPGPATH: standard size of a pathname buffer in Postgres (hence,
* maximum usable pathname length is one less).
*
* We'd use a standard system header symbol for this, if there weren't
* so many to choose from: MAXPATHLEN, _POSIX_PATH_MAX, MAX_PATH, PATH_MAX
* are all defined by different "standards", and often have different
* values on the same platform! So we just punt and use a reasonably
* generous setting here.
*/
#define MAXPGPATH 1024
/* /*
*------------------------------------------------------------------------ *------------------------------------------------------------------------
* The following is set using configure. * The following is set using configure.

View File

@ -1,9 +1,3 @@
#include <limits.h> /* For _POSIX_PATH_MAX */
#ifndef MAXPATHLEN
#define MAXPATHLEN _POSIX_PATH_MAX
#endif
#ifndef NOFILE #ifndef NOFILE
#define NOFILE NOFILES_MIN #define NOFILE NOFILES_MIN
#endif #endif

View File

@ -2,6 +2,3 @@
#define NEED_SIG_JMP #define NEED_SIG_JMP
#define USES_WINSOCK #define USES_WINSOCK
#define NOFILE 100 #define NOFILE 100
#ifndef MAXPATHLEN
#define MAXPATHLEN 250
#endif

View File

@ -6,7 +6,7 @@
* *
* Copyright (c) 1995, Regents of the University of California * Copyright (c) 1995, Regents of the University of California
* *
* $Id: postgres.h,v 1.27 1999/10/23 03:13:30 tgl Exp $ * $Id: postgres.h,v 1.28 1999/10/25 03:07:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -28,7 +28,7 @@
* 2) varlena and array types * 2) varlena and array types
* 3) TransactionId and CommandId * 3) TransactionId and CommandId
* 4) genbki macros used by catalog/pg_xxx.h files * 4) genbki macros used by catalog/pg_xxx.h files
* 5) random CSIGNBIT, MAXPGPATH, STATUS macros * 5) random stuff
* *
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
@ -158,9 +158,6 @@ typedef uint32 CommandId;
/* msb for char */ /* msb for char */
#define CSIGNBIT (0x80) #define CSIGNBIT (0x80)
/* this should probably be somewhere else */
#define MAXPGPATH 128
#define STATUS_OK (0) #define STATUS_OK (0)
#define STATUS_ERROR (-1) #define STATUS_ERROR (-1)
#define STATUS_NOT_FOUND (-2) #define STATUS_NOT_FOUND (-2)

View File

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: dynamic_loader.h,v 1.12 1999/07/15 23:04:21 momjian Exp $ * $Id: dynamic_loader.h,v 1.13 1999/10/25 03:07:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -14,7 +14,6 @@
#define DYNAMIC_LOADER_H #define DYNAMIC_LOADER_H
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> /* For MAXPATHLEN */
/* we need this include because port files use them */ /* we need this include because port files use them */
#include "postgres.h" #include "postgres.h"
@ -30,7 +29,7 @@
typedef struct df_files typedef struct df_files
{ {
char filename[MAXPATHLEN]; /* Full pathname of file */ char filename[MAXPGPATH]; /* Full pathname of file */
dev_t device; /* Device file is on */ dev_t device; /* Device file is on */
ino_t inode; /* Inode number of file */ ino_t inode; /* Inode number of file */
void *handle; /* a handle for pg_dl* functions */ void *handle; /* a handle for pg_dl* functions */

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.45 1999/10/22 23:14:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.46 1999/10/25 03:07:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -22,11 +22,6 @@
#include "postgres.h" #include "postgres.h"
#ifndef PATH_MAX
#include <sys/param.h>
#define PATH_MAX MAXPATHLEN
#endif
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
@ -527,7 +522,7 @@ cppline {space}*#.*(\\{space}*\n)*\n*
<incl>[^ \t\n]+ { /* got the include file name */ <incl>[^ \t\n]+ { /* got the include file name */
struct _yy_buffer *yb; struct _yy_buffer *yb;
struct _include_path *ip; struct _include_path *ip;
char inc_file[PATH_MAX]; char inc_file[MAXPGPATH];
yb = mm_alloc(sizeof(struct _yy_buffer)); yb = mm_alloc(sizeof(struct _yy_buffer));
@ -544,7 +539,7 @@ cppline {space}*#.*(\\{space}*\n)*\n*
yyin = NULL; yyin = NULL;
for (ip = include_paths; yyin == NULL && ip != NULL; ip = ip->next) for (ip = include_paths; yyin == NULL && ip != NULL; ip = ip->next)
{ {
if (strlen(ip->path) + strlen(yytext) + 3 > PATH_MAX) if (strlen(ip->path) + strlen(yytext) + 3 > MAXPGPATH)
{ {
fprintf(stderr, "Error: Path %s/%s is too long in line %d, skipping.\n", ip->path, yytext, yylineno); fprintf(stderr, "Error: Path %s/%s is too long in line %d, skipping.\n", ip->path, yytext, yylineno);
continue; continue;

View File

@ -9,7 +9,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.33 1999/08/31 01:37:36 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.34 1999/10/25 03:08:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -127,7 +127,7 @@ pg_krb4_init()
*/ */
if (realm = getenv("PGREALM")) if (realm = getenv("PGREALM"))
{ {
char tktbuf[MAXPATHLEN]; char tktbuf[MAXPGPATH];
(void) sprintf(tktbuf, "%s@%s", tkt_string(), realm); (void) sprintf(tktbuf, "%s@%s", tkt_string(), realm);
krb_set_tkt_string(tktbuf); krb_set_tkt_string(tktbuf);
@ -272,7 +272,7 @@ pg_krb5_init(void)
krb5_error_code code; krb5_error_code code;
char *realm, char *realm,
*defname; *defname;
char tktbuf[MAXPATHLEN]; char tktbuf[MAXPGPATH];
static krb5_ccache ccache = (krb5_ccache) NULL; static krb5_ccache ccache = (krb5_ccache) NULL;
if (ccache) if (ccache)

View File

@ -36,11 +36,6 @@
#define FALSE ((BOOL)0) #define FALSE ((BOOL)0)
#endif #endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#else
#define MAXPATHLEN 255
#endif
DWORD DWORD
GetPrivateProfileString(char *theSection, // section name GetPrivateProfileString(char *theSection, // section name
@ -50,7 +45,7 @@ GetPrivateProfileString(char *theSection, // section name
size_t theReturnBufferLength, // byte length of return buffer size_t theReturnBufferLength, // byte length of return buffer
char *theIniFileName) // pathname of ini file to search char *theIniFileName) // pathname of ini file to search
{ {
char buf[MAXPATHLEN+1]; char buf[MAXPGPATH];
char* ptr = 0; char* ptr = 0;
FILE* aFile = 0; FILE* aFile = 0;
size_t aLength; size_t aLength;
@ -70,8 +65,8 @@ GetPrivateProfileString(char *theSection, // section name
if( ptr == NULL) if( ptr == NULL)
{ {
if( MAXPATHLEN < j ) if( MAXPGPATH-1 < j )
theIniFileName[MAXPATHLEN] = '\0'; theIniFileName[MAXPGPATH-1] = '\0';
sprintf(buf,"%s",theIniFileName); sprintf(buf,"%s",theIniFileName);
} }
@ -84,12 +79,12 @@ GetPrivateProfileString(char *theSection, // section name
* the file won't be found and thus the default value will be * the file won't be found and thus the default value will be
* returned. * returned.
*/ */
if( MAXPATHLEN < strlen(ptr) + j ) if( MAXPGPATH-1 < strlen(ptr) + j )
{ {
if( MAXPATHLEN < strlen(ptr) ) if( MAXPGPATH-1 < strlen(ptr) )
ptr[MAXPATHLEN] = '\0'; ptr[MAXPGPATH-1] = '\0';
else else
theIniFileName[MAXPATHLEN-strlen(ptr)] = '\0'; theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
} }
sprintf( buf, "%s/%s",ptr,theIniFileName ); sprintf( buf, "%s/%s",ptr,theIniFileName );
@ -323,7 +318,7 @@ WritePrivateProfileString(char *theSection, // section name
char *theBuffer, // input buffer char *theBuffer, // input buffer
char *theIniFileName) // pathname of ini file to write char *theIniFileName) // pathname of ini file to write
{ {
char buf[MAXPATHLEN+1]; char buf[MAXPGPATH];
char* ptr = 0; char* ptr = 0;
FILE* aFile = 0; FILE* aFile = 0;
size_t aLength; size_t aLength;
@ -349,8 +344,8 @@ WritePrivateProfileString(char *theSection, // section name
if( ptr == NULL) if( ptr == NULL)
{ {
if( MAXPATHLEN < j ) if( MAXPGPATH-1 < j )
theIniFileName[MAXPATHLEN] = '\0'; theIniFileName[MAXPGPATH-1] = '\0';
sprintf(buf,"%s",theIniFileName); sprintf(buf,"%s",theIniFileName);
} }
@ -363,12 +358,12 @@ WritePrivateProfileString(char *theSection, // section name
// the file won't be found and thus the default value will be // the file won't be found and thus the default value will be
// returned. // returned.
// //
if( MAXPATHLEN < strlen(ptr) + j ) if( MAXPGPATH-1 < strlen(ptr) + j )
{ {
if( MAXPATHLEN < strlen(ptr) ) if( MAXPGPATH-1 < strlen(ptr) )
ptr[MAXPATHLEN] = '\0'; ptr[MAXPGPATH-1] = '\0';
else else
theIniFileName[MAXPATHLEN-strlen(ptr)] = '\0'; theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
} }
sprintf( buf, "%s/%s",ptr,theIniFileName ); sprintf( buf, "%s/%s",ptr,theIniFileName );

View File

@ -32,7 +32,6 @@ extern GLOBAL_VALUES globals;
// Constants --------------------------------------------------------------- // Constants ---------------------------------------------------------------
#define MIN(x,y) ((x) < (y) ? (x) : (y)) #define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAXPATHLEN (255+1) // Max path length
#define MAXKEYLEN (15+1) // Max keyword length #define MAXKEYLEN (15+1) // Max keyword length
#define MAXDESC (255+1) // Max description length #define MAXDESC (255+1) // Max description length
#define MAXDSNAME (32+1) // Max data source name length #define MAXDSNAME (32+1) // Max data source name length
@ -323,7 +322,7 @@ LPCSTR lpsz;
LPCSTR lpszStart; LPCSTR lpszStart;
char aszKey[MAXKEYLEN]; char aszKey[MAXKEYLEN];
int cbKey; int cbKey;
char value[MAXPATHLEN]; char value[MAXPGPATH];
memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo)); memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
@ -352,7 +351,7 @@ char value[MAXPATHLEN];
// lpsetupdlg->aAttr[iElement].fSupplied = TRUE; // lpsetupdlg->aAttr[iElement].fSupplied = TRUE;
_fmemcpy(value, lpszStart, MIN(lpsz-lpszStart+1, MAXPATHLEN)); _fmemcpy(value, lpszStart, MIN(lpsz-lpszStart+1, MAXPGPATH));
mylog("aszKey='%s', value='%s'\n", aszKey, value); mylog("aszKey='%s', value='%s'\n", aszKey, value);
@ -384,8 +383,8 @@ LPCSTR lpszDSN; // Pointer to da
{ {
if (hwndParent) if (hwndParent)
{ {
char szBuf[MAXPATHLEN]; char szBuf[MAXPGPATH];
char szMsg[MAXPATHLEN]; char szMsg[MAXPGPATH];
LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf)); LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf));
wsprintf(szMsg, szBuf, lpszDSN); wsprintf(szMsg, szBuf, lpszDSN);

View File

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