From: Iain Patterson Date: Fri, 22 Nov 2013 12:25:33 +0000 (+0000) Subject: Compiler food. X-Git-Tag: v2.19~5 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=8aa782adfab4d63e4115fead833c864fe43d4cbc;p=nssm.git Compiler food. Make strip_basename() non-static so it can be used elsewhere, particularly in cases where int and size_t are different sizes, ie on 32-bit builds. --- diff --git a/gui.cpp b/gui.cpp index 4bcb144..e28c044 100644 --- a/gui.cpp +++ b/gui.cpp @@ -4,15 +4,6 @@ static enum { NSSM_TAB_APPLICATION, NSSM_TAB_SHUTDOWN, NSSM_TAB_EXIT, NSSM_TAB_I static HWND tablist[NSSM_NUM_TABS]; static int selected_tab; -static void strip_basename(char *buffer) { - size_t len = strlen(buffer); - size_t i; - for (i = len; i && buffer[i] != '\\' && buffer[i] != '/'; i--); - /* X:\ is OK. */ - if (i && buffer[i-1] == ':') i++; - buffer[i] = '\0'; -} - int nssm_gui(int resource, char *name) { /* Create window */ HWND dlg = CreateDialog(0, MAKEINTRESOURCE(resource), 0, install_dlg); diff --git a/nssm.cpp b/nssm.cpp index 0ce8664..a60c378 100644 --- a/nssm.cpp +++ b/nssm.cpp @@ -13,6 +13,16 @@ int str_equiv(const char *a, const char *b) { } } +/* Remove basename of a path. */ +void strip_basename(char *buffer) { + size_t len = strlen(buffer); + size_t i; + for (i = len; i && buffer[i] != '\\' && buffer[i] != '/'; i--); + /* X:\ is OK. */ + if (i && buffer[i-1] == ':') i++; + buffer[i] = '\0'; +} + /* How to use me correctly */ int usage(int ret) { print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE); diff --git a/nssm.h b/nssm.h index 566a66f..1ee4ae2 100644 --- a/nssm.h +++ b/nssm.h @@ -16,6 +16,7 @@ #include "gui.h" int str_equiv(const char *, const char *); +void strip_basename(char *); #define NSSM "nssm" #define NSSM_VERSION "2.18" diff --git a/service.cpp b/service.cpp index ea5a460..077c1e8 100644 --- a/service.cpp +++ b/service.cpp @@ -69,7 +69,7 @@ int pre_install_service(int argc, char **argv) { /* Arguments are optional */ size_t flagslen = 0; size_t s = 0; - size_t i; + int i; for (i = 2; i < argc; i++) flagslen += strlen(argv[i]) + 1; if (! flagslen) flagslen = 1; @@ -87,10 +87,8 @@ int pre_install_service(int argc, char **argv) { } /* Work out directory name */ - size_t len = strlen(service->exe); - for (i = len; i && service->exe[i] != '\\' && service->exe[i] != '/'; i--); - memmove(service->dir, service->exe, i); - service->dir[i] = '\0'; + memmove(service->dir, service->exe, sizeof(service->dir)); + strip_basename(service->dir); int ret = install_service(service); cleanup_nssm_service(service);