b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From d5daf15c2098040b8b01753d3cdce8c1c79fc528 Mon Sep 17 00:00:00 2001 |
| 2 | From: David Seifert <soap@gentoo.org> |
| 3 | Date: Fri, 10 Feb 2017 21:30:49 +0100 |
| 4 | Subject: [PATCH] Use `static inline` instead of `inline` |
| 5 | |
| 6 | `inline` by itself is not portably guaranteed to emit |
| 7 | an external definition when needed in C99. The current |
| 8 | code base implicitly relies on GNU89 inline semantics, |
| 9 | which _always_ emit an external definition. More recent |
| 10 | versions of GCC and Clang switch to C99/C11 inline semantics |
| 11 | by default, which fails with undefined references. |
| 12 | |
| 13 | See also: |
| 14 | * http://www.greenend.org.uk/rjk/tech/inline.html |
| 15 | * https://clang.llvm.org/compatibility.html#inline |
| 16 | * http://blahg.josefsipek.net/?p=529 |
| 17 | --- |
| 18 | src/bwm-ng.c | 4 ++-- |
| 19 | src/help.c | 4 ++-- |
| 20 | src/options.c | 16 ++++++++-------- |
| 21 | src/output.c | 22 +++++++++++----------- |
| 22 | src/process.c | 28 ++++++++++++++-------------- |
| 23 | 5 files changed, 37 insertions(+), 37 deletions(-) |
| 24 | |
| 25 | --- a/src/bwm-ng.c |
| 26 | +++ b/src/bwm-ng.c |
| 27 | @@ -26,7 +26,7 @@ |
| 28 | |
| 29 | /* handle interrupt signal */ |
| 30 | void sigint(int sig) FUNCATTR_NORETURN; |
| 31 | -inline void init(void); |
| 32 | +static inline void init(void); |
| 33 | |
| 34 | /* clear stuff and exit */ |
| 35 | #ifdef __STDC__ |
| 36 | @@ -98,7 +98,7 @@ void sigint(int sig) { |
| 37 | deinit(0, NULL); |
| 38 | } |
| 39 | |
| 40 | -inline void init(void) { |
| 41 | +static inline void init(void) { |
| 42 | if_count=0; |
| 43 | delay=500; |
| 44 | #if EXTENDED_STATS |
| 45 | --- a/src/help.c |
| 46 | +++ b/src/help.c |
| 47 | @@ -24,9 +24,9 @@ |
| 48 | #include "global_vars.h" |
| 49 | #include "help.h" |
| 50 | |
| 51 | -inline void print_help_line(const char *short_c,const char * long_c,const char *descr); |
| 52 | +static inline void print_help_line(const char *short_c,const char * long_c,const char *descr); |
| 53 | |
| 54 | -inline void print_help_line(const char *short_c,const char * long_c,const char *descr) { |
| 55 | +static inline void print_help_line(const char *short_c,const char * long_c,const char *descr) { |
| 56 | #ifdef LONG_OPTIONS |
| 57 | printf(" %-23s",long_c); |
| 58 | #else |
| 59 | --- a/src/options.c |
| 60 | +++ b/src/options.c |
| 61 | @@ -30,12 +30,12 @@ static char* getToken(char** str, const |
| 62 | char *trim_whitespace(char *str); |
| 63 | int read_config(const char *config_file); |
| 64 | #endif |
| 65 | -inline int str2output_unit(char *optarg); |
| 66 | +static inline int str2output_unit(char *optarg); |
| 67 | #if EXTENDED_STATS |
| 68 | -inline int str2output_type(char *optarg); |
| 69 | +static inline int str2output_type(char *optarg); |
| 70 | #endif |
| 71 | -inline int str2out_method(char *optarg); |
| 72 | -inline int str2in_method(char *optarg); |
| 73 | +static inline int str2out_method(char *optarg); |
| 74 | +static inline int str2in_method(char *optarg); |
| 75 | |
| 76 | #ifdef CONFIG_FILE |
| 77 | /****************************************************************************** |
| 78 | @@ -65,7 +65,7 @@ static char* getToken(char** str, const |
| 79 | /******************************************************************************/ |
| 80 | #endif |
| 81 | |
| 82 | -inline int str2output_unit(char *optarg) { |
| 83 | +static inline int str2output_unit(char *optarg) { |
| 84 | if (optarg) { |
| 85 | if (!strcasecmp(optarg,"bytes")) return BYTES_OUT; |
| 86 | if (!strcasecmp(optarg,"bits")) return BITS_OUT; |
| 87 | @@ -76,7 +76,7 @@ inline int str2output_unit(char *optarg) |
| 88 | } |
| 89 | |
| 90 | #if EXTENDED_STATS |
| 91 | -inline int str2output_type(char *optarg) { |
| 92 | +static inline int str2output_type(char *optarg) { |
| 93 | if (optarg) { |
| 94 | if (!strcasecmp(optarg,"rate")) return RATE_OUT; |
| 95 | if (!strcasecmp(optarg,"max")) return MAX_OUT; |
| 96 | @@ -87,7 +87,7 @@ inline int str2output_type(char *optarg) |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | -inline int str2out_method(char *optarg) { |
| 101 | +static inline int str2out_method(char *optarg) { |
| 102 | if (optarg) { |
| 103 | if (!strcasecmp(optarg,"plain")) return PLAIN_OUT; |
| 104 | #ifdef HAVE_CURSES |
| 105 | @@ -109,7 +109,7 @@ inline int str2out_method(char *optarg) |
| 106 | } |
| 107 | |
| 108 | |
| 109 | -inline int str2in_method(char *optarg) { |
| 110 | +static inline int str2in_method(char *optarg) { |
| 111 | if (optarg) { |
| 112 | #ifdef PROC_NET_DEV |
| 113 | if (!strcasecmp(optarg,"proc")) return PROC_IN; |
| 114 | --- a/src/output.c |
| 115 | +++ b/src/output.c |
| 116 | @@ -25,13 +25,13 @@ |
| 117 | #include "output.h" |
| 118 | |
| 119 | inline static const char *output_type2str(void); |
| 120 | -inline const char *input2str(void); |
| 121 | -inline const char *show_all_if2str(void); |
| 122 | -inline ullong direction2value(char mode,struct inout_long stats); |
| 123 | +static inline const char *input2str(void); |
| 124 | +static inline const char *show_all_if2str(void); |
| 125 | +static inline ullong direction2value(char mode,struct inout_long stats); |
| 126 | #if EXTENDED_STATS |
| 127 | -inline double direction_max2value(char mode,struct inouttotal_double stats,int items); |
| 128 | +static inline double direction_max2value(char mode,struct inouttotal_double stats,int items); |
| 129 | #endif |
| 130 | -inline char *dyn_byte_value2str(double value,char *str,int buf_size); |
| 131 | +static inline char *dyn_byte_value2str(double value,char *str,int buf_size); |
| 132 | char *values2str(char mode,t_iface_speed_stats stats,t_iface_stats full_stats,float multiplier,char *str,int buf_size); |
| 133 | |
| 134 | inline static const char *output_type2str(void) { |
| 135 | @@ -59,7 +59,7 @@ inline static const char *output_type2st |
| 136 | } |
| 137 | |
| 138 | |
| 139 | -inline const char *input2str(void) { |
| 140 | +static inline const char *input2str(void) { |
| 141 | switch (input_method) { |
| 142 | #ifdef SYSCTL |
| 143 | case SYSCTL_IN: |
| 144 | @@ -121,7 +121,7 @@ inline const char *input2str(void) { |
| 145 | return ""; |
| 146 | } |
| 147 | |
| 148 | -inline const char *show_all_if2str(void) { |
| 149 | +static inline const char *show_all_if2str(void) { |
| 150 | switch (show_all_if) { |
| 151 | case 1: |
| 152 | return " (all)"; |
| 153 | @@ -262,7 +262,7 @@ int print_header(int option) { |
| 154 | } |
| 155 | |
| 156 | |
| 157 | -inline ullong direction2value(char mode,struct inout_long stats) { |
| 158 | +static inline ullong direction2value(char mode,struct inout_long stats) { |
| 159 | switch (mode) { |
| 160 | case 0: |
| 161 | return stats.in; |
| 162 | @@ -275,7 +275,7 @@ inline ullong direction2value(char mode, |
| 163 | } |
| 164 | |
| 165 | #if EXTENDED_STATS |
| 166 | -inline double direction_max2value(char mode,struct inouttotal_double stats,int items) { |
| 167 | +static inline double direction_max2value(char mode,struct inouttotal_double stats,int items) { |
| 168 | switch (mode) { |
| 169 | case 0: |
| 170 | return (double)(stats.in/items); |
| 171 | @@ -288,7 +288,7 @@ inline double direction_max2value(char m |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | -inline char *dyn_byte_value2str(double value,char *str,int buf_size) { |
| 176 | +static inline char *dyn_byte_value2str(double value,char *str,int buf_size) { |
| 177 | if (dynamic) { |
| 178 | if (value<1024) |
| 179 | snprintf(str,buf_size,"%15.2f ",value); |
| 180 | @@ -306,7 +306,7 @@ inline char *dyn_byte_value2str(double v |
| 181 | return str; |
| 182 | } |
| 183 | |
| 184 | -inline char *dyn_bit_value2str(double value,char *str,int buf_size) { |
| 185 | +static inline char *dyn_bit_value2str(double value,char *str,int buf_size) { |
| 186 | if (dynamic) { |
| 187 | if (value<1000) |
| 188 | snprintf(str,buf_size,"%15.2f ",value); |
| 189 | --- a/src/process.c |
| 190 | +++ b/src/process.c |
| 191 | @@ -26,19 +26,19 @@ |
| 192 | |
| 193 | short show_iface(char *instr, char *searchstr,char iface_is_up); |
| 194 | #if HAVE_GETTIMEOFDAY |
| 195 | -inline long tvdiff(struct timeval newer, struct timeval older); |
| 196 | +static inline long tvdiff(struct timeval newer, struct timeval older); |
| 197 | float get_time_delay(int iface_num); |
| 198 | #endif |
| 199 | -inline ullong calc_new_values(ullong new, ullong old); |
| 200 | +static inline ullong calc_new_values(ullong new, ullong old); |
| 201 | t_iface_speed_stats convert2calced_values(t_iface_speed_stats new, t_iface_speed_stats old); |
| 202 | t_iface_speed_stats convert2calced_disk_values(t_iface_speed_stats new, t_iface_speed_stats old); |
| 203 | #if EXTENDED_STATS |
| 204 | -inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data); |
| 205 | -inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data); |
| 206 | -inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier); |
| 207 | +static inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data); |
| 208 | +static inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data); |
| 209 | +static inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier); |
| 210 | void save_avg(struct t_avg *avg,struct iface_speed_stats calced_stats,float multiplier); |
| 211 | -inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values); |
| 212 | -inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier); |
| 213 | +static inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values); |
| 214 | +static inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier); |
| 215 | #endif |
| 216 | |
| 217 | /* returns the whether to show the iface or not |
| 218 | @@ -74,7 +74,7 @@ short show_iface(char *instr, char *sear |
| 219 | |
| 220 | #if HAVE_GETTIMEOFDAY |
| 221 | /* Returns: the time difference in milliseconds. */ |
| 222 | -inline long tvdiff(struct timeval newer, struct timeval older) { |
| 223 | +static inline long tvdiff(struct timeval newer, struct timeval older) { |
| 224 | return labs((newer.tv_sec-older.tv_sec)*1000+ |
| 225 | (newer.tv_usec-older.tv_usec)/1000); |
| 226 | } |
| 227 | @@ -92,7 +92,7 @@ float get_time_delay(int iface_num) { |
| 228 | #endif |
| 229 | |
| 230 | /* basically new-old, but handles "overflow" of source aswell */ |
| 231 | -inline ullong calc_new_values(ullong new, ullong old) { |
| 232 | +static inline ullong calc_new_values(ullong new, ullong old) { |
| 233 | /* FIXME: WRAP_AROUND _might_ be wrong for libstatgrab, where the type is always long long */ |
| 234 | return (new>=old) ? (ullong)(new-old) : (ullong)(( |
| 235 | #ifdef HAVE_LIBKSTAT |
| 236 | @@ -133,13 +133,13 @@ t_iface_speed_stats convert2calced_disk_ |
| 237 | |
| 238 | #if EXTENDED_STATS |
| 239 | /* sub old values from cached for avg stats */ |
| 240 | -inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { |
| 241 | +static inline void sub_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { |
| 242 | values->in-=data.in; |
| 243 | values->out-=data.out; |
| 244 | values->total-=data.total; |
| 245 | } |
| 246 | |
| 247 | -inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { |
| 248 | +static inline void add_avg_values(struct inouttotal_double *values,struct inouttotal_double data) { |
| 249 | values->in+=data.in; |
| 250 | values->out+=data.out; |
| 251 | values->total+=data.total; |
| 252 | @@ -148,7 +148,7 @@ inline void add_avg_values(struct inoutt |
| 253 | |
| 254 | /* put new-old bytes in inout_long struct into a inouttotal_double struct |
| 255 | * and add values to cached .value struct */ |
| 256 | -inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier) { |
| 257 | +static inline void save_avg_values(struct inouttotal_double *values,struct inouttotal_double *data,struct inout_long calced_stats,float multiplier) { |
| 258 | data->in=calced_stats.in*multiplier; |
| 259 | data->out=calced_stats.out*multiplier; |
| 260 | data->total=(calced_stats.in+calced_stats.out)*multiplier; |
| 261 | @@ -198,13 +198,13 @@ void save_avg(struct t_avg *avg,struct i |
| 262 | } |
| 263 | |
| 264 | /* add current in and out bytes to totals struct */ |
| 265 | -inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values) { |
| 266 | +static inline void save_sum(struct inout_long *stats,struct inout_long new_stats_values) { |
| 267 | stats->in+=new_stats_values.in; |
| 268 | stats->out+=new_stats_values.out; |
| 269 | } |
| 270 | |
| 271 | /* lookup old max values and save new if higher */ |
| 272 | -inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier) { |
| 273 | +static inline void save_max(struct inouttotal_double *stats,struct inout_long calced_stats,float multiplier) { |
| 274 | if (multiplier*calced_stats.in > stats->in) |
| 275 | stats->in=multiplier*calced_stats.in; |
| 276 | if (multiplier*calced_stats.out>stats->out) |