Go to the source code of this file.
◆ GET_PG_MAJORVERSION_NUM
| #define GET_PG_MAJORVERSION_NUM |
( |
|
v | ) |
((v) / 10000) |
◆ get_pg_version()
| uint32 get_pg_version |
( |
const char * |
datadir, |
|
|
char ** |
version_str |
|
) |
| |
Definition at line 44 of file version.c.
45{
46 FILE *version_fd;
49 int v1 = 0,
50 v2 = 0;
52
53 snprintf(ver_filename,
sizeof(ver_filename),
"%s/PG_VERSION",
55
56 if ((version_fd = fopen(ver_filename, "r")) == NULL)
57 pg_fatal(
"could not open version file \"%s\": %m", ver_filename);
58
59 if (
fstat(fileno(version_fd), &st) != 0)
60 pg_fatal(
"could not stat file \"%s\": %m", ver_filename);
62 pg_fatal(
"file \"%s\" is too large", ver_filename);
63
64 if (fscanf(version_fd,
"%63s",
buf) == 0 ||
65 sscanf(
buf,
"%d.%d", &v1, &v2) < 1)
66 pg_fatal(
"could not parse version file \"%s\"", ver_filename);
67
68 fclose(version_fd);
69
70 if (version_str)
71 {
73 memcpy(*version_str,
buf, st.st_size);
74 }
75
76 if (v1 < 10)
77 {
78
79 return v1 * 10000 + v2 * 100;
80 }
81 else
82 {
83
84 return v1 * 10000;
85 }
86}
void * pg_malloc(size_t size)
#define PG_VERSION_MAX_SIZE
References buf, datadir, fstat, MAXPGPATH, pg_fatal, pg_malloc(), PG_VERSION_MAX_SIZE, snprintf, and stat::st_size.
Referenced by check_data_dir(), check_data_directory(), CheckDataVersion(), and main().