summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 42c3cd8)
raw | patch | inline | side by side (parent: 42c3cd8)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 19 Dec 2008 14:26:47 +0000 (14:26 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 19 Dec 2008 14:26:47 +0000 (14:26 +0000) |
* added portable plbasename since basename is not available on stock win32
* rrd_update was using %d to show a timestamp ... %lli is better
since it also will show 64bit time_t correctly.
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3/program@1716 a5681a0c-68f1-0310-ab6d-d61299d08faa
* rrd_update was using %d to show a timestamp ... %lli is better
since it also will show 64bit time_t correctly.
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3/program@1716 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/Makefile.am | patch | blob | history | |
src/plbasename.c | [new file with mode: 0644] | patch | blob |
src/plbasename.h | [new file with mode: 0644] | patch | blob |
src/rrd_graph.c | patch | blob | history | |
src/rrd_update.c | patch | blob | history | |
win32/rrdlib.vcproj | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index f91ae6cdc01b3f907f77d315e59abb662470adb6..74d382f3962e7fd8555f982f471f711423d25a29 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
# strftime is here because we do not usually need it. unices have propper
# iso date support
EXTRA_DIST= librrd.pc.in strftime.c strftime.h rrd_getopt.c rrd_getopt1.c rrd_getopt.h \
- win32comp.c rrd_thread_safe_nt.c get_ver.awk librrd.sym.in.in
+ win32comp.c rrd_thread_safe_nt.c get_ver.awk librrd.sym.in.in plbasename.c plbasename.h
librrd.sym: librrd.sym.in
grep -v LIBC_HAS_GETOPT_LONG librrd.sym.in >$@
diff --git a/src/plbasename.c b/src/plbasename.c
--- /dev/null
+++ b/src/plbasename.c
@@ -0,0 +1,211 @@
+#ifdef WIN32
+/*
+ *
+ * Cross-platform basename/dirname
+ *
+ * Copyright 2005 Syd Logan, All Rights Reserved
+ *
+ * This code is distributed without warranty. You are free to use this
+ * code for any purpose, however, if this code is republished or
+ * redistributed in its original form, as hardcopy or electronically,
+ * then you must include this copyright notice along with the code.
+ *
+ */
+
+// minor changes 2008 by Stefan Ludewig stefan.ludewig@exitgames.com for WIN32 version RRDtool
+
+#include <memory.h>
+#include <stdlib.h>
+#include "plbasename.h"
+#include <string.h>
+#if defined(TEST)
+#include <stdio.h>
+#endif
+
+#if defined(__cplusplus)
+
+extern "C" {
+
+#endif
+
+const char *
+PL_basename(const char *name)
+{
+ const char *base;
+ char *p;
+ static char *tmp = NULL;
+ int len;
+
+ if (tmp) {
+ free(tmp);
+ tmp = NULL;
+ }
+
+ if (!name || !strcmp(name, ""))
+ return "";
+
+ if (!strcmp(name, "/"))
+ return "/";
+
+ len = strlen(name);
+ if (name[len - 1] == '/') {
+ // ditch the trailing '/'
+ p = tmp = (char*)malloc(len);
+ strncpy(p, name, len - 1);
+ } else {
+ p = (char *) name;
+ }
+
+ for (base = p; *p; p++)
+ if (*p == '/')
+ base = p + 1;
+
+ return base;
+}
+
+const char *
+PL_dirname(const char *name)
+{
+ static char *ret = NULL;
+ int len;
+ int size = 0;
+ const char *p;
+
+ if (ret) {
+ free(ret);
+ ret = NULL;
+ }
+
+ if (!name || !strcmp(name, "") || !strstr(name, "/"))
+ return(".");
+
+ if (!strcmp(name, "/"))
+ return(name);
+
+ // find the last slash in the string
+
+ len = strlen(name);
+ p = &name[len - 1];
+
+ if (*p == '/') p--; // skip the trailing /
+
+ while (p != name && *p != '/') p--;
+
+ size = p - name;
+ if (size) {
+ ret = (char*)malloc(size + 1);
+ memcpy(ret, name, size);
+ ret[size] = '\0';
+ } else if (*p == '/')
+ return "/";
+ else
+ return "";
+
+ return (const char *) ret;
+}
+
+#if defined(__cplusplus)
+
+}
+
+#endif
+
+#if defined(TEST)
+
+int
+main(int argc, char *argv[])
+{
+/* run the following tests:
+
+ path dirname basename
+ "/usr/lib" "/usr" "lib"
+ "/usr/" "/" "usr"
+ "usr" "." "usr"
+ "/" "/" "/"
+ "." "." "."
+ ".." "." ".."
+ NULL "." ""
+ "" "." ""
+ "./.." "." ".."
+
+ These results can be verified by running the unix commands
+ basename(1) and dirname(1). One tweek to the test strategy
+ used here would be, on darwin and linux, to shell out to
+ get the expected results vs hardcoding.
+*/
+ if (!strcmp(PL_basename("/usr/lib"), "lib"))
+ printf("PL_basename /usr/lib passed\n");
+ else
+ printf("PL_basename /usr/lib failed expected lib\n");
+ if (!strcmp(PL_dirname("/usr/lib"), "/usr"))
+ printf("PL_dirname /usr/lib passed\n");
+ else
+ printf("PL_dirname /usr/lib failed expected /usr\n");
+ if (!strcmp(PL_basename("/usr/"), "usr"))
+ printf("PL_basename /usr/ passed\n");
+ else
+ printf("PL_basename /usr/ failed expected usr\n");
+ if (!strcmp(PL_dirname("/usr/"), "/"))
+ printf("PL_dirname /usr/ passed\n");
+ else
+ printf("PL_dirname /usr/ failed expected /\n");
+ if (!strcmp(PL_basename("usr"), "usr"))
+ printf("PL_basename usr passed\n");
+ else
+ printf("PL_basename usr failed expected usr\n");
+ if (!strcmp(PL_dirname("usr"), "."))
+ printf("PL_dirname usr passed\n");
+ else
+ printf("PL_dirname usr failed expected .\n");
+ if (!strcmp(PL_basename("/"), "/"))
+ printf("PL_basename / passed\n");
+ else
+ printf("PL_basename / failed expected /\n");
+ if (!strcmp(PL_dirname("/"), "/"))
+ printf("PL_dirname / passed\n");
+ else
+ printf("PL_dirname / failed expected /\n");
+ if (!strcmp(PL_basename("."), "."))
+ printf("PL_basename . passed\n");
+ else
+ printf("PL_basename . failed\n");
+ if (!strcmp(PL_dirname("."), "."))
+ printf("PL_dirname . passed\n");
+ else
+ printf("PL_dirname . failed expected .\n");
+ if (!strcmp(PL_basename(".."), ".."))
+ printf("PL_basename .. passed\n");
+ else
+ printf("PL_basename .. failed expected ..\n");
+ if (!strcmp(PL_dirname(".."), "."))
+ printf("PL_dirname .. passed\n");
+ else
+ printf("PL_dirname .. failed expected .\n");
+ if (!strcmp(PL_basename(NULL), ""))
+ printf("PL_basename NULL passed\n");
+ else
+ printf("PL_basename NULL failed expected \"\"\n");
+ if (!strcmp(PL_dirname(NULL), "."))
+ printf("PL_dirname NULL passed\n");
+ else
+ printf("PL_dirname NULL failed expected .\n");
+ if (!strcmp(PL_basename(""), ""))
+ printf("PL_basename \"\" passed\n");
+ else
+ printf("PL_basename \"\" failed expected \"\"\n");
+ if (!strcmp(PL_dirname(""), "."))
+ printf("PL_dirname \"\" passed\n");
+ else
+ printf("PL_dirname \"\" failed expected .\n");
+
+ if (!strcmp(PL_basename("./.."), ".."))
+ printf("PL_basename ./.. passed\n");
+ else
+ printf("PL_basename ./.. failed expected ..\n");
+ if (!strcmp(PL_dirname("./.."), "."))
+ printf("PL_dirname ./.. passed\n");
+ else
+ printf("PL_dirname ./.. failed expected .\n");
+}
+#endif
+#endif // WIN32
diff --git a/src/plbasename.h b/src/plbasename.h
--- /dev/null
+++ b/src/plbasename.h
@@ -0,0 +1,45 @@
+#ifdef WIN32
+/*
+ *
+ * Cross-platform basename/dirname
+ *
+ * Copyright 2005 Syd Logan, All Rights Reserved
+ *
+ * This code is distributed without warranty. You are free to use this
+ * code for any purpose, however, if this code is republished or
+ * redistributed in its original form, as hardcopy or electronically,
+ * then you must include this copyright notice along with the code.
+ *
+ */
+
+// minor changes 2008 by Stefan Ludewig stefan.ludewig@exitgames.com for WIN32 version RRDtool
+
+#if !defined(__PL_BASENAME_H__)
+#define __PL_BASENAME_H__
+
+/*
+ path dirname basename
+ "/usr/lib" "/usr" "lib"
+ "/usr/" "/" "usr"
+ "usr" "." "usr"
+ "/" "/" "/"
+ "." "." "."
+ ".." "." ".."
+*/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+const char *PL_basename(const char *name);
+const char *PL_dirname(const char *name);
+
+#define basename(name) ((char*)PL_basename(name))
+#define dirname(name) ((char*)PL_dirname(name))
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
+#endif // WIN32
diff --git a/src/rrd_graph.c b/src/rrd_graph.c
index 03230776dc8cd82046d3fbb4b0f4bc53a3d6646d..c4e8bf0df748913dc2711313168089711e23635c 100644 (file)
--- a/src/rrd_graph.c
+++ b/src/rrd_graph.c
#ifdef WIN32
#include "strftime.h"
+#include "plbasename.h"
#endif
+
#include "rrd_tool.h"
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
diff --git a/src/rrd_update.c b/src/rrd_update.c
index aec00124a891978e7e9fb301e04f3e1835b7faea..fbd25360205f20e76e19d7f11a579be1d9c7342f 100644 (file)
--- a/src/rrd_update.c
+++ b/src/rrd_update.c
/* append info to the return hash */
*pcdp_summary = rrd_info_push(*pcdp_summary,
sprintf_alloc
- ("[%d]RRA[%s][%lu]DS[%s]", rra_time,
+ ("[%lli]RRA[%s][%lu]DS[%s]", rra_time,
rrd->rra_def[rra_idx].cf_nam,
rrd->rra_def[rra_idx].pdp_cnt,
rrd->ds_def[ds_idx].ds_nam),
diff --git a/win32/rrdlib.vcproj b/win32/rrdlib.vcproj
index 00a8b01265dc539c7431b404f3d39c3aa3c7caa6..dd5947e67c77fc329c291f5520d6fa3337a03d04 100644 (file)
--- a/win32/rrdlib.vcproj
+++ b/win32/rrdlib.vcproj
RelativePath="..\src\hash_32.c"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\src\plbasename.c"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\src\pngsize.c"\r
>\r
RelativePath="..\src\fnv.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\src\plbasename.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\src\rrd.h"\r
>\r