PostgreSQL Source Code: src/include/port.h File Reference (original) (raw)
#include <ctype.h>
#include <[netinet/in.h](in%5F8h%5Fsource.html)>
#include <[arpa/inet.h](port%5F2win32%5F2arpa%5F2inet%5F8h%5Fsource.html)>
Go to the source code of this file.
Typedefs | |
---|---|
typedef int | pgsocket |
typedef unsigned int | socklen_t |
typedef int(* | qsort_arg_comparator) (const void *a, const void *b, void *arg) |
typedef void(* | pqsigfunc) (SIGNAL_ARGS) |
Functions | |
---|---|
bool | pg_set_noblock (pgsocket sock) |
bool | pg_set_block (pgsocket sock) |
bool | has_drive_prefix (const char *path) |
char * | first_dir_separator (const char *filename) |
char * | last_dir_separator (const char *filename) |
char * | first_path_var_separator (const char *pathlist) |
void | join_path_components (char *ret_path, const char *head, const char *tail) |
void | canonicalize_path (char *path) |
void | canonicalize_path_enc (char *path, int encoding) |
void | make_native_path (char *filename) |
void | cleanup_path (char *path) |
bool | path_contains_parent_reference (const char *path) |
bool | path_is_relative_and_below_cwd (const char *path) |
bool | path_is_prefix_of_path (const char *path1, const char *path2) |
char * | make_absolute_path (const char *path) |
const char * | get_progname (const char *argv0) |
void | get_share_path (const char *my_exec_path, char *ret_path) |
void | get_etc_path (const char *my_exec_path, char *ret_path) |
void | get_include_path (const char *my_exec_path, char *ret_path) |
void | get_pkginclude_path (const char *my_exec_path, char *ret_path) |
void | get_includeserver_path (const char *my_exec_path, char *ret_path) |
void | get_lib_path (const char *my_exec_path, char *ret_path) |
void | get_pkglib_path (const char *my_exec_path, char *ret_path) |
void | get_locale_path (const char *my_exec_path, char *ret_path) |
void | get_doc_path (const char *my_exec_path, char *ret_path) |
void | get_html_path (const char *my_exec_path, char *ret_path) |
void | get_man_path (const char *my_exec_path, char *ret_path) |
bool | get_home_path (char *ret_path) |
void | get_parent_directory (char *path) |
char ** | pgfnames (const char *path) |
void | pgfnames_cleanup (char **filenames) |
void | set_pglocale_pgservice (const char *argv0, const char *app) |
int | validate_exec (const char *path) |
int | find_my_exec (const char *argv0, char *retpath) |
int | find_other_exec (const char *argv0, const char *target, const char *versionstr, char *retpath) |
char * | pipe_read_line (char *cmd) |
void | pg_usleep (long microsec) |
int | pg_strcasecmp (const char *s1, const char *s2) |
int | pg_strncasecmp (const char *s1, const char *s2, size_t n) |
unsigned char | pg_toupper (unsigned char ch) |
unsigned char | pg_tolower (unsigned char ch) |
unsigned char | pg_ascii_toupper (unsigned char ch) |
unsigned char | pg_ascii_tolower (unsigned char ch) |
int | pg_vsnprintf (char *str, size_t count, const char *fmt, va_list args) pg_attribute_printf(3 |
int int | pg_snprintf (char *str, size_t count, const char *fmt,...) pg_attribute_printf(3 |
int int int | pg_vsprintf (char *str, const char *fmt, va_list args) pg_attribute_printf(2 |
int int int int | pg_sprintf (char *str, const char *fmt,...) pg_attribute_printf(2 |
int int int int int | pg_vfprintf (FILE *stream, const char *fmt, va_list args) pg_attribute_printf(2 |
int int int int int int | pg_fprintf (FILE *stream, const char *fmt,...) pg_attribute_printf(2 |
int int int int int int int | pg_vprintf (const char *fmt, va_list args) pg_attribute_printf(1 |
int int int int int int int int | pg_printf (const char *fmt,...) pg_attribute_printf(1 |
int | pg_strfromd (char *str, size_t count, int precision, double value) |
char * | pg_strerror (int errnum) |
char * | pg_strerror_r (int errnum, char *buf, size_t buflen) |
const char * | pg_strsignal (int signum) |
int | pclose_check (FILE *stream) |
bool | rmtree (const char *path, bool rmtopdir) |
int | getpeereid (int sock, uid_t *uid, gid_t *gid) |
void | explicit_bzero (void *buf, size_t len) |
char * | mkdtemp (char *path) |
int | inet_aton (const char *cp, struct in_addr *addr) |
size_t | strlcat (char *dst, const char *src, size_t siz) |
size_t | strlcpy (char *dst, const char *src, size_t siz) |
size_t | strnlen (const char *str, size_t maxlen) |
char * | strsep (char **stringp, const char *delim) |
int | timingsafe_bcmp (const void *b1, const void *b2, size_t len) |
void | pg_qsort (void *base, size_t nel, size_t elsize, int(*cmp)(const void *, const void *)) |
int | pg_qsort_strcmp (const void *a, const void *b) |
void | qsort_arg (void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg) |
void | qsort_interruptible (void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg) |
void * | bsearch_arg (const void *key, const void *base0, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg) |
int | pg_localeconv_r (const char *lc_monetary, const char *lc_numeric, struct lconv *output) |
void | pg_localeconv_free (struct lconv *lconv) |
int | pg_get_encoding_from_locale (const char *ctype, bool write_message) |
char * | pg_inet_net_ntop (int af, const void *src, int bits, char *dst, size_t size) |
void | pg_strong_random_init (void) |
bool | pg_strong_random (void *buf, size_t len) |
int | pg_check_dir (const char *dir) |
int | pg_mkdir_p (char *path, int omode) |
void | pqsignal (int signo, pqsigfunc func) |
char * | escape_single_quotes_ascii (const char *src) |
char * | wait_result_to_str (int exitstatus) |
bool | wait_result_is_signal (int exit_status, int signum) |
bool | wait_result_is_any_signal (int exit_status, bool include_command_not_found) |
int | wait_result_to_exit_code (int exit_status) |
◆ ALL_CONNECTION_FAILURE_ERRNOS
#define ALL_CONNECTION_FAILURE_ERRNOS
Value:
Definition at line 122 of file port.h.
◆ closesocket
◆ DEVNULL
#define DEVNULL "/dev/null"
Definition at line 161 of file port.h.
◆ EXE
◆ fprintf
◆ HAVE_GETRLIMIT
◆ HAVE_POLL
◆ HAVE_POLL_H
◆ HAVE_READLINK
◆ HAVE_SETSID
◆ HAVE_SHM_OPEN
◆ HAVE_SYMLINK
◆ is_absolute_path
◆ IS_DIR_SEP
◆ is_nonwindows_absolute_path
| #define is_nonwindows_absolute_path | ( | | filename | ) | | -------------------------------------- | - | | ----------------------------------------------------------- | - |
Value:
( \
IS_NONWINDOWS_DIR_SEP((filename)[0]) \
)
Definition at line 83 of file port.h.
◆ IS_NONWINDOWS_DIR_SEP
| #define IS_NONWINDOWS_DIR_SEP | ( | | ch | ) | ((ch) == '/') | | -------------------------------- | - | | -- | - | ------------- |
Definition at line 82 of file port.h.
◆ is_windows_absolute_path
| #define is_windows_absolute_path | ( | | filename | ) | | ----------------------------------- | - | | ----------------------------------------------------------- | - |
Value:
( \
IS_WINDOWS_DIR_SEP((filename)[0]) || \
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
)
#define IS_WINDOWS_DIR_SEP(ch)
Definition at line 90 of file port.h.
◆ IS_WINDOWS_DIR_SEP
| #define IS_WINDOWS_DIR_SEP | ( | | ch | ) | ((ch) == '/' || (ch) == '\\') | | ----------------------------- | - | | -- | - | -------------------------------- |
Definition at line 88 of file port.h.
◆ pg_backend_random
◆ PG_BACKEND_VERSIONSTR
#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
Definition at line 144 of file port.h.
◆ PG_IOLBF
◆ pg_pread
◆ pg_pwrite
◆ PG_STRERROR_R_BUFLEN
#define PG_STRERROR_R_BUFLEN 256 /* Recommended buffer size for strerror_r */
Definition at line 257 of file port.h.
◆ PGINVALID_SOCKET
#define PGINVALID_SOCKET (-1)
Definition at line 31 of file port.h.
◆ pgoff_t
◆ pqsignal
#define pqsignal pqsignal_be
Definition at line 531 of file port.h.
◆ printf
◆ qsort
◆ snprintf
◆ sprintf
◆ strerror
◆ strerror_r
◆ TIMEZONE_GLOBAL
#define TIMEZONE_GLOBAL timezone
Definition at line 269 of file port.h.
◆ TZNAME_GLOBAL
#define TZNAME_GLOBAL tzname
Definition at line 270 of file port.h.
◆ USE_REPL_SNPRINTF
#define USE_REPL_SNPRINTF 1
Definition at line 180 of file port.h.
◆ vfprintf
◆ vprintf
◆ vsnprintf
◆ vsprintf
◆ pgsocket
◆ pqsigfunc
◆ qsort_arg_comparator
typedef int(* qsort_arg_comparator) (const void *a, const void *b, void *arg)
Definition at line 481 of file port.h.
◆ socklen_t
◆ bsearch_arg()
void * bsearch_arg | ( | const void * | key, |
---|---|---|---|
const void * | base0, | ||
size_t | nmemb, | ||
size_t | size, | ||
int(*)(const void *, const void *, void *) | compar, | ||
void * | arg | ||
) |
◆ canonicalize_path()
void canonicalize_path | ( | char * | path | ) |
---|
Definition at line 337 of file path.c.
338{
339
341}
void canonicalize_path_enc(char *path, int encoding)
References canonicalize_path_enc(), and PG_SQL_ASCII.
Referenced by AbsoluteConfigLocation(), add_tablespace_mapping(), adjust_data_dir(), check_canonical_path(), check_required_directory(), convert_and_check_filename(), create_script_for_old_cluster_deletion(), create_xlog_or_symlink(), CreateTableSpace(), find_in_path(), find_in_paths(), find_my_exec(), find_other_exec(), get_extension_control_directories(), get_tablespace_mapping(), GetConfFilesInDir(), main(), make_absolute_path(), make_relative_path(), member_verify_header(), normalize_exec_path(), parseCommandLine(), scan_for_existing_tablespaces(), setup(), setup_bin_paths(), setup_pgdata(), SplitDirectoriesString(), tablespace_list_append(), and test_canonicalize_path().
◆ canonicalize_path_enc()
void canonicalize_path_enc | ( | char * | path, |
---|---|---|---|
int | encoding | ||
) |
Definition at line 344 of file path.c.
345{
346 char *p,
347 *to_p;
348 char *spath;
349 char *parsed;
350 char *unparse;
351 bool was_sep = false;
353 int pathdepth = 0;
354
355#ifdef WIN32
356
357
358
359
360
361
362 debackslash_path(path, encoding);
363
364
365
366
367
368 p = path + strlen(path);
369 if (p > path && *(p - 1) == '"')
370 *(p - 1) = '/';
371#endif
372
373
374
375
376
377
379
380
381
382
383 p = path;
384#ifdef WIN32
385
386 if (*p)
387 p++;
388#endif
389 to_p = p;
390 for (; *p; p++, to_p++)
391 {
392
393 while (*p == '/' && was_sep)
394 p++;
395 if (to_p != p)
396 *to_p = *p;
397 was_sep = (*p == '/');
398 }
399 *to_p = '\0';
400
401
402
403
404
405
406
407
408
409
410
411
412
414 if (*spath == '\0')
415 return;
416
417 if (*spath == '/')
418 {
420
421 parsed = unparse = (spath + 1);
422 }
423 else
424 {
426 parsed = unparse = spath;
427 }
428
429 while (*unparse != '\0')
430 {
431 char *unparse_next;
432 bool is_double_dot;
433
434
435 unparse_next = unparse;
436 while (*unparse_next && *unparse_next != '/')
437 unparse_next++;
438 if (*unparse_next != '\0')
439 *unparse_next++ = '\0';
440
441
442 if (strcmp(unparse, ".") == 0)
443 {
444
445 unparse = unparse_next;
446 continue;
447 }
448
449 if (strcmp(unparse, "..") == 0)
450 is_double_dot = true;
451 else
452 {
453
454 Assert(*unparse != '\0');
455 is_double_dot = false;
456 }
457
459 {
461
462 if (!is_double_dot)
463 {
464
467 pathdepth++;
468 }
469 break;
471 if (is_double_dot)
472 {
473
474
475 *parsed = '\0';
477 if (--pathdepth == 0)
479 }
480 else
481 {
482
483 *parsed++ = '/';
485 pathdepth++;
486 }
487 break;
489 if (is_double_dot)
490 {
491
494 }
495 else
496 {
497
500 pathdepth++;
501 }
502 break;
504 if (is_double_dot)
505 {
506
507 *parsed = '\0';
509 if (--pathdepth == 0)
510 {
511
512
513
514
515
516
517 if (parsed == spath)
519 else
521 }
522 }
523 else
524 {
525
526 *parsed++ = '/';
528 pathdepth++;
529 }
530 break;
532 if (is_double_dot)
533 {
534
535 *parsed++ = '/';
537 }
538 else
539 {
540
541 *parsed++ = '/';
543
544
545
546
547
548
550 pathdepth = 1;
551 }
552 break;
553 }
554
555 unparse = unparse_next;
556 }
557
558
559
560
561
562
563
564 if (parsed == spath)
565 *parsed++ = '.';
566
567
568 *parsed = '\0';
569}
Assert(PointerIsAligned(start, uint64))
static char * append_subdir_to_path(char *path, char *subdir)
static void trim_trailing_separator(char *path)
static char * trim_directory(char *path)
@ RELATIVE_WITH_PARENT_REF
References ABSOLUTE_PATH_INIT, ABSOLUTE_WITH_N_DEPTH, append_subdir_to_path(), Assert(), encoding, RELATIVE_PATH_INIT, RELATIVE_WITH_N_DEPTH, RELATIVE_WITH_PARENT_REF, skip_drive, trim_directory(), and trim_trailing_separator().
Referenced by canonicalize_path(), do_copy(), exec_command_edit(), exec_command_write(), and process_file().
◆ cleanup_path()
void cleanup_path | ( | char * | path | ) |
---|
◆ escape_single_quotes_ascii()
char * escape_single_quotes_ascii | ( | const char * | src | ) |
---|
◆ explicit_bzero()
void explicit_bzero | ( | void * | buf, |
---|---|---|---|
size_t | len | ||
) |
Definition at line 52 of file explicit_bzero.c.
53{
55}
static void(*volatile bzero_p)(void *, size_t)
References buf, bzero_p, and len.
Referenced by freePGconn(), oauth_exchange(), passwordFromFile(), pg_cryptohash_create(), pg_cryptohash_free(), pg_hmac_create(), pg_hmac_free(), pqClearOAuthToken(), pqReleaseConnHosts(), and run_ssl_passphrase_command().
◆ find_my_exec()
int find_my_exec | ( | const char * | argv0, |
---|---|---|---|
char * | retpath | ||
) |
Definition at line 160 of file exec.c.
161{
162 char *path;
163
164
165
166
169 {
172
174 _("invalid binary \"%s\": %m"), retpath);
175 return -1;
176 }
177
178#ifdef WIN32
179
182#endif
183
184
185
186
187
188 if ((path = getenv("PATH")) && *path)
189 {
190 char *startp = NULL,
191 *endp = NULL;
192
193 do
194 {
195 if (!startp)
196 startp = path;
197 else
198 startp = endp + 1;
199
201 if (!endp)
202 endp = startp + strlen(startp);
203
205
208
210 {
211 case 0:
213 case -1:
214 break;
215 case -2:
217 _("could not read binary \"%s\": %m"),
218 retpath);
219 break;
220 }
221 } while (*endp);
222 }
223
225 _("could not find a \"%s\" to execute"), argv0);
226 return -1;
227}
#define log_error(errcodefn,...)
int validate_exec(const char *path)
static int normalize_exec_path(char *path)
int errcode(int sqlerrcode)
void join_path_components(char *ret_path, const char *head, const char *tail)
char * first_path_var_separator(const char *pathlist)
void canonicalize_path(char *path)
char * first_dir_separator(const char *filename)
size_t strlcpy(char *dst, const char *src, size_t siz)
References _, argv0, canonicalize_path(), errcode(), first_dir_separator(), first_path_var_separator(), join_path_components(), log_error, MAXPGPATH, Min, normalize_exec_path(), strlcpy(), and validate_exec().
Referenced by ensureCleanShutdown(), find_other_exec(), find_other_exec_or_die(), get_exec_path(), getInstallationPaths(), getRestoreCommand(), InitStandaloneProcess(), main(), process_psqlrc(), set_pglocale_pgservice(), setup(), and setup_bin_paths().
◆ find_other_exec()
int find_other_exec | ( | const char * | argv0, |
---|---|---|---|
const char * | target, | ||
const char * | versionstr, | ||
char * | retpath | ||
) |
Definition at line 310 of file exec.c.
312{
314 char *line;
315
317 return -1;
318
319
322
323
325 "/%s%s", target, EXE);
326
328 return -1;
329
330 snprintf(cmd, sizeof(cmd), "\"%s\" -V", retpath);
331
333 return -1;
334
335 if (strcmp(line, versionstr) != 0)
336 {
338 return -2;
339 }
340
342 return 0;
343}
int find_my_exec(const char *argv0, char *retpath)
char * pipe_read_line(char *cmd)
void pfree(void *pointer)
char * last_dir_separator(const char *filename)
References argv0, canonicalize_path(), EXE, find_my_exec(), last_dir_separator(), MAXPGPATH, pfree(), pipe_read_line(), snprintf, and validate_exec().
Referenced by ensureCleanShutdown(), find_other_exec_or_die(), get_exec_path(), getInstallationPaths(), getRestoreCommand(), isolation_start_test(), main(), and setup_bin_paths().
◆ first_dir_separator()
char * first_dir_separator | ( | const char * | filename | ) |
---|
Definition at line 110 of file path.c.
111{
112 const char *p;
113
117 return NULL;
118}
#define unconstify(underlying_type, expr)
References filename, IS_DIR_SEP, skip_drive, and unconstify.
Referenced by check_restricted_library_name(), check_valid_extension_name(), check_valid_version_name(), expand_dynamic_library_name(), find_in_path(), find_my_exec(), load_libraries(), and substitute_path_macro().
◆ first_path_var_separator()
char * first_path_var_separator | ( | const char * | pathlist | ) |
---|
◆ get_doc_path()
void get_doc_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_etc_path()
void get_etc_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_home_path()
bool get_home_path | ( | char * | ret_path | ) |
---|
Definition at line 1005 of file path.c.
1006{
1007#ifndef WIN32
1008
1009
1010
1011
1012 const char *home;
1013
1014 home = getenv("HOME");
1015 if (home && home[0])
1016 {
1018 return true;
1019 }
1020 else
1021 {
1022 struct passwd pwbuf;
1023 struct passwd *pw;
1024 char buf[1024];
1025 int rc;
1026
1027 rc = getpwuid_r(geteuid(), &pwbuf, buf, sizeof buf, &pw);
1028 if (rc != 0 || !pw)
1029 return false;
1031 return true;
1032 }
1033#else
1034 char *tmppath;
1035
1036
1037
1038
1039
1040
1041
1042
1043 tmppath = getenv("APPDATA");
1044 if (!tmppath)
1045 return false;
1047 return true;
1048#endif
1049}
References buf, MAXPGPATH, snprintf, and strlcpy().
Referenced by expand_tilde(), initializeInput(), and process_psqlrc().
◆ get_html_path()
void get_html_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_include_path()
void get_include_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_includeserver_path()
void get_includeserver_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_lib_path()
void get_lib_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_locale_path()
void get_locale_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_man_path()
void get_man_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_parent_directory()
void get_parent_directory | ( | char * | path | ) |
---|
◆ get_pkginclude_path()
void get_pkginclude_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_pkglib_path()
void get_pkglib_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ get_progname()
const char * get_progname | ( | const char * | argv0 | ) |
---|
Definition at line 652 of file path.c.
653{
654 const char *nodir_name;
656
658 if (nodir_name)
659 nodir_name++;
660 else
662
663
664
665
666
667 progname = strdup(nodir_name);
669 {
670 fprintf(stderr, "%s: out of memory\n", nodir_name);
671 abort();
672 }
673
674#if defined(__CYGWIN__) || defined(WIN32)
675
676 if (strlen(progname) > sizeof(EXE) - 1 &&
679#endif
680
682}
#define fprintf(file, fmt, msg)
char * last_dir_separator(const char *filename)
int pg_strcasecmp(const char *s1, const char *s2)
References argv0, EXE, fprintf, last_dir_separator(), pg_strcasecmp(), progname, and skip_drive.
Referenced by get_opts(), handle_help_version_opts(), main(), parseCommandLine(), pg_logging_init(), and regression_main().
◆ get_share_path()
void get_share_path | ( | const char * | my_exec_path, |
---|---|---|---|
char * | ret_path | ||
) |
◆ getpeereid()
int getpeereid | ( | int | sock, |
---|---|---|---|
uid_t * | uid, | ||
gid_t * | gid | ||
) |
Definition at line 33 of file getpeereid.c.
34{
35#if defined(SO_PEERCRED)
36
37 struct ucred peercred;
38 socklen_t so_len = sizeof(peercred);
39
40 if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) != 0 ||
41 so_len != sizeof(peercred))
42 return -1;
43 *uid = peercred.uid;
44 *gid = peercred.gid;
45 return 0;
46#elif defined(LOCAL_PEERCRED)
47
48 struct xucred peercred;
49 socklen_t so_len = sizeof(peercred);
50
51 if (getsockopt(sock, 0, LOCAL_PEERCRED, &peercred, &so_len) != 0 ||
52 so_len != sizeof(peercred) ||
53 peercred.cr_version != XUCRED_VERSION)
54 return -1;
55 *uid = peercred.cr_uid;
56 *gid = peercred.cr_gid;
57 return 0;
58#elif defined(HAVE_GETPEERUCRED)
59
60 ucred_t *ucred;
61
62 ucred = NULL;
63 if (getpeerucred(sock, &ucred) == -1)
64 return -1;
65
66 *uid = ucred_geteuid(ucred);
67 *gid = ucred_getegid(ucred);
68 ucred_free(ucred);
69
70 if (*uid == (uid_t) (-1) || *gid == (gid_t) (-1))
71 return -1;
72 return 0;
73#else
74
75 errno = ENOSYS;
76 return -1;
77#endif
78}
Referenced by auth_peer(), and PQconnectPoll().
◆ has_drive_prefix()
bool has_drive_prefix | ( | const char * | path | ) |
---|
◆ inet_aton()
int inet_aton | ( | const char * | cp, |
---|---|---|---|
struct in_addr * | addr | ||
) |
Definition at line 56 of file inet_aton.c.
57{
58 unsigned int val;
59 int base,
60 n;
61 char c;
62 u_int parts[4];
63 u_int *pp = parts;
64
65 for (;;)
66 {
67
68
69
70
72 base = 10;
73 if (*cp == '0')
74 {
75 if (*++cp == 'x' || *cp == 'X')
76 base = 16, cp++;
77 else
78 base = 8;
79 }
80 while ((c = *cp) != '\0')
81 {
82 if (isdigit((unsigned char) c))
83 {
84 val = (val * base) + (c - '0');
85 cp++;
86 continue;
87 }
88 if (base == 16 && isxdigit((unsigned char) c))
89 {
91 (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
92 cp++;
93 continue;
94 }
95 break;
96 }
97 if (*cp == '.')
98 {
99
100
101
102
103 if (pp >= parts + 3 || val > 0xff)
104 return 0;
105 *pp++ = val, cp++;
106 }
107 else
108 break;
109 }
110
111
112
113
114 while (*cp)
115 if (!isspace((unsigned char) *cp++))
116 return 0;
117
118
119
120
121 n = pp - parts + 1;
122 switch (n)
123 {
124
125 case 1:
126 break;
127
128 case 2:
129 if (val > 0xffffff)
130 return 0;
131 val |= parts[0] << 24;
132 break;
133
134 case 3:
135 if (val > 0xffff)
136 return 0;
137 val |= (parts[0] << 24) | (parts[1] << 16);
138 break;
139
140 case 4:
141 if (val > 0xff)
142 return 0;
143 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
144 break;
145 }
146 if (addr)
148 return 1;
149}
References pg_hton32, and val.
Referenced by is_ip_address(), and pq_verify_peer_name_matches_certificate_ip().
◆ join_path_components()
void join_path_components | ( | char * | ret_path, |
---|---|---|---|
const char * | head, | ||
const char * | tail | ||
) |
Definition at line 286 of file path.c.
288{
289 if (ret_path != head)
291
292
293
294
295
296
297 if (*tail)
298 {
299
300 snprintf(ret_path + strlen(ret_path), MAXPGPATH - strlen(ret_path),
301 "%s%s",
302 (*(skip_drive(head)) != '\0') ? "/" : "",
303 tail);
304 }
305}
References MAXPGPATH, skip_drive, snprintf, and strlcpy().
Referenced by AbsoluteConfigLocation(), find_my_exec(), GetConfFilesInDir(), main(), make_relative_path(), and process_file().
◆ last_dir_separator()
char * last_dir_separator | ( | const char * | filename | ) |
---|
Definition at line 145 of file path.c.
146{
147 const char *p,
148 *ret = NULL;
149
152 ret = p;
154}
References filename, IS_DIR_SEP, skip_drive, and unconstify.
Referenced by check_file_excluded(), ECPGconnect(), find_other_exec(), get_progname(), main(), pg_get_loaded_modules(), sendDir(), setup(), setup_bin_paths(), and should_allow_existing_directory().
◆ make_absolute_path()
char * make_absolute_path | ( | const char * | path | ) |
---|
Definition at line 807 of file path.c.
808{
809 char *new;
810
811
812 if (path == NULL)
813 return NULL;
814
816 {
817 char *buf;
818 size_t buflen;
819
821 for (;;)
822 {
824 if ()
825 {
826#ifndef FRONTEND
828 (errcode(ERRCODE_OUT_OF_MEMORY),
829 errmsg("out of memory")));
830#else
831 fprintf(stderr, _("out of memory\n"));
832 return NULL;
833#endif
834 }
835
836 if (getcwd(buf, buflen))
837 break;
838 else if (errno == ERANGE)
839 {
841 buflen *= 2;
842 continue;
843 }
844 else
845 {
846 int save_errno = errno;
847
849 errno = save_errno;
850#ifndef FRONTEND
851 elog(ERROR, "could not get current working directory: %m");
852#else
853 fprintf(stderr, _("could not get current working directory: %m\n"));
854 return NULL;
855#endif
856 }
857 }
858
859 new = malloc(strlen(buf) + strlen(path) + 2);
860 if (!new)
861 {
863#ifndef FRONTEND
865 (errcode(ERRCODE_OUT_OF_MEMORY),
866 errmsg("out of memory")));
867#else
868 fprintf(stderr, _("out of memory\n"));
869 return NULL;
870#endif
871 }
874 }
875 else
876 {
877 new = strdup(path);
878 if (!new)
879 {
880#ifndef FRONTEND
882 (errcode(ERRCODE_OUT_OF_MEMORY),
883 errmsg("out of memory")));
884#else
885 fprintf(stderr, _("out of memory\n"));
886 return NULL;
887#endif
888 }
889 }
890
891
893
894 return new;
895}
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void canonicalize_path(char *path)
#define is_absolute_path(filename)
References _, buf, canonicalize_path(), elog, ereport, errcode(), errmsg(), ERROR, fprintf, free, is_absolute_path, malloc, MAXPGPATH, and sprintf.
Referenced by regression_main(), SelectConfigFiles(), and SetDataDir().
◆ make_native_path()
void make_native_path | ( | char * | filename | ) |
---|
◆ mkdtemp()
char * mkdtemp | ( | char * | path | ) |
---|
◆ path_contains_parent_reference()
bool path_contains_parent_reference | ( | const char * | path | ) |
---|
◆ path_is_prefix_of_path()
bool path_is_prefix_of_path | ( | const char * | path1, |
---|---|---|---|
const char * | path2 | ||
) |
◆ path_is_relative_and_below_cwd()
bool path_is_relative_and_below_cwd | ( | const char * | path | ) |
---|
◆ pclose_check()
int pclose_check | ( | FILE * | stream | ) |
---|
Definition at line 391 of file exec.c.
392{
393 int exitstatus;
394 char *reason;
395
396 exitstatus = pclose(stream);
397
398 if (exitstatus == 0)
399 return 0;
400
401 if (exitstatus == -1)
402 {
403
405 _("%s() failed: %m"), "pclose");
406 }
407 else
408 {
411 "%s", reason);
413 }
414 return exitstatus;
415}
char * wait_result_to_str(int exitstatus)
References _, errcode(), log_error, pfree(), and wait_result_to_str().
Referenced by pipe_read_line().
◆ pg_ascii_tolower()
unsigned char pg_ascii_tolower | ( | unsigned char | ch | ) |
---|
◆ pg_ascii_toupper()
unsigned char pg_ascii_toupper | ( | unsigned char | ch | ) |
---|
◆ pg_check_dir()
int pg_check_dir | ( | const char * | dir | ) |
---|
Definition at line 33 of file pgcheckdir.c.
34{
35 int result = 1;
36 DIR *chkdir;
38 bool dot_found = false;
39 bool mount_found = false;
40 int readdir_errno;
41
43 if (chkdir == NULL)
44 return (errno == ENOENT) ? 0 : -1;
45
46 while (errno = 0, (file = readdir(chkdir)) != NULL)
47 {
48 if (strcmp(".", file->d_name) == 0 ||
49 strcmp("..", file->d_name) == 0)
50 {
51
52 continue;
53 }
54#ifndef WIN32
55
56 else if (file->d_name[0] == '.')
57 {
58 dot_found = true;
59 }
60
61 else if (strcmp("lost+found", file->d_name) == 0)
62 {
63 mount_found = true;
64 }
65#endif
66 else
67 {
68 result = 4;
69 break;
70 }
71 }
72
73 if (errno)
74 result = -1;
75
76
77 readdir_errno = errno;
79 result = -1;
80 else
81 errno = readdir_errno;
82
83
84 if (result == 1 && mount_found)
85 result = 3;
86
87
88 if (result == 1 && dot_found)
89 result = 2;
90
91 return result;
92}
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
References closedir(), dirent::d_name, opendir(), and readdir().
Referenced by bbsink_server_new(), cleanup_output_dirs(), create_data_directory(), create_fullpage_directory(), create_or_open_dir(), create_output_directory(), create_xlog_or_symlink(), main(), and verify_dir_is_empty_or_create().
◆ pg_fprintf()
int int int int int int pg_fprintf | ( | FILE * | stream, |
---|---|---|---|
const char * | fmt, | ||
... | |||
) |
◆ pg_get_encoding_from_locale()
int pg_get_encoding_from_locale | ( | const char * | ctype, |
---|---|---|---|
bool | write_message | ||
) |
Definition at line 301 of file chklocale.c.
302{
303 char *sys;
304 int i;
305
306#ifndef WIN32
308#endif
309
310
311 if (!ctype)
312 ctype = setlocale(LC_CTYPE, NULL);
313
314
315
319
320
321#ifndef WIN32
322 loc = newlocale(LC_CTYPE_MASK, ctype, (locale_t) 0);
324 return -1;
325
326 sys = nl_langinfo_l(CODESET, loc);
327 if (sys)
328 sys = strdup(sys);
329
330 freelocale(loc);
331#else
332 sys = win32_get_codeset(ctype);
333#endif
334
335 if (!sys)
336 return -1;
337
338
340 {
342 {
345 }
346 }
347
348
349
350#ifdef __darwin__
351
352
353
354
355
356 if (strlen(sys) == 0)
357 {
360 }
361#endif
362
363
364
365
366
367 if (write_message)
368 {
369#ifdef FRONTEND
370 fprintf(stderr, _("could not determine encoding for locale \"%s\": codeset is \"%s\""),
371 ctype, sys);
372
373 fputc('\n', stderr);
374#else
376 (errmsg("could not determine encoding for locale \"%s\": codeset is \"%s\"",
377 ctype, sys)));
378#endif
379 }
380
382 return -1;
383}
static const struct encoding_match encoding_match_list[]
const char * system_enc_name
References _, encoding_match_list, ereport, errmsg(), fprintf, free, i, locale_t, encoding_match::pg_enc_code, PG_SQL_ASCII, pg_strcasecmp(), PG_UTF8, setlocale, encoding_match::system_enc_name, and WARNING.
Referenced by cache_locale_time(), check_encoding_locale_matches(), check_locale_encoding(), main(), PGLC_localeconv(), pqConnectOptions2(), PQsetClientEncoding(), and setup_locale_encoding().
◆ pg_inet_net_ntop()
char * pg_inet_net_ntop | ( | int | af, |
---|---|---|---|
const void * | src, | ||
int | bits, | ||
char * | dst, | ||
size_t | size | ||
) |
Definition at line 77 of file inet_net_ntop.c.
78{
79
80
81
82
83
84
85 switch (af)
86 {
90#if AF_INET6 != PGSQL_AF_INET6
91 case AF_INET6:
92#endif
94 default:
96 return (NULL);
97 }
98}
static char * inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
static char * inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
References EAFNOSUPPORT, inet_net_ntop_ipv4(), inet_net_ntop_ipv6(), PGSQL_AF_INET, and PGSQL_AF_INET6.
Referenced by getHostaddr(), inet_abbrev(), network_host(), network_out(), network_show(), and pq_verify_peer_name_matches_certificate_ip().
◆ pg_localeconv_free()
void pg_localeconv_free | ( | struct lconv * | lconv | ) |
---|
◆ pg_localeconv_r()
int pg_localeconv_r | ( | const char * | lc_monetary, |
---|---|---|---|
const char * | lc_numeric, | ||
struct lconv * | output | ||
) |
Definition at line 231 of file pg_localeconv_r.c.
234{
235#ifdef WIN32
236 wchar_t *save_lc_ctype = NULL;
237 wchar_t *save_lc_monetary = NULL;
238 wchar_t *save_lc_numeric = NULL;
239 int save_config_thread_locale;
240 int result = -1;
241
242
243 save_config_thread_locale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
244
245
246
247
248
249
250
251
252 save_lc_ctype = _wsetlocale(LC_CTYPE, NULL);
253 if (!save_lc_ctype || !(save_lc_ctype = wcsdup(save_lc_ctype)))
254 goto exit;
255 save_lc_monetary = _wsetlocale(LC_MONETARY, NULL);
256 if (!save_lc_monetary || !(save_lc_monetary = wcsdup(save_lc_monetary)))
257 goto exit;
258 save_lc_numeric = _wsetlocale(LC_NUMERIC, NULL);
259 if (!save_lc_numeric || !(save_lc_numeric = wcsdup(save_lc_numeric)))
260 goto exit;
261
263
264
266 goto exit;
268 if (result != 0)
269 goto exit;
270
271
273 goto exit;
275
276exit:
277
278 if (save_lc_ctype)
279 {
280 _wsetlocale(LC_CTYPE, save_lc_ctype);
281 free(save_lc_ctype);
282 }
283 if (save_lc_monetary)
284 {
285 _wsetlocale(LC_MONETARY, save_lc_monetary);
286 free(save_lc_monetary);
287 }
288 if (save_lc_numeric)
289 {
290 _wsetlocale(LC_NUMERIC, save_lc_numeric);
291 free(save_lc_numeric);
292 }
293 _configthreadlocale(save_config_thread_locale);
294
295 return result;
296
297#else
300 int result;
301
302
303
304
305
306
307
308 errno = ENOENT;
309 monetary_locale = newlocale(LC_ALL_MASK, lc_monetary, 0);
310 if (monetary_locale == 0)
311 return -1;
312 numeric_locale = newlocale(LC_ALL_MASK, lc_numeric, 0);
313 if (numeric_locale == 0)
314 {
315 freelocale(monetary_locale);
316 return -1;
317 }
318
320#if defined(TRANSLATE_FROM_LANGINFO)
321
322 result = pg_localeconv_from_langinfo(output,
323 monetary_locale,
324 numeric_locale);
325#elif defined(HAVE_LOCALECONV_L)
326
328 localeconv_l(monetary_locale),
329 LC_MONETARY);
330 if (result == 0)
331 {
332
334 localeconv_l(numeric_locale),
335 LC_NUMERIC);
336 }
337#else
338
339 {
342
344
345 save_locale = uselocale(monetary_locale);
347 localeconv(),
348 LC_MONETARY);
349 if (result == 0)
350 {
351
352 uselocale(numeric_locale);
354 localeconv(),
355 LC_NUMERIC);
356 }
358
359 uselocale(save_locale);
360 }
361#endif
362
363 freelocale(monetary_locale);
364 freelocale(numeric_locale);
365
366 return result;
367#endif
368}
static char * lc_monetary
static int pg_localeconv_copy_members(struct lconv *dst, struct lconv *src, int category)
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
#define PTHREAD_MUTEX_INITIALIZER
References free, lc_monetary, lc_numeric, locale_t, output, pg_localeconv_copy_members(), PTHREAD_MUTEX_INITIALIZER, pthread_mutex_lock(), pthread_mutex_unlock(), and setlocale.
Referenced by PGLC_localeconv().
◆ pg_mkdir_p()
int pg_mkdir_p | ( | char * | path, |
---|---|---|---|
int | omode | ||
) |
Definition at line 57 of file pgmkdirp.c.
58{
59 struct stat sb;
60 mode_t numask,
61 oumask;
62 int last,
63 retval;
64 char *p;
65
66 retval = 0;
67 p = path;
68
69#ifdef WIN32
70
71 if (strlen(p) >= 2)
72 {
73 if (p[0] == '/' && p[1] == '/')
74 {
75
76 p = strstr(p + 2, "/");
77 if (p == NULL)
78 {
79 errno = EINVAL;
80 return -1;
81 }
82 }
83 else if (p[1] == ':' &&
84 ((p[0] >= 'a' && p[0] <= 'z') ||
85 (p[0] >= 'A' && p[0] <= 'Z')))
86 {
87
88 p += 2;
89 }
90 }
91#endif
92
93
94
95
96
97
98
99
100
101
102
103 oumask = umask(0);
105 (void) umask(numask);
106
107 if (p[0] == '/')
108 ++p;
109 for (last = 0; !last; ++p)
110 {
111 if (p[0] == '\0')
112 last = 1;
113 else if (p[0] != '/')
114 continue;
115 *p = '\0';
116 if (!last && p[1] == '\0')
117 last = 1;
118
119 if (last)
120 (void) umask(oumask);
121
122
123 if (stat(path, &sb) == 0)
124 {
125 if ((sb.st_mode))
126 {
127 if (last)
128 errno = EEXIST;
129 else
130 errno = ENOTDIR;
131 retval = -1;
132 break;
133 }
134 }
136 {
137 retval = -1;
138 break;
139 }
140 if (!last)
141 *p = '/';
142 }
143
144
145 (void) umask(oumask);
146
147 return retval;
148}
References mkdir, S_IRWXG, S_IRWXO, S_IRWXU, S_ISDIR, S_IWUSR, S_IXUSR, stat::st_mode, and stat.
Referenced by create_data_directory(), create_fullpage_directory(), create_output_directory(), create_xlog_or_symlink(), main(), prepare_for_swap(), recovery_create_dbdir(), StartLogStreamer(), TablespaceCreateDbspace(), and verify_dir_is_empty_or_create().
◆ pg_printf()
int int int int int int int int pg_printf | ( | const char * | fmt, |
---|---|---|---|
... | |||
) |
◆ pg_qsort()
void pg_qsort | ( | void * | base, |
---|---|---|---|
size_t | nel, | ||
size_t | elsize, | ||
int(*)(const void *, const void *) | cmp | ||
) |
◆ pg_qsort_strcmp()
int pg_qsort_strcmp | ( | const void * | a, |
---|---|---|---|
const void * | b | ||
) |
◆ pg_set_block()
Definition at line 49 of file noblock.c.
50{
51#if !defined(WIN32)
52 int flags;
53
54 flags = fcntl(sock, F_GETFL);
55 if (flags < 0)
56 return false;
57 if (fcntl(sock, F_SETFL, (flags & ~O_NONBLOCK)) == -1)
58 return false;
59 return true;
60#else
61 unsigned long ioctlsocket_ret = 0;
62
63
64 return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
65#endif
66}
◆ pg_set_noblock()
Definition at line 25 of file noblock.c.
26{
27#if !defined(WIN32)
28 int flags;
29
30 flags = fcntl(sock, F_GETFL);
31 if (flags < 0)
32 return false;
33 if (fcntl(sock, F_SETFL, (flags | O_NONBLOCK)) == -1)
34 return false;
35 return true;
36#else
37 unsigned long ioctlsocket_ret = 1;
38
39
40 return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
41#endif
42}
Referenced by pq_init(), PQconnectPoll(), and report_fork_failure_to_client().
◆ pg_snprintf()
int int pg_snprintf | ( | char * | str, |
---|---|---|---|
size_t | count, | ||
const char * | fmt, | ||
... | |||
) |
◆ pg_sprintf()
int int int int pg_sprintf | ( | char * | str, |
---|---|---|---|
const char * | fmt, | ||
... | |||
) |
◆ pg_strcasecmp()
int pg_strcasecmp | ( | const char * | s1, |
---|---|---|---|
const char * | s2 | ||
) |
Definition at line 36 of file pgstrcasecmp.c.
37{
38 for (;;)
39 {
40 unsigned char ch1 = (unsigned char) *s1++;
41 unsigned char ch2 = (unsigned char) *s2++;
42
43 if (ch1 != ch2)
44 {
45 if (ch1 >= 'A' && ch1 <= 'Z')
46 ch1 += 'a' - 'A';
48 ch1 = tolower(ch1);
49
50 if (ch2 >= 'A' && ch2 <= 'Z')
51 ch2 += 'a' - 'A';
53 ch2 = tolower(ch2);
54
55 if (ch1 != ch2)
56 return (int) ch1 - (int) ch2;
57 }
58 if (ch1 == 0)
59 break;
60 }
61 return 0;
62}
#define IS_HIGHBIT_SET(ch)
References IS_HIGHBIT_SET, s1, and s2.
Referenced by AlterType(), appendPGArray(), array_out(), build_startup_packet(), check_createrole_self_grant(), check_datestyle(), check_debug_io_direct(), check_log_destination(), check_publications_origin(), check_restrict_nonsystem_relation_kind(), check_usermap(), check_wal_consistency_checking(), comp_keyword_case_hook(), config_enum_lookup_by_name(), convert_any_priv_string(), createdb(), defGetBoolean(), defGetCopyHeaderChoice(), defGetCopyLogVerbosityChoice(), defGetCopyOnErrorChoice(), defGetGeneratedColsOption(), defGetStreamingMode(), defGetTypeLength(), DefineAggregate(), DefineCollation(), DefineType(), do_pset(), dumpSubscription(), echo_hidden_hook(), echo_hook(), evaluateSleep(), exec_command(), ExecVacuum(), expect_boolean_value(), find_matching_ts_config(), get_arg_by_name(), get_collation_actual_version_libc(), get_dbnames_list_to_restore(), get_progname(), GetAttributeStorage(), GetCommandTagEnum(), getMetaCommand(), helpSQL(), histcontrol_hook(), hostname_match(), IsReservedOriginName(), locate_stem_module(), lookup_prop_name(), main(), makeVariableValue(), map_typename_pattern(), on_error_rollback_hook(), parse_basebackup_options(), parse_hstore(), parse_one_reloption(), parse_output_parameters(), parse_slash_copy(), parse_subscription_options(), parseArchiveFormat(), parseCommandLine(), parseDumpFormat(), parseNameAndArgTypes(), ParseVariableBool(), pg_checksum_parse_type(), pg_fe_sendauth(), pg_find_encoding(), pg_get_encoding_from_locale(), pg_size_bytes(), pg_stat_get_progress_info(), pgp_get_cipher_code(), pgp_get_digest_code(), pgstat_get_kind_from_str(), pgstat_register_kind(), PGTYPEStimestamp_defmt_scan(), plperl_trigger_handler(), plpgsql_extra_checks_check_hook(), PLy_exec_trigger(), pq_verify_peer_name_matches_certificate_name(), process_backslash_command(), prsd_headline(), px_gen_salt(), px_resolve_alias(), ReadArrayToken(), RegisterCustomRmgr(), show_context_hook(), splitTzLine(), ssl_protocol_version_to_openssl(), sslVerifyProtocolRange(), sslVerifyProtocolVersion(), stats_fill_fcinfo_from_arg_pairs(), SyncRepGetStandbyPriority(), unicode_norm_form_from_string(), validate_exec(), validate_log_connections_options(), variable_is_guc_list_quote(), verbosity_hook(), verify_heapam(), wildcard_certificate_match(), and xmlpi().
◆ pg_strerror()
char * pg_strerror | ( | int | errnum | ) |
---|
◆ pg_strerror_r()
char * pg_strerror_r | ( | int | errnum, |
---|---|---|---|
char * | buf, | ||
size_t | buflen | ||
) |
Definition at line 46 of file strerror.c.
47{
48 char *str;
49
50
51#ifdef WIN32
52
53 if (errnum >= 10000 && errnum <= 11999)
54 return win32_socket_strerror(errnum, buf, buflen);
55#endif
56
57
59
60
61
62
63
64
65
66
67 if (str == NULL || *str == '\0' || *str == '?')
69
70 if (str == NULL)
71 {
72 snprintf(buf, buflen, _("operating system error %d"), errnum);
74 }
75
76 return str;
77}
static char * get_errno_symbol(int errnum)
static char * gnuish_strerror_r(int errnum, char *buf, size_t buflen)
References _, buf, get_errno_symbol(), gnuish_strerror_r(), snprintf, and str.
Referenced by pg_strerror().
◆ pg_strfromd()
int pg_strfromd | ( | char * | str, |
---|---|---|---|
size_t | count, | ||
int | precision, | ||
double | value | ||
) |
Definition at line 1318 of file snprintf.c.
1319{
1321 int signvalue = 0;
1322 int vallen;
1323 char fmt[8];
1325
1326
1329 target.bufend = str + count - 1;
1330 target.stream = NULL;
1332 target.failed = false;
1333
1334
1335
1336
1337
1338
1339 if (precision < 1)
1340 precision = 1;
1341 else if (precision > 32)
1342 precision = 32;
1343
1344
1345
1346
1347
1348 if (isnan(value))
1349 {
1351 vallen = 3;
1352 }
1353 else
1354 {
1355 static const double dzero = 0.0;
1356
1357 if (value < 0.0 ||
1358 (value == 0.0 &&
1359 memcmp(&value, &dzero, sizeof(double)) != 0))
1360 {
1361 signvalue = '-';
1363 }
1364
1365 if (isinf(value))
1366 {
1367 strcpy(convert, "Infinity");
1368 vallen = 8;
1369 }
1370 else
1371 {
1372 fmt[0] = '%';
1373 fmt[1] = '.';
1374 fmt[2] = '*';
1375 fmt[3] = 'g';
1376 fmt[4] = '\0';
1378 if (vallen < 0)
1379 {
1380 target.failed = true;
1381 goto fail;
1382 }
1383
1384#ifdef WIN32
1385 if (vallen >= 6 &&
1386 convert[vallen - 5] == 'e' &&
1387 convert[vallen - 3] == '0')
1388 {
1391 vallen--;
1392 }
1393#endif
1394 }
1395 }
1396
1397 if (signvalue)
1399
1401
1402fail:
1403 *(target.bufptr) = '\0';
1406}
static void dostr(const char *str, int slen, PrintfTarget *target)
static void dopr_outch(int c, PrintfTarget *target)
static void convert(const int32 val, char *const buf)
References Assert(), PrintfTarget::bufend, PrintfTarget::bufptr, PrintfTarget::bufstart, convert(), dopr_outch(), dostr(), PrintfTarget::failed, PrintfTarget::nchars, snprintf, str, PrintfTarget::stream, and value.
Referenced by float4out(), and float8out_internal().
◆ pg_strncasecmp()
int pg_strncasecmp | ( | const char * | s1, |
---|---|---|---|
const char * | s2, | ||
size_t | n | ||
) |
Definition at line 69 of file pgstrcasecmp.c.
70{
71 while (n-- > 0)
72 {
73 unsigned char ch1 = (unsigned char) *s1++;
74 unsigned char ch2 = (unsigned char) *s2++;
75
76 if (ch1 != ch2)
77 {
78 if (ch1 >= 'A' && ch1 <= 'Z')
79 ch1 += 'a' - 'A';
81 ch1 = tolower(ch1);
82
83 if (ch2 >= 'A' && ch2 <= 'Z')
84 ch2 += 'a' - 'A';
86 ch2 = tolower(ch2);
87
88 if (ch1 != ch2)
89 return (int) ch1 - (int) ch2;
90 }
91 if (ch1 == 0)
92 break;
93 }
94 return 0;
95}
References IS_HIGHBIT_SET, s1, and s2.
Referenced by check_content_type(), check_datestyle(), check_for_device_flow(), check_special_value(), check_timezone(), checkKeyword(), command_no_begin(), do_pset(), float4in_internal(), float8in_internal(), get_collation_actual_version_libc(), helpSQL(), issuer_from_well_known_uri(), MainLoop(), makeVariableValue(), map_sql_identifier_to_xml_name(), multirange_in(), numeric_in(), parse_bool_with_len(), parse_jsonb_index_flags(), parse_or_operator(), ParseTzFile(), ParseVariableBool(), range_parse(), replace_guc_value(), scan_directory_ci(), set_unicode_line_style(), set_var_from_str(), SpecialTags(), and validate_token_format().
◆ pg_strong_random()
bool pg_strong_random | ( | void * | buf, |
---|---|---|---|
size_t | len | ||
) |
Definition at line 150 of file pg_strong_random.c.
151{
152 int f;
153 char *p = buf;
154 ssize_t res;
155
156 f = open("/dev/urandom", O_RDONLY, 0);
157 if (f == -1)
158 return false;
159
160 while (len)
161 {
163 if (res <= 0)
164 {
165 if (errno == EINTR)
166 continue;
167
169 return false;
170 }
171
172 p += res;
173 len -= res;
174 }
175
177 return true;
178}
References buf, close, EINTR, len, and read.
Referenced by build_client_first_message(), build_server_first_message(), CheckMD5Auth(), gen_random_uuid(), generate_uuidv7(), init_sess_key(), InitControlFile(), pad_eme_pkcs1_v15(), PerformRadiusTransaction(), pg_be_scram_build_secret(), pg_fe_scram_build_secret(), pg_random_bytes(), pgp_s2k_fill(), PostgresMain(), px_gen_salt(), set_random_seed(), and write_prefix().
◆ pg_strong_random_init()
void pg_strong_random_init | ( | void | ) |
---|
◆ pg_strsignal()
const char * pg_strsignal | ( | int | signum | ) |
---|
◆ pg_tolower()
unsigned char pg_tolower | ( | unsigned char | ch | ) |
---|
Definition at line 122 of file pgstrcasecmp.c.
123{
124 if (ch >= 'A' && ch <= 'Z')
125 ch += 'a' - 'A';
127 ch = tolower(ch);
128 return ch;
129}
References IS_HIGHBIT_SET.
Referenced by DecodeTimezoneAbbrevPrefix(), dequote_downcase_identifier(), dir_strcmp(), ParseDateTime(), patternToSQLRegex(), PGTYPESdate_defmt_asc(), PQfnumber(), SB_lower_char(), strlower_libc_sb(), strtitle_libc_sb(), and validateTzEntry().
◆ pg_toupper()
unsigned char pg_toupper | ( | unsigned char | ch | ) |
---|
◆ pg_usleep()
void pg_usleep | ( | long | microsec | ) |
---|
Definition at line 53 of file signal.c.
54{
56 {
57
58
59
60
61
62 SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
63 return;
64 }
65
67 (microsec < 500 ? 1 : (microsec + 500) / 1000))
68 == WAIT_OBJECT_0)
69 {
72 return;
73 }
74}
void pgwin32_dispatch_queued_signals(void)
HANDLE pgwin32_signal_event
References EINTR, pgwin32_dispatch_queued_signals(), pgwin32_signal_event, and unlikely.
Referenced by _bt_pendingfsm_finalize(), AcceptConnection(), auth_delay_checks(), AutoVacLauncherMain(), AutoVacWorkerMain(), BackendInitialize(), BackgroundWorkerMain(), BackgroundWriterMain(), CheckpointerMain(), ConditionalXactLockTableWait(), CountOtherDBBackends(), CreateCheckPoint(), do_watch(), exec_prog(), FileReadV(), FileWriteV(), get_controlfile_by_exact_path(), InitPostgres(), main(), perform_spin_delay(), pgarch_ArchiverCopyLoop(), pgwin32_recv(), read_local_xlog_page_guts(), regression_main(), RequestCheckpoint(), ResolveRecoveryConflictWithDatabase(), ResolveRecoveryConflictWithVirtualXIDs(), StartupXLOG(), threadRun(), vacuum_delay_point(), wait_for_connection_state(), wait_for_end_recovery(), wait_for_postmaster_promote(), wait_for_postmaster_start(), wait_for_postmaster_stop(), wait_pid(), WaitExceedsMaxStandbyDelay(), WALDumpOpenSegment(), WalSndWaitStopping(), WalWriterMain(), XactLockTableWait(), and XLogFlush().
◆ pg_vfprintf()
int int int int int pg_vfprintf | ( | FILE * | stream, |
---|---|---|---|
const char * | fmt, | ||
va_list | args | ||
) |
◆ pg_vprintf()
int int int int int int int pg_vprintf | ( | const char * | fmt, |
---|---|---|---|
va_list | args | ||
) |
◆ pg_vsnprintf()
int pg_vsnprintf | ( | char * | str, |
---|---|---|---|
size_t | count, | ||
const char * | fmt, | ||
va_list | args | ||
) |
◆ pg_vsprintf()
int int int pg_vsprintf | ( | char * | str, |
---|---|---|---|
const char * | fmt, | ||
va_list | args | ||
) |
◆ pgfnames()
char ** pgfnames | ( | const char * | path | ) |
---|
Definition at line 37 of file pgfnames.c.
38{
41 char **filenames;
42 int numnames = 0;
43 int fnsize = 200;
44
46 if (dir == NULL)
47 {
48 pg_log_warning("could not open directory \"%s\": %m", path);
49 return NULL;
50 }
51
52 filenames = (char **) palloc(fnsize * sizeof(char *));
53
54 while (errno = 0, (file = readdir(dir)) != NULL)
55 {
56 if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
57 {
58 if (numnames + 1 >= fnsize)
59 {
60 fnsize *= 2;
61 filenames = (char **) repalloc(filenames,
62 fnsize * sizeof(char *));
63 }
65 }
66 }
67
68 if (errno)
69 pg_log_warning("could not read directory \"%s\": %m", path);
70
71 filenames[numnames] = NULL;
72
74 pg_log_warning("could not close directory \"%s\": %m", path);
75
76 return filenames;
77}
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
#define pg_log_warning(...)
References closedir(), dirent::d_name, opendir(), palloc(), pg_log_warning, pstrdup(), readdir(), and repalloc().
Referenced by scan_available_timezones().
◆ pgfnames_cleanup()
void pgfnames_cleanup | ( | char ** | filenames | ) |
---|
◆ pipe_read_line()
char * pipe_read_line | ( | char * | cmd | ) |
---|
Definition at line 352 of file exec.c.
353{
354 FILE *pipe_cmd;
355 char *line;
356
357 fflush(NULL);
358
359 errno = 0;
360 if ((pipe_cmd = popen(cmd, "r")) == NULL)
361 {
363 _("could not execute command \"%s\": %m"), cmd);
364 return NULL;
365 }
366
367
368 errno = 0;
370
371 if (line == NULL)
372 {
373 if (ferror(pipe_cmd))
375 _("could not read from command \"%s\": %m"), cmd);
376 else
378 _("no data was returned by command \"%s\""), cmd);
379 }
380
382
383 return line;
384}
int pclose_check(FILE *stream)
int errcode_for_file_access(void)
char * pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
References _, errcode(), errcode_for_file_access(), log_error, pclose_check(), and pg_get_line().
Referenced by check_exec(), find_other_exec(), and getRestoreCommand().
◆ pqsignal()
Definition at line 42 of file legacy-pqsignal.c.
43{
44#ifndef WIN32
45 struct sigaction act,
46 oact;
47
48 act.sa_handler = func;
49 sigemptyset(&act.sa_mask);
50 act.sa_flags = 0;
52 act.sa_flags |= SA_RESTART;
53#ifdef SA_NOCLDSTOP
55 act.sa_flags |= SA_NOCLDSTOP;
56#endif
57 if (sigaction(signo, &act, &oact) < 0)
58 return SIG_ERR;
59 return oact.sa_handler;
60#else
61 return signal(signo, func);
62#endif
63}
References SIGALRM, and SIGCHLD.
◆ qsort_arg()
Referenced by _bt_sort_array_elements(), create_list_bounds(), create_range_bounds(), gbt_num_picksplit(), gbt_var_picksplit(), ginExtractEntries(), mcelem_array_selec(), multirange_canonicalize(), range_deduplicate_values(), range_gist_double_sorting_split(), range_gist_single_sorting_split(), reduce_expanded_ranges(), sort_expanded_ranges(), SortAndUniqItems(), spg_range_quad_picksplit(), startScanKey(), tbm_prepare_shared_iterate(), tsvectorrecv(), uniqueentry(), and uniqueifyJsonbObject().
◆ qsort_interruptible()
void qsort_interruptible | ( | void * | base, |
---|---|---|---|
size_t | nel, | ||
size_t | elsize, | ||
qsort_arg_comparator | cmp, | ||
void * | arg | ||
) |
◆ rmtree()
bool rmtree | ( | const char * | path, |
---|---|---|---|
bool | rmtopdir | ||
) |
Definition at line 50 of file rmtree.c.
51{
55 bool result = true;
56 size_t dirnames_size = 0;
57 size_t dirnames_capacity = 8;
58 char **dirnames;
59
61 if (dir == NULL)
62 {
63 pg_log_warning("could not open directory \"%s\": %m", path);
64 return false;
65 }
66
67 dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
68
69 while (errno = 0, (de = readdir(dir)))
70 {
71 if (strcmp(de->d_name, ".") == 0 ||
72 strcmp(de->d_name, "..") == 0)
73 continue;
74 snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
76 {
78
79 break;
81
82
83
84
85
86 if (dirnames_size == dirnames_capacity)
87 {
89 sizeof(char *) * dirnames_capacity * 2);
90 dirnames_capacity *= 2;
91 }
92 dirnames[dirnames_size++] = pstrdup(pathbuf);
93 break;
94 default:
95 if (unlink(pathbuf) != 0 && errno != ENOENT)
96 {
97 pg_log_warning("could not remove file \"%s\": %m", pathbuf);
98 result = false;
99 }
100 break;
101 }
102 }
103
104 if (errno != 0)
105 {
106 pg_log_warning("could not read directory \"%s\": %m", path);
107 result = false;
108 }
109
111
112
113 for (size_t i = 0; i < dirnames_size; ++i)
114 {
115 if ((dirnames[i], true))
116 result = false;
118 }
119
120 if (rmtopdir)
121 {
122 if (rmdir(path) != 0)
123 {
124 pg_log_warning("could not remove directory \"%s\": %m", path);
125 result = false;
126 }
127 }
128
130
131 return result;
132}
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
bool rmtree(const char *path, bool rmtopdir)
#define pg_log_warning(...)
References CLOSEDIR, dirent::d_name, get_dirent_type(), i, LOG_LEVEL, MAXPGPATH, OPENDIR, palloc(), pfree(), pg_log_warning, PGFILETYPE_DIR, PGFILETYPE_ERROR, pstrdup(), readdir(), repalloc(), rmtree(), and snprintf.
Referenced by cleanup_directories_atexit(), cleanup_output_dirs(), CreateSlotOnDisk(), dbase_redo(), movedb(), movedb_failure_callback(), regression_main(), remove_dbtablespaces(), remove_new_subdir(), ReplicationSlotDropPtr(), RestoreSlotFromDisk(), rmtree(), and StartupReplicationSlots().
◆ set_pglocale_pgservice()
void set_pglocale_pgservice | ( | const char * | argv0, |
---|---|---|---|
const char * | app | ||
) |
Definition at line 429 of file exec.c.
430{
433
434
436 {
438
439
440
441
442
443
444
445
446
447
448 }
449
451 return;
452
453#ifdef ENABLE_NLS
455 bindtextdomain(app, path);
456 textdomain(app);
457
458 setenv("PGLOCALEDIR", path, 0);
459#endif
460
461 if (getenv("PGSYSCONFDIR") == NULL)
462 {
464
465 setenv("PGSYSCONFDIR", path, 0);
466 }
467}
#define PG_TEXTDOMAIN(domain)
void get_locale_path(const char *my_exec_path, char *ret_path)
void get_etc_path(const char *my_exec_path, char *ret_path)
References argv0, find_my_exec(), get_etc_path(), get_locale_path(), MAXPGPATH, my_exec_path, PG_TEXTDOMAIN, setenv, and setlocale.
Referenced by main(), and regression_main().
◆ strlcat()
size_t strlcat | ( | char * | dst, |
---|---|---|---|
const char * | src, | ||
size_t | siz | ||
) |
◆ strlcpy()
size_t strlcpy | ( | char * | dst, |
---|---|---|---|
const char * | src, | ||
size_t | siz | ||
) |
Definition at line 45 of file strlcpy.c.
46{
47 char *d = dst;
48 const char *s = src;
49 size_t n = siz;
50
51
52 if (n != 0)
53 {
54 while (--n != 0)
55 {
56 if ((*d++ = *s++) == '\0')
57 break;
58 }
59 }
60
61
62 if (n == 0)
63 {
64 if (siz != 0)
65 *d = '\0';
66 while (*s++)
67 ;
68 }
69
70 return (s - src - 1);
71}
Referenced by _pgstat64(), _tarGetHeader(), AbsoluteConfigLocation(), abstime2tm(), astreamer_inject_file(), astreamer_tar_header(), BaseBackup(), be_tls_get_peer_issuer_name(), be_tls_get_peer_serial(), be_tls_get_peer_subject_name(), BootstrapModeMain(), ChooseConstraintName(), ChooseExtendedStatisticName(), ChooseExtendedStatisticNameAddition(), ChooseForeignKeyConstraintNameAddition(), ChooseIndexNameAddition(), ChooseRelationName(), CleanupPriorWALFiles(), close_walfile(), ConvertTimeZoneAbbrevs(), create_script_for_old_cluster_deletion(), DCH_cache_getnew(), DecodeTimezoneAbbrev(), DefineRelation(), descriptor_variable(), DetermineTimeZoneAbbrevOffsetInternal(), do_pg_backup_start(), ensureCleanShutdown(), expand_tilde(), fetch_fp_info(), find_in_path(), find_my_exec(), find_other_exec_or_die(), from_char_parse_int_len(), fsync_parent_path(), get_configdata(), get_control_data(), get_dbname_oid_list_from_mfile(), get_exec_path(), get_extension_control_directories(), get_home_path(), get_prompt(), get_tablespace_mapping(), getRestoreCommand(), gnuish_strerror_r(), hash_create(), identify_system_timezone(), initialize_SSL(), InitPostgres(), injection_wait(), InjectionPointAttach(), isolation_init(), join_path_components(), KeepFileRestoredFromArchive(), logfile_getname(), logicalrep_read_begin_prepare(), logicalrep_read_commit_prepared(), logicalrep_read_prepare_common(), logicalrep_read_rollback_prepared(), main(), make_oper_cache_key(), make_relative_path(), mdsyncfiletag(), mdunlinkfiletag(), normalize_exec_path(), NUM_cache_getnew(), parse_include(), ParseAbortRecord(), parseCommandLine(), ParseCommitRecord(), ParseLongOption(), parseServiceInfo(), pg_getnameinfo_all(), pg_open_tzfile(), pg_perm_setlocale(), pg_stat_get_wal_receiver(), pg_timezone_abbrevs_abbrevs(), pg_TZDIR(), pg_tzenumerate_next(), pgstat_bestart_initial(), pgstat_bestart_security(), postprocess_sql_command(), PQcancel(), pqGetErrorNotice3(), pqGetHomeDirectory(), pqParseInput3(), PQrequestCancel(), process_directory_recursively(), process_file(), process_postgres_switches(), px_crypt_des(), recoveryStopsAfter(), RequestNamedLWLockTranche(), RequestXLogStreaming(), results_differ(), rot13_passphrase(), scan_available_timezones(), scan_directory(), scan_directory_ci(), scan_for_existing_tablespaces(), SerializeLibraryState(), setup_bin_paths(), SimpleLruInit(), SSLerrmessage(), tar_close(), tarCreateHeader(), timestamptz_to_str(), TimeZoneAbbrevIsKnown(), uuid_generate_internal(), validate_exec(), WaitEventCustomNew(), WalReceiverMain(), and XLogRestorePoint().
◆ strnlen()
size_t strnlen | ( | const char * | str, |
---|---|---|---|
size_t | maxlen | ||
) |
◆ strsep()
char * strsep | ( | char ** | stringp, |
---|---|---|---|
const char * | delim | ||
) |
Definition at line 49 of file strsep.c.
50{
51 char *s;
52 const char *spanp;
53 int c,
54 sc;
55 char *tok;
56
57 if ((s = *stringp) == NULL)
58 return (NULL);
59 for (tok = s;;)
60 {
61 c = *s++;
62 spanp = delim;
63 do
64 {
65 if ((sc = *spanp++) == c)
66 {
67 if (c == 0)
68 s = NULL;
69 else
70 s[-1] = 0;
71 *stringp = s;
72 return (tok);
73 }
74 } while (sc != 0);
75 }
76
77}
Referenced by parse_scram_secret(), pg_logging_init(), and split_to_stringlist().
◆ timingsafe_bcmp()
int timingsafe_bcmp | ( | const void * | b1, |
---|---|---|---|
const void * | b2, | ||
size_t | len | ||
) |
Definition at line 30 of file timingsafe_bcmp.c.
31{
32#ifdef USE_SSL
33 return CRYPTO_memcmp(b1, b2, n);
34#else
35 const unsigned char *p1 = b1,
36 *p2 = b2;
37 int ret = 0;
38
39 for (; n > 0; n--)
40 ret |= *p1++ ^ *p2++;
41 return (ret != 0);
42#endif
43}
Referenced by SendCancelRequest().
◆ validate_exec()
int validate_exec | ( | const char * | path | ) |
---|
Definition at line 88 of file exec.c.
89{
91 int is_r;
92 int is_x;
93
94#ifdef WIN32
95 char path_exe[MAXPGPATH + sizeof(".exe") - 1];
96
97
98 if (strlen(path) < strlen(".exe") ||
99 pg_strcasecmp(path + strlen(path) - strlen(".exe"), ".exe") != 0)
100 {
101 strlcpy(path_exe, path, sizeof(path_exe) - 4);
102 strcat(path_exe, ".exe");
103 path = path_exe;
104 }
105#endif
106
107
108
109
110
111
112
114 return -1;
115
117 {
118
119
120
121
122
123
124 errno = S_ISDIR(buf.st_mode) ? EISDIR : EPERM;
125 return -1;
126 }
127
128
129
130
131
132#ifndef WIN32
133 is_r = (access(path, R_OK) == 0);
134 is_x = (access(path, X_OK) == 0);
135
136#else
139 errno = EACCES;
140#endif
141 return is_x ? (is_r ? 0 : -2) : -1;
142}
References buf, MAXPGPATH, pg_strcasecmp(), S_IRUSR, S_ISDIR, S_ISREG, S_IXUSR, stat, and strlcpy().
Referenced by check_exec(), find_my_exec(), and find_other_exec().
◆ wait_result_is_any_signal()
bool wait_result_is_any_signal | ( | int | exit_status, |
---|---|---|---|
bool | include_command_not_found | ||
) |
◆ wait_result_is_signal()
bool wait_result_is_signal | ( | int | exit_status, |
---|---|---|---|
int | signum | ||
) |
◆ wait_result_to_exit_code()
int wait_result_to_exit_code | ( | int | exit_status | ) |
---|
◆ wait_result_to_str()
char * wait_result_to_str | ( | int | exitstatus | ) |
---|
Definition at line 33 of file wait_error.c.
34{
35 char str[512];
36
37
38
39
40
41
42 if (exitstatus == -1)
43 {
45 }
47 {
48
49
50
51
53 {
54 case 126:
56 break;
57
58 case 127:
60 break;
61
62 default:
64 _("child process exited with exit code %d"),
66 }
67 }
69 {
70#if defined(WIN32)
72 _("child process was terminated by exception 0x%X"),
74#else
76 _("child process was terminated by signal %d: %s"),
78#endif
79 }
80 else
82 _("child process exited with unrecognized status %d"),
83 exitstatus);
84
86}
const char * pg_strsignal(int signum)
References _, pg_strsignal(), pstrdup(), snprintf, str, WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.
Referenced by adjust_data_dir(), BaseBackup(), ClosePipeFromProgram(), ClosePipeToProgram(), do_copy(), exec_command_write(), ExecuteRecoveryCommand(), get_bin_version(), get_control_data(), modify_subscriber_sysid(), pclose_check(), RestoreArchivedFile(), run_ssl_passphrase_command(), and shell_finish_command().