Skip to content

Commit 01e7366

Browse files
committed
mysqlname: A small utility to filesystem escape a database name
1 parent d4718f7 commit 01e7366

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

mysqlname.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef MYSQL_NAME_C
2+
#define MYSQL_NAME_C
3+
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <mysql.h>
7+
#include <my_global.h>
8+
#include <my_sys.h>
9+
#include <m_ctype.h>
10+
11+
typedef unsigned int uint;
12+
uint tablename_to_filename(const char *from, char *to, uint to_length);
13+
extern CHARSET_INFO *system_charset_info;
14+
15+
int
16+
main(int argc, char* argv[]) {
17+
char out[1024];
18+
memset(out, '\0', sizeof(out));
19+
20+
/* Must be initialized early for comparison of service name */
21+
system_charset_info= &my_charset_utf8_general_ci;
22+
23+
if (argc != 2) {
24+
fprintf(stderr, "Please specify a database name\n");
25+
return 1;
26+
}
27+
28+
tablename_to_filename(argv[1], out, sizeof(out));
29+
printf("%s\n", out);
30+
31+
return 0;
32+
}
33+
34+
#endif

0 commit comments

Comments
 (0)