Sfoglia il codice sorgente

* Our own dirname() function, although couldn't we just use strrchr()?

svn: 837
Bryan Drewery 22 anni fa
parent
commit
532c3d4a44
6 ha cambiato i file con 58 aggiunte e 15 eliminazioni
  1. 1 1
      src/chanprog.c
  2. 2 1
      src/compat/Makefile.in
  3. 1 0
      src/compat/compat.h
  4. 44 0
      src/compat/dirname.c
  5. 8 0
      src/compat/dirname.h
  6. 2 13
      src/shell.c

+ 1 - 1
src/chanprog.c

@@ -673,7 +673,7 @@ int shouldjoin(struct chanset_t *chan)
 {
   if (!strncmp(conf.bot->nick, "wtest", 5) && !strcmp(chan->dname, "#wraith"))
     return 1;
-  else if (!strncmp(conf.bot->nick, "wtest", 5))
+  else if (!strncmp(conf.bot->nick, "wtest", 4)) /* use 5 for all */
     return 0; 
 #ifdef G_BACKUP
   struct flag_record fr = { FR_CHAN | FR_ANYWH | FR_GLOBAL, 0, 0, 0, 0 };

+ 2 - 1
src/compat/Makefile.in

@@ -14,7 +14,8 @@ STRIP = @STRIP@
 CFLAGS = @CFLAGS@ -I../.. -I$(top_srcdir) -I$(top_srcdir)/src @DEFS@ $(CFLGS)
 CPPFLAGS = @CPPFLAGS@
 
-OBJS = inet_aton.o \
+OBJS = dirname.o \
+	inet_aton.o \
 	inet_ntop.o \
 	snprintf.o \
 	memset.o \

+ 1 - 0
src/compat/compat.h

@@ -7,6 +7,7 @@
 #ifndef _EGG_COMPAT_COMPAT_H
 #define _EGG_COMPAT_COMPAT_H
 
+#include "dirname.h"
 #include "inet_aton.h"
 #include "inet_ntop.h"
 #include "snprintf.h"

+ 44 - 0
src/compat/dirname.c

@@ -0,0 +1,44 @@
+#include "common.h"
+#include <errno.h>
+#include <string.h>
+#include <sys/param.h>
+
+char *
+dirname(const char *path)
+{
+        static char bname[MAXPATHLEN];
+        register const char *endp;
+
+        /* Empty or NULL string gets treated as "." */
+        if (path == NULL || *path == '\0') {
+                strncpyz(bname, ".", sizeof bname);
+                return(bname);
+        }
+
+        /* Strip trailing slashes */
+        endp = path + strlen(path) - 1;
+        while (endp > path && *endp == '/')
+                endp--;
+
+        /* Find the start of the dir */
+        while (endp > path && *endp != '/')
+                endp--;
+
+        /* Either the dir is "/" or there are no slashes */
+        if (endp == path) {
+                strncpyz(bname, *endp == '/' ? "/" : ".", sizeof bname);
+                return(bname);
+        } else {
+                do {
+                        endp--;
+                } while (endp > path && *endp == '/');
+        }
+
+        if (endp - path + 2 > sizeof(bname)) {
+                errno = ENAMETOOLONG;
+                return(NULL);
+        }
+        strncpyz(bname, path, endp - path + 2);
+        return(bname);
+}
+

+ 8 - 0
src/compat/dirname.h

@@ -0,0 +1,8 @@
+#ifndef _DIRNAME_H
+#define _DIRNAME_H
+
+#undef dirname
+
+char *dirname(const char *);
+#endif /* !_DIRNAME_H */
+

+ 2 - 13
src/shell.c

@@ -42,9 +42,6 @@
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#ifndef CYGWIN_HACKS
-#  include <libgen.h>
-#endif /* !CYGWIN_HACKS */
 #include <ctype.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -812,18 +809,10 @@ char *confdir()
 
   if (!confdir || (confdir && !confdir[0])) {
 #ifdef LEAF
-    {
-      egg_snprintf(confdir, sizeof confdir, "%s/.ssh", homedir());
-    }
+    egg_snprintf(confdir, sizeof confdir, "%s/.ssh", homedir());
 #endif /* LEAF */
 #ifdef HUB
-    {
-      char *buf = NULL;
-
-      buf = strdup(binname);
-      egg_snprintf(confdir, sizeof confdir, "%s", dirname(buf));
-      free(buf);
-    }
+    egg_snprintf(confdir, sizeof confdir, "%s", dirname(binname));
 #endif /* HUB */
   }
   return confdir;