diff --git a/include/h.h b/include/h.h index efb96d996..ebce77dec 100644 --- a/include/h.h +++ b/include/h.h @@ -194,7 +194,7 @@ extern MODVAR char *debugmode, *configfile, *sbrk0; extern char *getfield(char *); extern void set_sockhost(Client *, const char *); #ifdef _WIN32 -extern char *sock_strerror(int); +extern const char *sock_strerror(int); #endif extern int dgets(int, char *, int); @@ -657,8 +657,8 @@ extern int callbacks_check(void); extern void callbacks_switchover(void); extern int efunctions_check(void); extern void efunctions_switchover(void); -extern char *encode_ip(char *); -extern char *decode_ip(char *); +extern char *encode_ip(const char *); +extern char *decode_ip(const char *); extern void sendto_one_nickcmd(Client *server, MessageTag *mtags, Client *client, char *umodes); extern int on_dccallow_list(Client *to, Client *from); extern int add_dccallow(Client *client, Client *optr); @@ -919,7 +919,7 @@ extern CMD_FUNC(cmd_rehash); extern CMD_FUNC(cmd_die); extern CMD_FUNC(cmd_restart); extern void cmd_alias(Client *client, MessageTag *recv_mtags, int parc, char *parv[], char *cmd); /* special! */ -extern char *pcre2_version(void); +extern const char *pcre2_version(void); extern int get_terminal_width(void); extern int has_common_channels(Client *c1, Client *c2); extern int user_can_see_member(Client *user, Client *target, Channel *channel); @@ -1048,11 +1048,11 @@ extern void add_fmt_nvplist(NameValuePrioList **lst, int priority, const char *n extern NameValuePrioList *find_nvplist(NameValuePrioList *list, const char *name); extern void free_nvplist(NameValuePrioList *lst); extern const char *get_connect_extinfo(Client *client); -extern char *unreal_strftime(char *str); +extern char *unreal_strftime(const char *str); extern void strtolower(char *str); -extern void strtolower_safe(char *dst, char *src, int size); +extern void strtolower_safe(char *dst, const char *src, int size); extern void strtoupper(char *str); -extern void strtoupper_safe(char *dst, char *src, int size); +extern void strtoupper_safe(char *dst, const char *src, int size); extern int running_interactively(void); extern int terminal_supports_color(void); extern void skip_whitespace(char **p); diff --git a/include/proto.h b/include/proto.h index c1b5f59c8..d5d2d5c19 100644 --- a/include/proto.h +++ b/include/proto.h @@ -43,7 +43,7 @@ extern EVENT(handshake_timeout); extern EVENT(check_deadsockets); extern EVENT(try_connections); /* support.c */ -extern char *my_itoa(int i); +extern const char *my_itoa(int i); /* s_serv.c */ extern void load_tunefile(void); diff --git a/src/support.c b/src/support.c index de74c99a8..c2243232b 100644 --- a/src/support.c +++ b/src/support.c @@ -34,7 +34,7 @@ extern void outofmemory(); #define is_enabled match /** Convert integer to string */ -char *my_itoa(int i) +const char *my_itoa(int i) { static char buf[128]; ircsnprintf(buf, sizeof(buf), "%d", i); @@ -1056,7 +1056,7 @@ time_t unreal_getfilemodtime(const char *filename) #endif /** Encode an IP string (eg: "1.2.3.4") to a BASE64 encoded value for S2S traffic */ -char *encode_ip(char *ip) +char *encode_ip(const char *ip) { static char retbuf[25]; /* returned string */ char addrbuf[16]; @@ -1089,7 +1089,7 @@ char *encode_ip(char *ip) } /** Decode a BASE64 encoded string to an IP address string. Used for S2S traffic. */ -char *decode_ip(char *buf) +char *decode_ip(const char *buf) { int n; char targ[25]; @@ -1183,7 +1183,7 @@ struct u_WSA_errors WSAErrors[] = { }; /** Get socket error string */ -char *sock_strerror(int error) +const char *sock_strerror(int error) { static char unkerr[64]; int start = 0; @@ -1299,7 +1299,7 @@ literal: } /** Return the PCRE2 library version in use */ -char *pcre2_version(void) +const char *pcre2_version(void) { static char buf[256]; @@ -1350,7 +1350,7 @@ int get_terminal_width(void) #endif /** Like strftime() but easier. */ -char *unreal_strftime(char *str) +char *unreal_strftime(const char *str) { time_t t; struct tm *tmp; @@ -1359,7 +1359,11 @@ char *unreal_strftime(char *str) t = time(NULL); tmp = localtime(&t); if (!tmp || !strftime(buf, sizeof(buf), str, tmp)) - return str; + { + /* If anything fails bigtime, then return the format string */ + strlcpy(buf, str, sizeof(buf)); + return buf; + } return buf; } @@ -1368,7 +1372,7 @@ char *unreal_strftime(char *str) #endif /** Convert a string to lowercase - with separate input/output buffer */ -void strtolower_safe(char *dst, char *src, int size) +void strtolower_safe(char *dst, const char *src, int size) { if (!size) return; /* size of 0 is unworkable */ @@ -1390,7 +1394,7 @@ void strtolower(char *str) } /** Convert a string to uppercase - with separate input/output buffer */ -void strtoupper_safe(char *dst, char *src, int size) +void strtoupper_safe(char *dst, const char *src, int size) { if (!size) return; /* size of 0 is unworkable */