Standardize on MAXPGPATH as the size of a file pathname buffer,
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 25 Oct 1999 03:08:03 +0000 (03:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 25 Oct 1999 03:08:03 +0000 (03:08 +0000)
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.

22 files changed:
src/backend/access/transam/xlog.c
src/backend/bootstrap/bootstrap.c
src/backend/commands/dbcommands.c
src/backend/libpq/pqcomm.c
src/backend/postmaster/postmaster.c
src/backend/storage/smgr/md.c
src/backend/tcop/postgres.c
src/backend/utils/adt/filename.c
src/backend/utils/error/elog.c
src/backend/utils/init/postinit.c
src/backend/utils/misc/database.c
src/bin/psql/psql.c
src/include/config.h.in
src/include/port/sco.h
src/include/port/win32.h
src/include/postgres.h
src/include/utils/dynamic_loader.h
src/interfaces/ecpg/preproc/pgc.l
src/interfaces/libpq/fe-auth.c
src/interfaces/odbc/gpps.c
src/interfaces/odbc/setup.c
src/utils/version.c

index e8e85b111387f552f6a04961697e12a933299aa6..05eb5b0706fc9e9713fb0685dc94d3e31cfc3dad 100644 (file)
@@ -5,7 +5,7 @@
  *
  * 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       CreateCheckPoint(bool shutdown);
 
-char       XLogDir[MAXPGPATH+1];
-char       ControlFilePath[MAXPGPATH+1];
+char       XLogDir[MAXPGPATH];
+char       ControlFilePath[MAXPGPATH];
 uint32     XLOGbuffers = 0;
 XLogRecPtr MyLastRecPtr = {0, 0};
 bool       StopIfError = false;
@@ -147,8 +147,8 @@ typedef struct CheckPoint
 #define    XLogFileSize    (XLogLastSeg * XLogSegSize)
 
 #define    XLogFileName(path, log, seg)    \
-           sprintf(path, "%.*s%c%08X%08X",     \
-           MAXPGPATH, XLogDir, SEP_CHAR, log, seg)
+           snprintf(path, MAXPGPATH, "%s%c%08X%08X",   \
+                    XLogDir, SEP_CHAR, log, seg)
 
 #define    PrevBufIdx(curridx)     \
        ((curridx == 0) ? XLogCtl->XLogCacheBlck : (curridx - 1))
@@ -718,7 +718,7 @@ XLogWrite(char *buffer)
 static int
 XLogFileInit(uint32 log, uint32 seg)
 {
-   char    path[MAXPGPATH+1];
+   char    path[MAXPGPATH];
    int     fd;
 
    XLogFileName(path, log, seg);
@@ -760,7 +760,7 @@ tryAgain:
 static int
 XLogFileOpen(uint32 log, uint32 seg, bool econt)
 {
-   char    path[MAXPGPATH+1];
+   char    path[MAXPGPATH];
    int     fd;
 
    XLogFileName(path, log, seg);
@@ -1067,7 +1067,7 @@ next_record_is_invalid:;
        readId++;
    }
    {
-       char    path[MAXPGPATH+1];
+       char    path[MAXPGPATH];
 
        XLogFileName(path, readId, readSeg);
        unlink(path);
index 8871e14835a27a7413f8e4c8b5150667605416b5..35797e82d255c187b8f107dcb40f30d60ec0136b 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (c) 1994, Regents of the University of California
  *
  * 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)
    {
-       sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
-       sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
+       snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
+                DataDir, SEP_CHAR);
+       snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
+                DataDir, SEP_CHAR);
    }
 
    if (IsUnderPostmaster && xloginit)
index b243dd173b19fa2a64a9898abb30c0a7de163ab8..75a917092a002054e3b3dca073bfe8e55b34f449 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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;
    int4        user_id;
-   char        buf[512];
+   char        buf[MAXPGPATH + 100];
    char       *lp,
-               loc[512];
+               loc[MAXPGPATH];
 
    /*
     * 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)
            *(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
        strcpy(loc, dbname);
@@ -71,11 +71,11 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
    if (mkdir(lp, S_IRWXU) != 0)
        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);
    system(buf);
 
-   snprintf(buf, 512,
+   snprintf(buf, sizeof(buf),
           "insert into pg_database (datname, datdba, encoding, datpath)"
          " values ('%s', '%d', '%d', '%s');", dbname, user_id, encoding,
             loc);
@@ -89,8 +89,8 @@ destroydb(char *dbname, CommandDest dest)
    int4        user_id;
    Oid         db_id;
    char       *path,
-               dbpath[MAXPGPATH + 1],
-               buf[MAXPGPATH + 50];
+               dbpath[MAXPGPATH],
+               buf[MAXPGPATH + 100];
    Relation    pgdbrel;
    HeapScanDesc pgdbscan;
    ScanKeyData key;
@@ -233,7 +233,7 @@ check_permissions(char *command,
    bool        use_super;
    char       *userName;
    text       *dbtext;
-   char        path[MAXPGPATH + 1];
+   char        path[MAXPGPATH];
 
    userName = GetPgUserName();
    utup = SearchSysCacheTuple(USENAME,
@@ -332,7 +332,7 @@ static void
 stop_vacuum(char *dbpath, char *dbname)
 {
 #ifdef NOT_USED
-   char        filename[MAXPGPATH + 1];
+   char        filename[MAXPGPATH];
    FILE       *fp;
    int         pid;
 
index 7fc86d4ede30209e7d3c8d60cdca48a6c6cd509b..44cdbd8984dff4179f160a36b7eac068f56cf3bf 100644 (file)
@@ -28,7 +28,7 @@
  *
  * 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.
  */
 
-static char sock_path[MAXPGPATH + 1] = "";
+static char sock_path[MAXPGPATH];
+
 
 /* StreamDoUnlink()
  * Shutdown routine for backend connection
index 4ac877bbadf95929d354da19b66b46fcd16a7b1e..611e44304800ebb8910a8dbc6aad9dcf27e80257 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * 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
  *
@@ -179,7 +179,7 @@ static time_t   tnow;
 /*
  * Default Values
  */
-static char Execfile[MAXPATHLEN] = "";
+static char Execfile[MAXPGPATH];
 
 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
  */
-static char ExtraOptions[MAXPATHLEN] = "";
+static char ExtraOptions[MAXPGPATH];
 
 /*
  * These globals control the behavior of the postmaster in case some
@@ -294,10 +294,10 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
    }
    else
    {
-       char        path[MAXPATHLEN];
+       char        path[MAXPGPATH];
        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);
 #ifndef __CYGWIN32__
        fp = AllocateFile(path, "r");
@@ -446,7 +446,7 @@ PostmasterMain(int argc, char *argv[])
            case 'b':
                /* Set the backend executable file to use. */
                if (!ValidateBinary(optarg))
-                   strcpy(Execfile, optarg);
+                   StrNCpy(Execfile, optarg, MAXPGPATH);
                else
                {
                    fprintf(stderr, "%s: invalid backend \"%s\"\n",
@@ -1698,7 +1698,7 @@ DoBackend(Port *port)
 {
    char       *av[ARGV_SIZE * 2];
    int         ac = 0;
-   char        execbuf[MAXPATHLEN];
+   char        execbuf[MAXPGPATH];
    char        debugbuf[ARGV_SIZE];
    char        protobuf[ARGV_SIZE];
    char        dbbuf[ARGV_SIZE];
@@ -1749,7 +1749,7 @@ DoBackend(Port *port)
     * ----------------
     */
 
-   StrNCpy(execbuf, Execfile, MAXPATHLEN);
+   StrNCpy(execbuf, Execfile, MAXPGPATH);
    av[ac++] = execbuf;
 
    /*
@@ -2013,7 +2013,7 @@ SSDataBase(bool startup)
    {
        char       *av[ARGV_SIZE * 2];
        int         ac = 0;
-       char        execbuf[MAXPATHLEN];
+       char        execbuf[MAXPGPATH];
        char        nbbuf[ARGV_SIZE];
        char        dbbuf[ARGV_SIZE];
 
@@ -2024,7 +2024,7 @@ SSDataBase(bool startup)
        StreamClose(ServerSock_UNIX);
 #endif
 
-       StrNCpy(execbuf, Execfile, MAXPATHLEN);
+       StrNCpy(execbuf, Execfile, MAXPGPATH);
        av[ac++] = execbuf;
 
        av[ac++] = "-d";
index 6d8425c4bd6f2d29951beec832cd935f66cf5e6c..c76f533511320cb2e311dc93de02d44431881be5 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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
 /* this is work arround only !!! */
    {
-       char        dbpath[MAXPGPATH + 1];
+       char        dbpath[MAXPGPATH];
        Oid         id;
        char       *tmpPath;
 
@@ -628,7 +628,7 @@ mdblindwrt(char *dbstr,
    else
 /* this is work arround only !!! */
    {
-       char        dbpath[MAXPGPATH + 1];
+       char        dbpath[MAXPGPATH];
        Oid         id;
        char       *tmpPath;
 
index ddf6c280e4fb0ed53c7c26691a593ca86c2cd281..a73344e932a8bf66079c971c56ea28a2053e596c 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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
  *   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;
 
 /* Define status buffer needed by PS_SET_STATUS */
@@ -114,8 +113,6 @@ int         dontExecute = 0;
 static int ShowStats;
 static bool IsEmptyQuery = false;
 
-char       relname[80];        /* current relation name */
-
 /* note: these declarations had better match tcopprot.h */
 DLLIMPORT sigjmp_buf Warn_restart;
 
@@ -126,7 +123,7 @@ extern int  NBuffers;
 
 static bool    EchoQuery = false;      /* default don't echo */
 time_t     tim;
-char       pg_pathname[256];
+char       pg_pathname[MAXPGPATH];
 FILE      *StatFp;
 
 /* ----------------
@@ -1359,8 +1356,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
            proc_exit(1);
        }
        BaseInit();
-       sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
-       sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
+       snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
+                DataDir, SEP_CHAR);
+       snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
+                DataDir, SEP_CHAR);
        StartupXLOG();
    }
 
@@ -1372,6 +1371,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
    SetCharSet();
 #endif
 
+   /* On some systems our dynloader code needs the executable's pathname */
    if (FindExec(pg_pathname, argv[0], "postgres") < 0)
        elog(FATAL, "%s: could not locate executable, bailing out...",
             argv[0]);
@@ -1494,7 +1494,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
    if (!IsUnderPostmaster)
    {
        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");
    }
 
    /*
index eb705b9f6b4b6de0c23d5d8f9bac90b232904a4f..0a3871280dc64160a41b095b45b60c887dc6326f 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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)
     */
 
-   str = (char *) palloc(MAXPATHLEN * sizeof(*str));
+   str = (char *) palloc(MAXPGPATH);
    str[0] = '\0';
    if (file[0] == '~')
    {
index 342a1029d1639ea100a6788acca86f92f597532d..247cf1c724a5c9f8c72af3bf83598d0d719fd459 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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])
    {
-       OutputFileName[MAXPGPATH - 1] = '\0';
        if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY,
                       0666)) < 0)
            elog(FATAL, "DebugFileOpen: open of %s: %m",
@@ -448,7 +447,8 @@ DebugFileOpen(void)
    fd = fileno(stderr);
    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);
    }
    if (fd < 0)
index 20db5c34bb71129b7b1f8254c22825962c4bc182..72c87f161964f141f4277fa5fd5f4b9e63fd1158 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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
  *     InitPostgres() is the function called from PostgresMain
@@ -100,7 +100,7 @@ static void
 InitMyDatabaseInfo(char *name)
 {
    char       *path,
-               myPath[MAXPGPATH + 1];
+               myPath[MAXPGPATH];
 
    SetDatabaseName(name);
    GetRawDatabaseInfo(name, &MyDatabaseId, myPath);
@@ -143,10 +143,9 @@ static void
 VerifySystemDatabase()
 {
    char       *reason;
-
    /* Failure reason returned by some function.  NULL if no failure */
    int         fd;
-   char        errormsg[1000];
+   char        errormsg[MAXPGPATH+100];
 
    errormsg[0] = '\0';
 
@@ -155,20 +154,21 @@ VerifySystemDatabase()
 #else
    if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1)
 #endif
-       sprintf(errormsg, "Database system does not exist.  "
-               "PGDATA directory '%s' not found.\n\tNormally, you "
-               "create a database system by running initdb.",
-               DataDir);
+       snprintf(errormsg, sizeof(errormsg),
+                "Database system does not exist.  "
+                "PGDATA directory '%s' not found.\n\tNormally, you "
+                "create a database system by running initdb.",
+                DataDir);
    else
    {
        close(fd);
        ValidatePgVersion(DataDir, &reason);
        if (reason != NULL)
-           sprintf(errormsg,
-                   "InitPostgres could not validate that the database"
-                   " system version is compatible with this level of"
-                   " Postgres.\n\tYou may need to run initdb to create"
-                   " a new database system.\n\t%s", reason);
+           snprintf(errormsg, sizeof(errormsg),
+                    "InitPostgres could not validate that the database"
+                    " system version is compatible with this level of"
+                    " Postgres.\n\tYou may need to run initdb to create"
+                    " a new database system.\n\t%s", reason);
    }
    if (errormsg[0] != '\0')
        elog(FATAL, errormsg);
@@ -185,7 +185,7 @@ VerifyMyDatabase()
    /* Failure reason returned by some function.  NULL if no failure */
    char       *reason;
    int         fd;
-   char        errormsg[1000];
+   char        errormsg[MAXPGPATH+100];
 
    name = DatabaseName;
    myPath = DatabasePath;
@@ -195,26 +195,26 @@ VerifyMyDatabase()
 #else
    if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1)
 #endif
-       sprintf(errormsg,
-               "Database '%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"
-               " CREATE DATABASE.\n\tTo see what databases exist,"
-               " look at the subdirectories of '%s/base/'.",
-               name, myPath, DataDir);
+       snprintf(errormsg, sizeof(errormsg),
+                "Database '%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"
+                " CREATE DATABASE.\n\tTo see what databases exist,"
+                " look at the subdirectories of '%s/base/'.",
+                name, myPath, DataDir);
    else
    {
        close(fd);
        ValidatePgVersion(myPath, &reason);
        if (reason != NULL)
-           sprintf(errormsg,
-                   "InitPostgres could not validate that the database"
-                   " version is compatible with this level of Postgres"
-                   "\n\teven though the database system as a whole"
-                   " appears to be at a compatible level."
-                   "\n\tYou may need to recreate the database with SQL"
-                   " commands DROP DATABASE and CREATE DATABASE."
-                   "\n\t%s", reason);
+           snprintf(errormsg, sizeof(errormsg),
+                    "InitPostgres could not validate that the database"
+                    " version is compatible with this level of Postgres"
+                    "\n\teven though the database system as a whole"
+                    " appears to be at a compatible level."
+                    "\n\tYou may need to recreate the database with SQL"
+                    " commands DROP DATABASE and CREATE DATABASE."
+                    "\n\t%s", reason);
        else
        {
 
@@ -229,10 +229,10 @@ VerifyMyDatabase()
 
            rc = chdir(myPath);
            if (rc < 0)
-               sprintf(errormsg,
-                       "InitPostgres unable to change "
-                       "current directory to '%s', errno = %s (%d).",
-                       myPath, strerror(errno), errno);
+               snprintf(errormsg, sizeof(errormsg),
+                        "InitPostgres unable to change "
+                        "current directory to '%s', errno = %s (%d).",
+                        myPath, strerror(errno), errno);
            else
                errormsg[0] = '\0';
        }
index f5ff732b8f2f9dfa967978502febb8364d68003e..cda5cfbdab3a8130912197d47886bf3e800beea3 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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,
                dbid;
-   char        dbpath[MAXPGPATH + 1];
+   char        dbpath[MAXPGPATH];
    text       *dbtext;
 
    Relation    dbrel;
@@ -86,8 +86,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
 
    owner = palloc(sizeof(Oid));
    *owner = dbowner;
-   path = palloc(strlen(dbpath) + 1);
-   strcpy(path, dbpath);
+   path = pstrdup(dbpath);     /* doesn't do the right thing! */
 
    return FALSE;
 }  /* GetDatabaseInfo() */
@@ -97,46 +96,53 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
 char *
 ExpandDatabasePath(char *dbpath)
 {
-   char       *path;
+   char        buf[MAXPGPATH];
    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 */
    if (*dbpath == SEP_CHAR)
    {
 #ifdef ALLOW_ABSOLUTE_DBPATHS
        cp = strrchr(dbpath, SEP_CHAR);
-       strncpy(buf, dbpath, (cp - dbpath));
-       sprintf(&buf[cp - dbpath], "%cbase%c%s", SEP_CHAR, SEP_CHAR, (cp + 1));
+       len = cp - dbpath;
+       strncpy(buf, dbpath, len);
+       snprintf(&buf[len], MAXPGPATH-len, "%cbase%c%s",
+                SEP_CHAR, SEP_CHAR, (cp + 1));
 #else
        return NULL;
 #endif
    }
    /* 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);
-       strncpy(buf, dbpath, (cp - dbpath));
-       buf[cp - dbpath] = '\0';
-       path = getenv(buf);
+       len = cp - dbpath;
+       strncpy(buf, dbpath, len);
+       buf[len] = '\0';
+       envvar = getenv(buf);
 
        /*
         * problem getting environment variable? let calling routine
         * handle it
         */
-       if (path == NULL)
-           return path;
+       if (envvar == NULL)
+           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
-       sprintf(buf, "%s%cbase%c%s", DataDir, SEP_CHAR, SEP_CHAR, dbpath);
-
-   path = palloc(strlen(buf) + 1);
-   strcpy(path, buf);
+   {
+       /* no path delimiter? then add the default path prefix */
+       snprintf(buf, sizeof(buf), "%s%cbase%c%s",
+                DataDir, SEP_CHAR, SEP_CHAR, dbpath);
+   }
 
-   return path;
+   return pstrdup(buf);
 }  /* ExpandDatabasePath() */
 
 
index 89bd8e8e1f239da67ce9dd0acc57a2d4251fc2fd..e61ac491446e4f8798aad59af4e93e0eebe84123 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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 <io.h>
 #else
-#include <sys/param.h>         /* for MAXPATHLEN */
 #include <sys/ioctl.h>
 #include <unistd.h>
 #endif
@@ -76,7 +75,6 @@
 #define open(x,y,z) _open(x,y,z)
 #define strcasecmp(x,y) stricmp(x,y)
 #define pqsignal(x,y)
-#define MAXPATHLEN MAX_PATH
 #define R_OK 0
 
 /* getopt is not in the standard includes on Win32 */
@@ -1495,7 +1493,7 @@ do_copy(const char *args, PsqlSettings *pset)
    bool        from;
 
    /* 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 */
    char        table[NAMEDATALEN];
index e36220e940ca4ece0f3c3a2238d13d31ed41148d..698526e7da2bfd3f55fc16bab0f16239cf8ca255 100644 (file)
 /* #define NO_SECURITY        */
 /* #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.  
index 074c65339790bbac5654dacbbe02541c3921efc9..daba7b5a708156e366bd24cd91be68801d9d42a1 100644 (file)
@@ -1,9 +1,3 @@
-#include <limits.h>                /* For _POSIX_PATH_MAX */
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN     _POSIX_PATH_MAX
-#endif
-
 #ifndef NOFILE
 #define NOFILE         NOFILES_MIN
 #endif
index 7e21816b2b6707df40db49f8d9ed22ddf52bd90b..59bd010afc829cd2f3fa1d040168ce3fa23d14f5 100644 (file)
@@ -2,6 +2,3 @@
 #define NEED_SIG_JMP
 #define USES_WINSOCK
 #define NOFILE       100
-#ifndef MAXPATHLEN
-#define MAXPATHLEN   250
-#endif
index 5835f4448661280145dcf84cce791e03332d8afb..ddc84007332a3a05148c613306ef2c33d2871682 100644 (file)
@@ -6,7 +6,7 @@
  *
  * 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
  *     3)      TransactionId and CommandId
  *     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 */
 #define CSIGNBIT (0x80)
 
-/* this should probably be somewhere else */
-#define MAXPGPATH      128
-
 #define STATUS_OK              (0)
 #define STATUS_ERROR           (-1)
 #define STATUS_NOT_FOUND       (-2)
index 78d74966c7fcfd240baa14dabbae34b8d8018bdb..fa2acd226ab3e8ec57aa8d1f927279ea331f9b49 100644 (file)
@@ -6,7 +6,7 @@
  *
  * 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
 
 #include <sys/types.h>
-#include <sys/param.h>         /* For MAXPATHLEN */
 
 /* we need this include because port files use them */
 #include "postgres.h"
@@ -30,7 +29,7 @@
 
 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 */
    ino_t       inode;          /* Inode number of file */
    void       *handle;         /* a handle for pg_dl* functions */
index ed406c9dd97aebdac1a95ff6e123ca5991cfd5a9..d84144262ea47323a70d711122642402b2d15629 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
 
-#ifndef PATH_MAX
-#include <sys/param.h>
-#define PATH_MAX MAXPATHLEN
-#endif
-
 #include "miscadmin.h"
 #include "nodes/parsenodes.h"
 #include "nodes/pg_list.h"
@@ -527,7 +522,7 @@ cppline     {space}*#.*(\\{space}*\n)*\n*
 <incl>[^ \t\n]+    { /* got the include file name */
              struct _yy_buffer *yb;
              struct _include_path *ip;
-             char inc_file[PATH_MAX];
+             char inc_file[MAXPGPATH];
 
              yb = mm_alloc(sizeof(struct _yy_buffer));
 
@@ -544,7 +539,7 @@ cppline     {space}*#.*(\\{space}*\n)*\n*
              yyin = NULL;
              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);
                    continue;
index 574d78c25d55aa3b7181c8484bdef08c34ae47b3..fe92bd6964a15010bd324ae60312da003d4acb39 100644 (file)
@@ -9,7 +9,7 @@
  * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
  *
  * 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"))
    {
-       char        tktbuf[MAXPATHLEN];
+       char        tktbuf[MAXPGPATH];
 
        (void) sprintf(tktbuf, "%s@%s", tkt_string(), realm);
        krb_set_tkt_string(tktbuf);
@@ -272,7 +272,7 @@ pg_krb5_init(void)
    krb5_error_code code;
    char       *realm,
               *defname;
-   char        tktbuf[MAXPATHLEN];
+   char        tktbuf[MAXPGPATH];
    static krb5_ccache ccache = (krb5_ccache) NULL;
 
    if (ccache)
index 8d2796673caf0830a59ac8ecf32fba0ae9581525..b067ca1c10eb7257b62cc5c32e10396b334eeee1 100644 (file)
 #define FALSE  ((BOOL)0)
 #endif
 
-#if HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#else
-#define MAXPATHLEN 255
-#endif
 
 DWORD
 GetPrivateProfileString(char *theSection,  // section name
@@ -50,7 +45,7 @@ GetPrivateProfileString(char *theSection, // section name
    size_t theReturnBufferLength,   // byte length of return buffer
    char *theIniFileName)       // pathname of ini file to search
 {
-   char buf[MAXPATHLEN+1];
+   char buf[MAXPGPATH];
    char* ptr = 0;
    FILE* aFile = 0;
    size_t aLength;
@@ -70,8 +65,8 @@ GetPrivateProfileString(char *theSection, // section name
 
    if( ptr == NULL)
    {
-       if( MAXPATHLEN < j )
-           theIniFileName[MAXPATHLEN] = '\0';
+       if( MAXPGPATH-1 < j )
+           theIniFileName[MAXPGPATH-1] = '\0';
 
        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
     * returned.
    */
-   if( MAXPATHLEN < strlen(ptr) + j )
+   if( MAXPGPATH-1 < strlen(ptr) + j )
    {
-       if( MAXPATHLEN < strlen(ptr) )
-           ptr[MAXPATHLEN] = '\0';
+       if( MAXPGPATH-1 < strlen(ptr) )
+           ptr[MAXPGPATH-1] = '\0';
        else
-           theIniFileName[MAXPATHLEN-strlen(ptr)] = '\0';
+           theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
    }
 
    sprintf( buf, "%s/%s",ptr,theIniFileName );
@@ -323,7 +318,7 @@ WritePrivateProfileString(char *theSection, // section name
    char *theBuffer,    // input buffer
    char *theIniFileName)   // pathname of ini file to write
 {
-   char buf[MAXPATHLEN+1];
+   char buf[MAXPGPATH];
    char* ptr = 0;
    FILE* aFile = 0;
    size_t aLength;
@@ -349,8 +344,8 @@ WritePrivateProfileString(char *theSection, // section name
 
    if( ptr == NULL)
    {
-       if( MAXPATHLEN < j )
-           theIniFileName[MAXPATHLEN] = '\0';
+       if( MAXPGPATH-1 < j )
+           theIniFileName[MAXPGPATH-1] = '\0';
 
        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
    // returned.
    //
-   if( MAXPATHLEN < strlen(ptr) + j )
+   if( MAXPGPATH-1 < strlen(ptr) + j )
    {
-       if( MAXPATHLEN < strlen(ptr) )
-           ptr[MAXPATHLEN] = '\0';
+       if( MAXPGPATH-1 < strlen(ptr) )
+           ptr[MAXPGPATH-1] = '\0';
        else
-           theIniFileName[MAXPATHLEN-strlen(ptr)] = '\0';
+           theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
    }
 
    sprintf( buf, "%s/%s",ptr,theIniFileName );
index dae789003dd9215543b7505639f5a0c7805a25db..40816fd110029ae7b1bea3f72f58e7d8cd01b8ed 100644 (file)
@@ -32,7 +32,6 @@ extern GLOBAL_VALUES globals;
 // Constants ---------------------------------------------------------------
 #define MIN(x,y)      ((x) < (y) ? (x) : (y))
 
-#define MAXPATHLEN      (255+1)           // Max path length
 #define MAXKEYLEN       (15+1)            // Max keyword length
 #define MAXDESC         (255+1)           // Max description length
 #define MAXDSNAME       (32+1)            // Max data source name length
@@ -323,7 +322,7 @@ LPCSTR  lpsz;
 LPCSTR  lpszStart;
 char    aszKey[MAXKEYLEN];
 int     cbKey;
-char    value[MAXPATHLEN];
+char    value[MAXPGPATH];
 
        memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
 
@@ -352,7 +351,7 @@ char    value[MAXPATHLEN];
 
 
                 // 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);
 
@@ -384,8 +383,8 @@ LPCSTR  lpszDSN;                                                // Pointer to da
         {
                 if (hwndParent)
                 {
-                        char  szBuf[MAXPATHLEN];
-                        char  szMsg[MAXPATHLEN];
+                        char  szBuf[MAXPGPATH];
+                        char  szMsg[MAXPGPATH];
 
                         LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf));
                         wsprintf(szMsg, szBuf, lpszDSN);
index 2284093eab878bab3516e4850068344e34d37b7f..092f055d53f561ef17fa52be8452836501f627dd 100644 (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,