1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Massive commit to run PGINDENT on all *.c and *.h files.

This commit is contained in:
Bruce Momjian
1997-09-07 05:04:48 +00:00
parent 8fecd4febf
commit 1ccd423235
687 changed files with 150775 additions and 136888 deletions

View File

@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* strdup.c--
* copies a null-terminated string.
* copies a null-terminated string.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/utils/Attic/strdup.c,v 1.2 1996/11/28 03:32:18 bryanh Exp $
* $Header: /cvsroot/pgsql/src/utils/Attic/strdup.c,v 1.3 1997/09/07 05:04:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -15,11 +15,11 @@
#include <stdlib.h>
#include "strdup.h"
char *
strdup(char const *string)
char *
strdup(char const * string)
{
char *nstr;
char *nstr;
nstr = strcpy((char *)malloc(strlen(string)+1), string);
return nstr;
nstr = strcpy((char *) malloc(strlen(string) + 1), string);
return nstr;
}

View File

@ -1,25 +1,25 @@
/*-------------------------------------------------------------------------
*
* version.c--
* Routines to handle Postgres version number.
* Routines to handle Postgres version number.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.6 1997/08/27 03:48:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.7 1997/09/07 05:04:48 momjian Exp $
*
* NOTES
* XXX eventually, should be able to handle version identifiers
* of length != 4.
* 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 linked with
* stuff that does not cinterface.a
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
#include <sys/file.h>
#include <fcntl.h> /* For open() flags */
#include <fcntl.h> /* For open() flags */
#include <sys/stat.h>
#include <ctype.h>
#include <string.h>
@ -29,109 +29,127 @@
#include "postgres.h"
#include "storage/fd.h" /* for O_ */
#include "storage/fd.h" /* for O_ */
#include "version.h"
#include "version.h"
static void
PathSetVersionFilePath(const char *path, char *filepathbuf) {
PathSetVersionFilePath(const char *path, char *filepathbuf)
{
/*----------------------------------------------------------------------------
PathSetVersionFilePath
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))
*filepathbuf = '\0';
else
sprintf(filepathbuf, "%s%c%s", path, SEP_CHAR, PG_VERFILE);
if (strlen(path) > (MAXPGPATH - sizeof(PG_VERFILE) - 1))
*filepathbuf = '\0';
else
sprintf(filepathbuf, "%s%c%s", path, SEP_CHAR, PG_VERFILE);
}
void
ValidatePgVersion(const char *path, char **reason_p) {
ValidatePgVersion(const char *path, char **reason_p)
{
/*----------------------------------------------------------------------------
Determine whether the PG_VERSION file in directory <path> indicates
a data version compatible with the version of this program.
If compatible, return <*reason_p> == NULL. Otherwise, malloc space,
fill it with a text string explaining how it isn't compatible (or why
we can't tell), and return a pointer to that space as <*reason_p>.
Determine whether the PG_VERSION file in directory <path> indicates
a data version compatible with the version of this program.
If compatible, return <*reason_p> == NULL. Otherwise, malloc space,
fill it with a text string explaining how it isn't compatible (or why
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 fd;
char version[4];
char full_path[MAXPGPATH + 1];
PathSetVersionFilePath(path, full_path);
if ((fd = open(full_path, O_RDONLY,0)) == -1) {
*reason_p = malloc(200);
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') {
PathSetVersionFilePath(path, full_path);
*reason_p = malloc(200);
sprintf(*reason_p, "File '%s' does not have a valid format "
"for a PG_VERSION file.", full_path);
} else {
if (version[2] != '0' + PG_VERSION ||
version[0] != '0' + PG_RELEASE) {
*reason_p = malloc(200);
sprintf(*reason_p,
"Version number in file '%s' should be %d.%d, "
"not %c.%c.",
full_path,
PG_RELEASE, PG_VERSION, version[0], version[2]);
} else *reason_p = NULL;
}
close(fd);
}
if ((fd = open(full_path, O_RDONLY, 0)) == -1)
{
*reason_p = malloc(200);
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')
{
*reason_p = malloc(200);
sprintf(*reason_p, "File '%s' does not have a valid format "
"for a PG_VERSION file.", full_path);
}
else
{
if (version[2] != '0' + PG_VERSION ||
version[0] != '0' + PG_RELEASE)
{
*reason_p = malloc(200);
sprintf(*reason_p,
"Version number in file '%s' should be %d.%d, "
"not %c.%c.",
full_path,
PG_RELEASE, PG_VERSION, version[0], version[2]);
}
else
*reason_p = NULL;
}
close(fd);
}
}
void
SetPgVersion(const char *path, char **reason_p) {
SetPgVersion(const char *path, char **reason_p)
{
/*---------------------------------------------------------------------------
Create the PG_VERSION file in the directory <path>.
If we fail, allocate storage, fill it with a text string explaining why,
and return a pointer to that storage as <*reason_p>. If we succeed,
and return a pointer to that storage as <*reason_p>. If we succeed,
return *reason_p = NULL.
---------------------------------------------------------------------------*/
int fd;
char version[4];
char full_path[MAXPGPATH+1];
PathSetVersionFilePath(path, full_path);
fd = open(full_path, O_WRONLY|O_CREAT|O_EXCL, 0666);
if (fd < 0) {
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p,
"Unable to create file '%s', errno from open(): %s (%d).",
full_path, strerror(errno), errno);
} else {
int rc; /* return code from some function we call */
int fd;
char version[4];
char full_path[MAXPGPATH + 1];
version[0] = '0' + PG_RELEASE;
version[1] = '.';
version[2] = '0' + PG_VERSION;
version[3] = '\n';
rc = write(fd, version, 4);
if (rc != 4) {
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p,
"Failed to write to file '%s', after it was already "
"open. Errno from write(): %s (%d)",
full_path, strerror(errno), errno);
} else *reason_p = NULL;
close(fd);
}
PathSetVersionFilePath(path, full_path);
fd = open(full_path, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0)
{
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p,
"Unable to create file '%s', errno from open(): %s (%d).",
full_path, strerror(errno), errno);
}
else
{
int rc; /* return code from some function we call */
version[0] = '0' + PG_RELEASE;
version[1] = '.';
version[2] = '0' + PG_VERSION;
version[3] = '\n';
rc = write(fd, version, 4);
if (rc != 4)
{
*reason_p = malloc(100 + strlen(full_path));
sprintf(*reason_p,
"Failed to write to file '%s', after it was already "
"open. Errno from write(): %s (%d)",
full_path, strerror(errno), errno);
}
else
*reason_p = NULL;
close(fd);
}
}