Skip to content

Commit a40276c

Browse files
committed
Bug#18367457: DON'T USE #DEFINE TO REPLACE POSIX FUNCTIONS WITH WINDOWS EQUIVALENTS
Rather than globally doing #define posix_function_name windows_equivalent this patch adds inline functions which calls the appropriate function. This avoids polluting the global namespace.
1 parent d33ba17 commit a40276c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+288
-299
lines changed

client/mysql.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ int main(int argc,char *argv[])
13231323

13241324
put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.",
13251325
INFO_INFO);
1326-
snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),
1326+
my_snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),
13271327
"Your MySQL connection id is %lu\nServer version: %s\n",
13281328
mysql_thread_id(&mysql), server_version_string(&mysql));
13291329
put_info((char*) glob_buffer.ptr(),INFO_INFO);
@@ -3370,7 +3370,7 @@ static int com_server_help(String *buffer __attribute__((unused)),
33703370
else
33713371
{
33723372
put_info("\nNothing found", INFO_INFO);
3373-
if (strncasecmp(server_cmd, "help 'contents'", 15) == 0)
3373+
if (native_strncasecmp(server_cmd, "help 'contents'", 15) == 0)
33743374
{
33753375
put_info("\nPlease check if 'help tables' are loaded.\n", INFO_INFO);
33763376
goto err;

client/mysql_plugin.c

+27-23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <stdio.h>
2424
#include <string.h>
2525

26+
#ifdef _WIN32
27+
#define popen _popen
28+
#define pclose _pclose
29+
#endif
2630

2731
#define SHOW_VERSION "1.0.0"
2832
#define PRINT_VERSION do { printf("%s Ver %s Distrib %s\n", \
@@ -187,7 +191,7 @@ static char *get_value(char *line, const char *item)
187191
int item_len= (int)strlen(item);
188192
int line_len = (int)strlen(line);
189193

190-
if ((strncasecmp(line, item, item_len) == 0))
194+
if ((native_strncasecmp(line, item, item_len) == 0))
191195
{
192196
int start= 0;
193197
char *s= 0;
@@ -290,11 +294,11 @@ static char *add_quotes(const char *path)
290294
char windows_cmd_friendly[FN_REFLEN];
291295

292296
if (has_spaces(path))
293-
snprintf(windows_cmd_friendly, sizeof(windows_cmd_friendly),
294-
"\"%s\"", path);
297+
my_snprintf(windows_cmd_friendly, sizeof(windows_cmd_friendly),
298+
"\"%s\"", path);
295299
else
296-
snprintf(windows_cmd_friendly, sizeof(windows_cmd_friendly),
297-
"%s", path);
300+
my_snprintf(windows_cmd_friendly, sizeof(windows_cmd_friendly),
301+
"%s", path);
298302
return my_strdup(PSI_NOT_INSTRUMENTED,
299303
windows_cmd_friendly, MYF(MY_FAE));
300304
}
@@ -343,16 +347,16 @@ static int get_default_values()
343347
else
344348
format_str = "%s mysqld > %s";
345349

346-
snprintf(defaults_cmd, sizeof(defaults_cmd), format_str,
347-
add_quotes(tool_path), add_quotes(defaults_file));
350+
my_snprintf(defaults_cmd, sizeof(defaults_cmd), format_str,
351+
add_quotes(tool_path), add_quotes(defaults_file));
348352
if (opt_verbose)
349353
{
350354
printf("# my_print_defaults found: %s\n", tool_path);
351355
}
352356
}
353357
#else
354-
snprintf(defaults_cmd, sizeof(defaults_cmd),
355-
"%s mysqld > %s", tool_path, defaults_file);
358+
my_snprintf(defaults_cmd, sizeof(defaults_cmd),
359+
"%s mysqld > %s", tool_path, defaults_file);
356360
#endif
357361

358362
/* Execute the command */
@@ -780,29 +784,29 @@ static int check_options(int argc, char **argv, char *operation)
780784
{
781785
continue;
782786
}
783-
if ((strcasecmp(argv[i], "ENABLE") == 0) ||
784-
(strcasecmp(argv[i], "DISABLE") == 0))
787+
if ((native_strcasecmp(argv[i], "ENABLE") == 0) ||
788+
(native_strcasecmp(argv[i], "DISABLE") == 0))
785789
{
786790
strcpy(operation, argv[i]);
787791
num_found++;
788792
}
789-
else if ((strncasecmp(argv[i], basedir_prefix, basedir_len) == 0) &&
793+
else if ((native_strncasecmp(argv[i], basedir_prefix, basedir_len) == 0) &&
790794
!opt_basedir)
791795
{
792796
opt_basedir= my_strndup(PSI_NOT_INSTRUMENTED,
793797
argv[i]+basedir_len,
794798
strlen(argv[i])-basedir_len, MYF(MY_FAE));
795799
num_found++;
796800
}
797-
else if ((strncasecmp(argv[i], datadir_prefix, datadir_len) == 0) &&
801+
else if ((native_strncasecmp(argv[i], datadir_prefix, datadir_len) == 0) &&
798802
!opt_datadir)
799803
{
800804
opt_datadir= my_strndup(PSI_NOT_INSTRUMENTED,
801805
argv[i]+datadir_len,
802806
strlen(argv[i])-datadir_len, MYF(MY_FAE));
803807
num_found++;
804808
}
805-
else if ((strncasecmp(argv[i], plugin_dir_prefix, plugin_dir_len) == 0) &&
809+
else if ((native_strncasecmp(argv[i], plugin_dir_prefix, plugin_dir_len) == 0) &&
806810
!opt_plugin_dir)
807811
{
808812
opt_plugin_dir= my_strndup(PSI_NOT_INSTRUMENTED,
@@ -843,7 +847,7 @@ static int check_options(int argc, char **argv, char *operation)
843847
{
844848
return 1;
845849
}
846-
if (strcasecmp(plugin_data.name, plugin_name) != 0)
850+
if (native_strcasecmp(plugin_data.name, plugin_name) != 0)
847851
{
848852
fprintf(stderr, "ERROR: plugin name requested does not match config "
849853
"file data.\n");
@@ -1117,7 +1121,7 @@ static int build_bootstrap_file(char *operation, char *bootstrap)
11171121
error= 1;
11181122
goto exit;
11191123
}
1120-
if (strcasecmp(operation, "enable") == 0)
1124+
if (native_strcasecmp(operation, "enable") == 0)
11211125
{
11221126
int i= 0;
11231127
fprintf(file, "REPLACE INTO mysql.plugin VALUES ");
@@ -1239,14 +1243,14 @@ static int bootstrap_server(char *server_path, char *bootstrap_file)
12391243
else
12401244
format_str= "%s %s --bootstrap --datadir=%s --basedir=%s < %s";
12411245

1242-
snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), format_str,
1243-
add_quotes(convert_path(server_path)), verbose_str,
1244-
add_quotes(opt_datadir), add_quotes(opt_basedir),
1245-
add_quotes(bootstrap_file));
1246+
my_snprintf(bootstrap_cmd, sizeof(bootstrap_cmd), format_str,
1247+
add_quotes(convert_path(server_path)), verbose_str,
1248+
add_quotes(opt_datadir), add_quotes(opt_basedir),
1249+
add_quotes(bootstrap_file));
12461250
#else
1247-
snprintf(bootstrap_cmd, sizeof(bootstrap_cmd),
1248-
"%s --no-defaults --bootstrap --datadir=%s --basedir=%s"
1249-
" < %s", server_path, opt_datadir, opt_basedir, bootstrap_file);
1251+
my_snprintf(bootstrap_cmd, sizeof(bootstrap_cmd),
1252+
"%s --no-defaults --bootstrap --datadir=%s --basedir=%s"
1253+
" < %s", server_path, opt_datadir, opt_basedir, bootstrap_file);
12501254
#endif
12511255

12521256
/* Execute the command */

client/mysql_upgrade.c

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
# endif
3737
#endif
3838

39+
#ifdef _WIN32
40+
#define popen _popen
41+
#define pclose _pclose
42+
#endif
43+
3944
static char mysql_path[FN_REFLEN];
4045
static char mysqlcheck_path[FN_REFLEN];
4146

client/mysqladmin.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
801801
/* We don't use mysql_kill(), since it only handles 32-bit IDs. */
802802
char buff[26], *out; /* "KILL " + max 20 digs + NUL */
803803
out= strxmov(buff, "KILL ", NullS);
804-
ullstr(strtoull(pos, NULL, 0), out);
804+
ullstr(my_strtoull(pos, NULL, 0), out);
805805

806806
if (mysql_query(mysql, buff))
807807
{
@@ -1348,7 +1348,7 @@ static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)
13481348
printf("| %-*s|", (int) field->max_length + 1, cur[0]);
13491349

13501350
field = mysql_fetch_field(result);
1351-
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
1351+
tmp = cur[1] ? my_strtoull(cur[1], NULL, 10) : (ulonglong) 0;
13521352
printf(" %-*s|\n", (int) field->max_length + 1,
13531353
llstr((tmp - last_values[row]), buff));
13541354
last_values[row] = tmp;
@@ -1366,7 +1366,7 @@ static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)),
13661366
if (!row)
13671367
putchar('|');
13681368

1369-
tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0;
1369+
tmp = cur[1] ? my_strtoull(cur[1], NULL, 10) : (ulonglong) 0;
13701370
printf(" %-*s|", ex_val_max_len[row] + 1,
13711371
llstr((tmp - last_values[row]), buff));
13721372

@@ -1391,7 +1391,7 @@ static void store_values(MYSQL_RES *result)
13911391
for (i = 0; (row = mysql_fetch_row(result)); i++)
13921392
{
13931393
my_stpcpy(ex_var_names[i], row[0]);
1394-
last_values[i]=strtoull(row[1],NULL,10);
1394+
last_values[i]= my_strtoull(row[1],NULL,10);
13951395
ex_val_max_len[i]=2; /* Default print width for values */
13961396
}
13971397
ex_var_count = i;

client/mysqlimport.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static int write_to_table(char *filename, MYSQL *mysql)
318318
{
319319
if (verbose)
320320
fprintf(stdout, "Deleting the old data from table %s\n", tablename);
321-
snprintf(sql_statement, FN_REFLEN*16+256, "DELETE FROM %s", tablename);
321+
my_snprintf(sql_statement, FN_REFLEN*16+256, "DELETE FROM %s", tablename);
322322
if (mysql_query(mysql, sql_statement))
323323
{
324324
db_error_with_table(mysql, tablename);

client/mysqlshow.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ list_dbs(MYSQL *mysql,const char *wild)
451451
if ((rresult = mysql_store_result(mysql)))
452452
{
453453
rrow = mysql_fetch_row(rresult);
454-
rowcount += (ulong) strtoull(rrow[0], (char**) 0, 10);
454+
rowcount += (ulong) my_strtoull(rrow[0], (char**) 0, 10);
455455
mysql_free_result(rresult);
456456
}
457457
}
@@ -592,7 +592,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
592592
if ((rresult = mysql_store_result(mysql)))
593593
{
594594
rrow = mysql_fetch_row(rresult);
595-
rowcount += (unsigned long) strtoull(rrow[0], (char**) 0, 10);
595+
rowcount += (unsigned long) my_strtoull(rrow[0], (char**) 0, 10);
596596
mysql_free_result(rresult);
597597
}
598598
sprintf(rows,"%10lu",rowcount);
@@ -709,7 +709,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
709709
return 1;
710710
}
711711
row= mysql_fetch_row(result);
712-
rows= (ulong) strtoull(row[0], (char**) 0, 10);
712+
rows= (ulong) my_strtoull(row[0], (char**) 0, 10);
713713
mysql_free_result(result);
714714
}
715715

client/mysqltest.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ using std::max;
6262

6363
#ifdef _WIN32
6464
#define setenv(a,b,c) _putenv_s(a,b)
65+
#define popen _popen
66+
#define pclose _pclose
6567
#endif
6668

6769
#define MAX_VAR_NAME_LENGTH 256
@@ -1293,7 +1295,7 @@ void handle_command_error(struct st_command *command, uint error)
12931295
{
12941296
const char var_name[]= "__error";
12951297
char buf[10];
1296-
int err_len= snprintf(buf, 10, "%u", error);
1298+
int err_len= my_snprintf(buf, 10, "%u", error);
12971299
buf[err_len > 9 ? 9 : err_len]= '0';
12981300
var_set(var_name, var_name + 7, buf, buf + err_len);
12991301
}
@@ -3245,7 +3247,7 @@ void do_exec(struct st_command *command)
32453247
{
32463248
const char var_name[]= "__error";
32473249
char buf[10];
3248-
int err_len= snprintf(buf, 10, "%u", error);
3250+
int err_len= my_snprintf(buf, 10, "%u", error);
32493251
buf[err_len > 9 ? 9 : err_len]= '0';
32503252
var_set(var_name, var_name + 7, buf, buf + err_len);
32513253
}
@@ -4516,7 +4518,7 @@ int do_save_master_pos()
45164518
if (*status)
45174519
{
45184520
status+= sizeof(latest_trans_epoch_str)-1;
4519-
latest_trans_epoch= strtoull(status, (char**) 0, 10);
4521+
latest_trans_epoch= my_strtoull(status, (char**) 0, 10);
45204522
}
45214523
else
45224524
die("result does not contain '%s' in '%s'",
@@ -4530,7 +4532,7 @@ int do_save_master_pos()
45304532
if (*status)
45314533
{
45324534
status+= sizeof(latest_handled_binlog_epoch_str)-1;
4533-
latest_handled_binlog_epoch= strtoull(status, (char**) 0, 10);
4535+
latest_handled_binlog_epoch= my_strtoull(status, (char**) 0, 10);
45344536
}
45354537
else
45364538
die("result does not contain '%s' in '%s'",

cmake/os/Windows.cmake

-39
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ ELSE()
4949
SET(SYSTEM_TYPE "Win32")
5050
ENDIF()
5151

52-
ADD_DEFINITIONS("-D_CRT_SECURE_NO_DEPRECATE")
53-
5452
# Target Windows Vista or later, i.e _WIN32_WINNT_VISTA
5553
ADD_DEFINITIONS("-D_WIN32_WINNT=0x0600")
5654
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_WIN32_WINNT=0x0600")
@@ -177,43 +175,6 @@ IF(NOT HAVE_ISNAN)
177175
CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h)
178176
ENDIF()
179177

180-
# See http://msdn.microsoft.com/en-us/library/ms235384.aspx
181-
# about POSIX functions and their Windows replacements
182-
183-
# Windows replacement functions.
184-
SET(alloca _alloca)
185-
SET(finite _finite)
186-
SET(popen _popen)
187-
SET(pclose _pclose)
188-
SET(strcasecmp _stricmp)
189-
SET(strncasecmp _strnicmp)
190-
SET(strtoll _strtoi64)
191-
SET(strtoull _strtoui64)
192-
SET(snprintf _snprintf)
193-
SET(vsnprintf _vsnprintf)
194-
195-
# Windows replacement functions where the POSIX name is deprecated.
196-
SET(access _access)
197-
SET(chdir _chdir)
198-
SET(chmod _chmod)
199-
SET(dup _dup)
200-
SET(fdopen _fdopen)
201-
SET(fileno _fileno)
202-
SET(getcwd _getcwd)
203-
SET(isatty _isatty)
204-
SET(mkdir _mkdir)
205-
SET(putenv _putenv)
206-
SET(read _read)
207-
SET(rmdir _rmdir)
208-
SET(strdup _strdup)
209-
SET(stricmp _stricmp)
210-
SET(tzset _tzset)
211-
SET(umask _umask)
212-
SET(unlink _unlink)
213-
214-
# Windows security enchanced replacement functions.
215-
SET(strtok_r strtok_s)
216-
217178
CHECK_TYPE_SIZE(ssize_t SIZE_OF_SSIZE_T)
218179
IF(NOT HAVE_SIZE_OF_SSIZE_T)
219180
SET(ssize_t SSIZE_T)

config.h.cmake

-31
Original file line numberDiff line numberDiff line change
@@ -317,37 +317,6 @@
317317
#cmakedefine SIGPIPE @SIGPIPE@
318318
#cmakedefine isnan @isnan@
319319

320-
#cmakedefine alloca @alloca@
321-
#cmakedefine finite @finite@
322-
#cmakedefine popen @popen@
323-
#cmakedefine pclose @pclose@
324-
#cmakedefine strcasecmp @strcasecmp@
325-
#cmakedefine strncasecmp @strncasecmp@
326-
#cmakedefine strtoll @strtoll@
327-
#cmakedefine strtoull @strtoull@
328-
#cmakedefine snprintf @snprintf@
329-
#cmakedefine vsnprintf @vsnprintf@
330-
331-
#cmakedefine access @access@
332-
#cmakedefine chdir @chdir@
333-
#cmakedefine chmod @chmod@
334-
#cmakedefine dup @dup@
335-
#cmakedefine fdopen @fdopen@
336-
#cmakedefine fileno @fileno@
337-
#cmakedefine getcwd @getcwd@
338-
#cmakedefine isatty @isatty@
339-
#cmakedefine mkdir @mkdir@
340-
#cmakedefine putenv @putenv@
341-
#cmakedefine read @read@
342-
#cmakedefine rmdir @rmdir@
343-
#cmakedefine strdup @strdup@
344-
#cmakedefine stricmp @stricmp@
345-
#cmakedefine tzset @tzset@
346-
#cmakedefine umask @umask@
347-
#cmakedefine unlink @unlink@
348-
349-
#cmakedefine strtok_r @strtok_r@
350-
351320
#cmakedefine ssize_t @ssize_t@
352321

353322
/*

extra/yassl/src/ssl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,11 @@ unsigned long ERR_get_error()
16961696
};
16971697

16981698
TaoCrypt::ASN1_TIME_extract(time->data, time->type, &t);
1699+
#ifdef _WIN32
1700+
_snprintf(buf, len, "%s %2d %02d:%02d:%02d %d GMT",
1701+
#else
16991702
snprintf(buf, len, "%s %2d %02d:%02d:%02d %d GMT",
1703+
#endif
17001704
month_names[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,
17011705
t.tm_sec, t.tm_year + 1900);
17021706
return buf;

0 commit comments

Comments
 (0)