]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
formatting.c cleanup: Add some const pointer qualifiers
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 29 Oct 2025 08:27:59 +0000 (09:27 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 29 Oct 2025 08:28:50 +0000 (09:28 +0100)
Co-authored-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/6dd9d208-a3ed-49b5-b03d-8617261da973%40eisentraut.org

src/backend/utils/adt/formatting.c

index fa703f6f8b32857ebf717e6e3a33908e6a63605a..a94e00eaa0deda59b3ce569ea5c4e6077a3eede7 100644 (file)
@@ -436,7 +436,7 @@ typedef struct
        bool            has_tz;                 /* was there a TZ field? */
        int                     gmtoffset;              /* GMT offset of fixed-offset zone abbrev */
        pg_tz      *tzp;                        /* pg_tz for dynamic abbrev */
-       char       *abbrev;                     /* dynamic abbrev */
+       const char *abbrev;                     /* dynamic abbrev */
 } TmFromChar;
 
 #define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar))
@@ -1055,8 +1055,8 @@ static void dump_index(const KeyWord *k, const int *index);
 static void dump_node(FormatNode *node, int max);
 #endif
 
-static const char *get_th(char *num, int type);
-static char *str_numth(char *dest, char *num, int type);
+static const char *get_th(const char *num, int type);
+static char *str_numth(char *dest, const char *num, int type);
 static int     adjust_partial_year_to_2020(int year);
 static size_t strspace_len(const char *str);
 static bool from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode,
@@ -1074,15 +1074,15 @@ static bool from_char_seq_search(int *dest, const char **src,
                                                                 const char *const *array,
                                                                 char **localized_array, Oid collid,
                                                                 FormatNode *node, Node *escontext);
-static bool do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std,
+static bool do_to_timestamp(const text *date_txt, const text *fmt, Oid collid, bool std,
                                                        struct pg_tm *tm, fsec_t *fsec, struct fmt_tz *tz,
                                                        int *fprec, uint32 *flags, Node *escontext);
 static char *fill_str(char *str, int c, int max);
-static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
+static FormatNode *NUM_cache(int len, NUMDesc *Num, const text *pars_str, bool *shouldFree);
 static char *int_to_roman(int number);
 static int     roman_to_int(NUMProc *Np, size_t input_len);
 static void NUM_prepare_locale(NUMProc *Np);
-static char *get_last_relevant_decnum(char *num);
+static char *get_last_relevant_decnum(const char *num);
 static void NUM_numpart_from_char(NUMProc *Np, int id, size_t input_len);
 static void NUM_numpart_to_char(NUMProc *Np, int id);
 static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
@@ -1524,7 +1524,7 @@ dump_node(FormatNode *node, int max)
  * type --> 0 upper, 1 lower
  */
 static const char *
-get_th(char *num, int type)
+get_th(const char *num, int type)
 {
        size_t          len = strlen(num);
        char            last;
@@ -1570,7 +1570,7 @@ get_th(char *num, int type)
  * type --> 0 upper, 1 lower
  */
 static char *
-str_numth(char *dest, char *num, int type)
+str_numth(char *dest, const char *num, int type)
 {
        if (dest != num)
                strcpy(dest, num);
@@ -3875,7 +3875,7 @@ DCH_cache_fetch(const char *str, bool std)
  * for formatting.
  */
 static text *
-datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval, Oid collid)
+datetime_to_char_body(TmToChar *tmtc, const text *fmt, bool is_interval, Oid collid)
 {
        FormatNode *format;
        char       *fmt_str,
@@ -4371,7 +4371,7 @@ datetime_format_has_tz(const char *fmt_str)
  * struct 'tm', 'fsec', struct 'tz', and 'fprec'.
  */
 static bool
-do_to_timestamp(text *date_txt, text *fmt, Oid collid, bool std,
+do_to_timestamp(const text *date_txt, const text *fmt, Oid collid, bool std,
                                struct pg_tm *tm, fsec_t *fsec, struct fmt_tz *tz,
                                int *fprec, uint32 *flags, Node *escontext)
 {
@@ -4945,7 +4945,7 @@ NUM_cache_fetch(const char *str)
  * Cache routine for NUM to_char version
  */
 static FormatNode *
-NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)
+NUM_cache(int len, NUMDesc *Num, const text *pars_str, bool *shouldFree)
 {
        FormatNode *format = NULL;
        char       *str;
@@ -5297,7 +5297,7 @@ NUM_prepare_locale(NUMProc *Np)
  * behavior as if FM hadn't been specified).
  */
 static char *
-get_last_relevant_decnum(char *num)
+get_last_relevant_decnum(const char *num)
 {
        char       *result,
                           *p = strchr(num, '.');