You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
11 KiB

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