Skip to content

Commit e2e5b01

Browse files
LekensteynAndersBroman
authored andcommitted
cli_main: remove real_main from stack traces for non-Windows
Restore the "main" name since that is used everywhere else except for Windows. On Windows, "main" is renamed via a macro to avoid a conflict with "wmain" and to allow it to be called in cli_main.c. For those wondering, GUI applications (such as Qt) have a different entry point, namely WinMain. In Qt5, src/winmain/qtmain_win.cpp defines WinMain, but seems to convert its arguments from Unicode to CP_ACP (ASCII). It might not support UTF-8, but I did not verify this. Change-Id: I93fa59324eb2ef95a305b08fc5ba34d49cc73bf0 Reviewed-on: https://code.wireshark.org/review/31208 Petri-Dish: Peter Wu <[email protected]> Reviewed-by: Anders Broman <[email protected]>
1 parent 974969c commit e2e5b01

18 files changed

+29
-28
lines changed

capinfos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ hash_to_str(const unsigned char *hash, size_t length, char *str) {
14001400
}
14011401

14021402
int
1403-
real_main(int argc, char *argv[])
1403+
main(int argc, char *argv[])
14041404
{
14051405
char *init_progfile_dir_error;
14061406
wtap *wth;

captype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ failure_message_cont(const char *msg_format, va_list ap)
7878
}
7979

8080
int
81-
real_main(int argc, char *argv[])
81+
main(int argc, char *argv[])
8282
{
8383
char *init_progfile_dir_error;
8484
wtap *wth;

cli_main.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Compile and link this with all CLI programs where the main routine
3-
* should get UTF-8 arguments on Windows. In those programs, declare
4-
* the main program as real_main() rather than main().
3+
* should get UTF-8 arguments on Windows. In those programs, include the
4+
* cli_main.h header to rename main to real_main on Windows.
55
*
66
* This is used in software licensed under the GPLv2, and its license MUST
77
* be compatible with that license.
@@ -62,12 +62,11 @@ wmain(int argc, wchar_t *wc_argv[])
6262
argv[i] = utf8_string;
6363
}
6464
argv[i] = NULL;
65-
return real_main(argc, argv);
66-
}
67-
#else /* _WIN32 */
68-
int
69-
main(int argc, char *argv[])
70-
{
65+
/*
66+
* The original "main" routine was renamed to "real_main" via a macro in
67+
* the cli_main.h header file since either "main" or "wmain" can be
68+
* defined on Windows, but not both.
69+
*/
7170
return real_main(argc, argv);
7271
}
7372
#endif

cli_main.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*
22
* Declaration of the real main routine, for all CLI programs where the
33
* main routine should get UTF-8 arguments on Windows. In those programs,
4-
* in the file that defines the main routine, include this header and define
5-
* the main routine as real_main() rather than main(), and build those
6-
* programs with cli_main.c and link with the object file.
4+
* in the file that defines the main routine, include this header and link
5+
* those programs with cli_main.c.
76
*
87
* This is used in software licensed under the GPLv2, and its license MUST
98
* be compatible with that license.
@@ -16,4 +15,7 @@
1615
* SPDX-License-Identifier: MIT
1716
*/
1817

19-
extern int real_main(int argc, char *argv[]);
18+
#ifdef _WIN32
19+
int real_main(int argc, char *argv[]);
20+
#define main real_main
21+
#endif

dumpcap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4656,7 +4656,7 @@ get_dumpcap_runtime_info(GString *str)
46564656

46574657
/* And now our feature presentation... [ fade to music ] */
46584658
int
4659-
real_main(int argc, char *argv[])
4659+
main(int argc, char *argv[])
46604660
{
46614661
int opt;
46624662
static const struct option long_options[] = {

editcap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ editcap_dump_open(const char *filename, const wtap_dump_params *params,
982982
}
983983

984984
int
985-
real_main(int argc, char *argv[])
985+
main(int argc, char *argv[])
986986
{
987987
char *init_progfile_dir_error;
988988
wtap *wth = NULL;

extcap/androiddump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ static int capture_android_tcpdump(char *interface, char *fifo,
24802480
return EXIT_CODE_SUCCESS;
24812481
}
24822482

2483-
int real_main(int argc, char **argv) {
2483+
int main(int argc, char *argv[]) {
24842484
int ret = EXIT_CODE_GENERIC;
24852485
int option_idx = 0;
24862486
int result;

extcap/ciscodump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int list_config(char *interface, unsigned int remote_port)
515515
return EXIT_SUCCESS;
516516
}
517517

518-
int real_main(int argc, char **argv)
518+
int main(int argc, char *argv[])
519519
{
520520
int result;
521521
int option_idx = 0;

extcap/randpktdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int list_config(char *interface)
121121
return EXIT_SUCCESS;
122122
}
123123

124-
int real_main(int argc, char *argv[])
124+
int main(int argc, char *argv[])
125125
{
126126
int option_idx = 0;
127127
int result;

extcap/sshdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static char* concat_filters(const char* extcap_filter, const char* remote_filter
329329
return g_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter);
330330
}
331331

332-
int real_main(int argc, char **argv)
332+
int main(int argc, char *argv[])
333333
{
334334
int result;
335335
int option_idx = 0;

extcap/udpdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static void run_listener(const char* fifo, const guint16 port, const char* proto
356356
g_free(buf);
357357
}
358358

359-
int real_main(int argc, char *argv[])
359+
int main(int argc, char *argv[])
360360
{
361361
int option_idx = 0;
362362
int result;

mergecap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ merge_callback(merge_event event, int num,
227227
}
228228

229229
int
230-
real_main(int argc, char *argv[])
230+
main(int argc, char *argv[])
231231
{
232232
char *init_progfile_dir_error;
233233
int opt;

randpkt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ usage(gboolean is_error)
100100
}
101101

102102
int
103-
real_main(int argc, char **argv)
103+
main(int argc, char *argv[])
104104
{
105105
char *init_progfile_dir_error;
106106
int opt;

rawshark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ set_link_type(const char *lt_arg) {
403403
}
404404

405405
int
406-
real_main(int argc, char *argv[])
406+
main(int argc, char *argv[])
407407
{
408408
char *init_progfile_dir_error;
409409
int opt, i;

reordercap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ failure_message_cont(const char *msg_format, va_list ap)
161161
/* Main function. */
162162
/********************************************************************/
163163
int
164-
real_main(int argc, char *argv[])
164+
main(int argc, char *argv[])
165165
{
166166
char *init_progfile_dir_error;
167167
wtap *wth = NULL;

text2pcap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ parse_options (int argc, char *argv[])
18531853
}
18541854

18551855
int
1856-
real_main(int argc, char *argv[])
1856+
main(int argc, char *argv[])
18571857
{
18581858
int ret = EXIT_SUCCESS;
18591859

tfshark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ get_tfshark_runtime_version_info(GString *str)
300300
}
301301

302302
int
303-
real_main(int argc, char *argv[])
303+
main(int argc, char *argv[])
304304
{
305305
char *init_progfile_dir_error;
306306
int opt;

tshark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ must_do_dissection(dfilter_t *rfcode, dfilter_t *dfcode,
670670
}
671671

672672
int
673-
real_main(int argc, char *argv[])
673+
main(int argc, char *argv[])
674674
{
675675
char *init_progfile_dir_error;
676676
int opt;

0 commit comments

Comments
 (0)