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.

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