Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
022c9f0d
Commit
022c9f0d
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Handling non-ascii chars in the binary
parent
e3806197
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
build/main.c
+58
-10
58 additions, 10 deletions
build/main.c
with
58 additions
and
10 deletions
build/main.c
+
58
−
10
View file @
022c9f0d
...
...
@@ -18,11 +18,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#
if defined(_WIN32)
#def
ine _CRT_SECURE_NO_WARNINGS // Disable deprecation warn
ing
i
n
VS2005
#
else
#define _
XOPEN_SOURCE 600 // For PATH_MAX on linux
#
endif
#
undef UNICODE // Use ANSI WinAPI functions
#
un
def
_UNICODE // Use multibyte encod
ing
o
n
Windows
#
define _MBCS // Use multibyte encoding on Windows
#define _
CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005
#
define _XOPEN_SOURCE 600 // For PATH_MAX on linux
#include
<sys/stat.h>
#include
<stdio.h>
...
...
@@ -39,7 +39,7 @@
#ifdef _WIN32
#include
<windows.h>
#include
<direct.h>
// For
getcwd
#include
<direct.h>
// For
chdir()
#include
<winsvc.h>
#include
<shlobj.h>
...
...
@@ -57,7 +57,10 @@
#define sleep(x) Sleep((x) * 1000)
#define abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size))
#define SIGCHLD 0
typedef
struct
_stat
file_stat_t
;
#define stat(x, y) my_stat((x), (y))
#else
typedef
struct
stat
file_stat_t
;
#include
<sys/wait.h>
#include
<unistd.h>
#define DIRSEP '/'
...
...
@@ -275,7 +278,7 @@ static void init_server_name(void) {
}
static
int
is_path_absolute
(
const
char
*
path
)
{
#ifdef
_
WIN32
#ifdef WIN32
return
path
!=
NULL
&&
((
path
[
0
]
==
'\\'
&&
path
[
1
]
==
'\\'
)
||
// UNC path, e.g. \\server\dir
(
isalpha
(
path
[
0
])
&&
path
[
1
]
==
':'
&&
path
[
2
]
==
'\\'
));
// E.g. X:\dir
...
...
@@ -294,9 +297,17 @@ static char *get_option(char **options, const char *option_name) {
return
NULL
;
}
#ifdef WIN32 // _WIN32 can be undefined if -DNO_GUI is used
static
int
my_stat
(
const
char
*
path
,
file_stat_t
*
st
)
{
wchar_t
buf
[
PATH_MAX
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
path
,
-
1
,
buf
,
sizeof
(
buf
)
/
sizeof
(
buf
[
0
]));
return
_wstat
(
buf
,
st
);
}
#endif
static
void
verify_existence
(
char
**
options
,
const
char
*
option_name
,
int
must_be_dir
)
{
struct
stat
st
;
file_
stat
_t
st
;
const
char
*
path
=
get_option
(
options
,
option_name
);
if
(
path
!=
NULL
&&
(
stat
(
path
,
&
st
)
!=
0
||
...
...
@@ -307,6 +318,31 @@ static void verify_existence(char **options, const char *option_name,
}
}
#ifdef WIN32
static
int
my_argc
;
static
char
**
my_argv
;
static
void
to_utf8
(
wchar_t
*
src
,
char
*
dst
,
size_t
dst_len
)
{
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
wcslen
(
src
)
+
1
,
dst
,
dst_len
,
0
,
0
);
}
static
void
init_utf8_argc_argv
(
void
)
{
wchar_t
**
wargv
=
CommandLineToArgvW
(
GetCommandLineW
(),
&
my_argc
);
if
(
wargv
!=
NULL
)
{
char
buf
[
1024
*
8
];
int
i
;
// TODO(lsm): free that at some point.
my_argv
=
calloc
(
my_argc
+
1
,
sizeof
(
my_argv
[
0
]));
for
(
i
=
0
;
i
<
my_argc
;
i
++
)
{
to_utf8
(
wargv
[
i
],
buf
,
sizeof
(
buf
));
my_argv
[
i
]
=
strdup
(
buf
);
printf
(
"init_utf8_argc_argv: [%s] [%ls]
\n
"
,
my_argv
[
i
],
wargv
[
i
]);
}
LocalFree
(
wargv
);
}
}
#endif
static
void
set_absolute_path
(
char
*
options
[],
const
char
*
option_name
,
const
char
*
path_to_mongoose_exe
)
{
char
path
[
PATH_MAX
],
abs
[
PATH_MAX
],
*
option_value
;
...
...
@@ -322,7 +358,13 @@ static void set_absolute_path(char *options[], const char *option_name,
// be the relative directory for everything.
// Extract mongoose executable directory into path.
if
((
p
=
strrchr
(
path_to_mongoose_exe
,
DIRSEP
))
==
NULL
)
{
#ifdef WIN32
wchar_t
buf
[
PATH_MAX
];
GetCurrentDirectoryW
(
sizeof
(
buf
)
/
sizeof
(
buf
[
0
]),
buf
);
to_utf8
(
buf
,
path
,
sizeof
(
path
));
#else
getcwd
(
path
,
sizeof
(
path
));
#endif
}
else
{
snprintf
(
path
,
sizeof
(
path
),
"%.*s"
,
(
int
)
(
p
-
path_to_mongoose_exe
),
path_to_mongoose_exe
);
...
...
@@ -611,7 +653,7 @@ static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
fclose
(
fp
);
TerminateThread
(
hThread
,
0
);
mg_destroy_server
(
&
server
);
start_mongoose
(
_
_argc
,
_
_argv
);
start_mongoose
(
my
_argc
,
my
_argv
);
mg_start_thread
(
serving_thread_func
,
server
);
}
EnableWindow
(
GetDlgItem
(
hDlg
,
ID_SAVE
),
TRUE
);
...
...
@@ -867,7 +909,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
StartServiceCtrlDispatcher
(
service_table
);
exit
(
EXIT_SUCCESS
);
}
else
{
start_mongoose
(
_
_argc
,
_
_argv
);
start_mongoose
(
my
_argc
,
my
_argv
);
hThread
=
mg_start_thread
(
serving_thread_func
,
server
);
s_uTaskbarRestart
=
RegisterWindowMessage
(
TEXT
(
"TaskbarCreated"
));
}
...
...
@@ -944,6 +986,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
HWND
hWnd
;
MSG
msg
;
init_utf8_argc_argv
();
init_server_name
();
memset
(
&
cls
,
0
,
sizeof
(
cls
));
cls
.
lpfnWndProc
=
(
WNDPROC
)
WindowProc
;
...
...
@@ -1060,6 +1103,11 @@ int main(int argc, char *argv[]) {
}
#else
int
main
(
int
argc
,
char
*
argv
[])
{
#ifdef WIN32
init_utf8_argc_argv
();
argc
=
my_argc
;
argv
=
my_argv
;
#endif
init_server_name
();
start_mongoose
(
argc
,
argv
);
printf
(
"%s serving [%s] on port %s
\n
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment