@@ -60,18 +60,106 @@ int my_access(const char *path, int amode)
60
60
List of file names that causes problem on windows
61
61
62
62
NOTE that one can also not have file names of type CON.TXT
63
+
64
+ NOTE: it is important to keep "CLOCK$" on the first place,
65
+ we skip it in check_if_legal_tablename.
63
66
*/
64
-
65
67
static const char * reserved_names []=
66
68
{
67
- "CON" , "PRN" , "AUX" , "NUL" , "COM1" , "COM2" , "COM3" , "COM4" , "COM5" , "COM6" ,
68
- "COM7" , "COM8" , "COM9" , "LPT1" , "LPT2" , "LPT3" , "LPT4" , "LPT5" , "LPT6" ,
69
- "LPT7" , "LPT8" , "LPT9" , "CLOCK$" ,
69
+ "CLOCK$" ,
70
+ "CON" , "PRN" , "AUX" , "NUL" ,
71
+ "COM1" , "COM2" , "COM3" , "COM4" , "COM5" , "COM6" , "COM7" , "COM8" , "COM9" ,
72
+ "LPT1" , "LPT2" , "LPT3" , "LPT4" , "LPT5" , "LPT6" , "LPT7" , "LPT8" , "LPT9" ,
70
73
NullS
71
74
};
72
75
73
76
#define MAX_RESERVED_NAME_LENGTH 6
74
77
78
+
79
+ /*
80
+ Looks up a null-terminated string in a list,
81
+ case insensitively.
82
+
83
+ SYNOPSIS
84
+ str_list_find()
85
+ list list of items
86
+ str item to find
87
+
88
+ RETURN
89
+ 0 ok
90
+ 1 reserved file name
91
+ */
92
+ static int str_list_find (const char * * list , const char * str )
93
+ {
94
+ const char * * name ;
95
+ for (name = list ; * name ; name ++ )
96
+ {
97
+ if (!my_strcasecmp (& my_charset_latin1 , * name , str ))
98
+ return 1 ;
99
+ }
100
+ return 0 ;
101
+ }
102
+
103
+
104
+ /*
105
+ A map for faster reserved_names lookup,
106
+ helps to avoid loops in many cases.
107
+ 1 - can be the first letter
108
+ 2 - can be the second letter
109
+ 4 - can be the third letter
110
+ */
111
+ static char reserved_map [256 ]=
112
+ {
113
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* ................ */
114
+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,0 , /* ................ */
127
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* ................ */
128
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 /* ................ */
129
+ };
130
+
131
+
132
+ /*
133
+ Check if a table name may cause problems
134
+
135
+ SYNOPSIS
136
+ check_if_legal_tablename
137
+ name Table name (without any extensions)
138
+
139
+ DESCRIPTION
140
+ We don't check 'CLOCK$' because dollar sign is encoded as @0024,
141
+ making table file name 'CLOCK@0024', which is safe.
142
+ This is why we start lookup from the second element
143
+ (i.e. &reserver_name[1])
144
+
145
+ RETURN
146
+ 0 ok
147
+ 1 reserved file name
148
+ */
149
+
150
+ int check_if_legal_tablename (const char * name )
151
+ {
152
+ DBUG_ENTER ("check_if_legal_tablename" );
153
+ DBUG_RETURN ((reserved_map [(uchar ) name [0 ]] & 1 ) &&
154
+ (reserved_map [(uchar ) name [1 ]] & 2 ) &&
155
+ (reserved_map [(uchar ) name [2 ]] & 4 ) &&
156
+ str_list_find (& reserved_names [1 ], name ));
157
+ }
158
+
159
+
160
+ #if defined(MSDOS ) || defined(__WIN__ ) || defined(__EMX__ )
161
+
162
+
75
163
/*
76
164
Check if a path will access a reserverd file name that may cause problems
77
165
0 commit comments