Browse Source

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.
Iain Patterson 9 years ago
parent
commit
8aa782adfa
4 changed files with 14 additions and 14 deletions
  1. 0 9
      gui.cpp
  2. 10 0
      nssm.cpp
  3. 1 0
      nssm.h
  4. 3 5
      service.cpp

+ 0 - 9
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);

+ 10 - 0
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);

+ 1 - 0
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"

+ 3 - 5
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);