summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 480d14d)
raw | patch | inline | side by side (parent: 480d14d)
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/trunk/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/trunk/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 8913e4add8b117833aab02121d5d74b8d23ca0be..35ed960ee23386b31baf4baf2ddd812f0c57e885 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
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 989a2b4e5d695a7db5068dfdd2ae02d303191697..d1343b989e0d2aa4a4200c9a6dcc31c04285d803 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 72a9905cc3d83095e473c886eff3581f3b937b26..fa50929a5fd4aae6ee2a8e92fede979d1a1c5f2f 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 bae4a95f18b8ab2f39be94c6b865fc4dee178b77..dd5947e67c77fc329c291f5520d6fa3337a03d04 100644 (file)
--- a/win32/rrdlib.vcproj
+++ b/win32/rrdlib.vcproj
PrecompiledHeaderThrough="precompiled.h"\r
WarningLevel="3"\r
DebugInformationFormat="3"\r
+ CompileAs="2"\r
DisableSpecificWarnings="4996"\r
/>\r
<Tool\r
PrecompiledHeaderThrough="precompiled.h"\r
WarningLevel="3"\r
DebugInformationFormat="3"\r
+ CompileAs="2"\r
DisableSpecificWarnings="4996"\r
/>\r
<Tool\r
<File\r
RelativePath="..\src\hash_32.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
+ </File>\r
+ <File\r
+ RelativePath="..\src\plbasename.c"\r
+ >\r
</File>\r
<File\r
RelativePath="..\src\pngsize.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_create.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_diff.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_dump.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_error.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_fetch.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_first.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_format.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_getopt.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_getopt1.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_gfx.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_graph.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_graph_helper.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_hw.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_hw_math.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_hw_update.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_info.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_last.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_lastupdate.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_nan_inf.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_open.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_parsetime.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_resize.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_restore.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_rpncalc.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_thread_safe_nt.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_tune.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_update.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_version.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
<File\r
RelativePath="..\src\rrd_xport.c"\r
>\r
- <FileConfiguration\r
- Name="Debug|Win32"\r
- >\r
- <Tool\r
- Name="VCCLCompilerTool"\r
- CompileAs="2"\r
- />\r
- </FileConfiguration>\r
</File>\r
</Filter>\r
<Filter\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