You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by mt...@apache.org on 2010/05/17 16:05:41 UTC
svn commit: r945167 - in /trafficserver/traffic/trunk/iocore/utils:
I_Layout.h Layout.cc
Author: mturk
Date: Mon May 17 14:05:41 2010
New Revision: 945167
URL: http://svn.apache.org/viewvc?rev=945167&view=rev
Log:
Axe C-like API and use static members
Modified:
trafficserver/traffic/trunk/iocore/utils/I_Layout.h
trafficserver/traffic/trunk/iocore/utils/Layout.cc
Modified: trafficserver/traffic/trunk/iocore/utils/I_Layout.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/I_Layout.h?rev=945167&r1=945166&r2=945167&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/I_Layout.h (original)
+++ trafficserver/traffic/trunk/iocore/utils/I_Layout.h Mon May 17 14:05:41 2010
@@ -31,7 +31,6 @@
#ifndef _I_Layout_h
#define _I_Layout_h
-
/**
The Layout is a simple place holder for the distribution layout.
@@ -58,31 +57,49 @@ struct Layout
/**
Return file path relative to Layout->prefix
- Memory is allocated, so use free() when no longer needed
+ Memory is allocated, so use xfree() when no longer needed
*/
char *relative(const char *file);
/**
+ Return file path relative to Layout->prefix
+ Store the path to buf. The buf should be large eough to store
+ PATH_MAX characters
+
+ */
+ void relative(char *buf, size_t bufsz, const char *file);
+
+ /**
Return file path relative to dir
- Memory is allocated, so use free() when no longer needed
+ Memory is allocated, so use xfree() when no longer needed
Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
*/
static char *relative_to(const char *dir, const char *file);
-};
-/**
- Creates a Layout Object with the given prefix. If no
- prefix is given, the prefix defaults to the one specified
- at the compile time.
+ /**
+ Return file path relative to dir
+ Store the path to buf. The buf should be large eough to store
+ PATH_MAX characters
+ Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
- */
-void create_default_layout(const char *prefix = 0);
+ */
+ static void relative_to(char *buf, size_t bufsz, const char *dir, const char *file);
-/**
- Returns the Layout object created by create_default_layout().
- */
-Layout *default_layout();
+ /**
+ Creates a Layout Object with the given prefix. If no
+ prefix is given, the prefix defaults to the one specified
+ at the compile time.
+
+ */
+ static void create(const char *prefix = 0);
+
+ /**
+ Returns the Layout object created by create_default_layout().
+
+ */
+ static Layout *get();
+};
#endif
Modified: trafficserver/traffic/trunk/iocore/utils/Layout.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Layout.cc?rev=945167&r1=945166&r2=945167&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Layout.cc (original)
+++ trafficserver/traffic/trunk/iocore/utils/Layout.cc Mon May 17 14:05:41 2010
@@ -29,7 +29,7 @@
static Layout *layout = NULL;
Layout *
-default_layout()
+Layout::get()
{
if (layout == NULL) {
ink_assert("need to call create_default_layout before accessing" "default_layout()");
@@ -38,9 +38,11 @@ default_layout()
}
void
-create_default_layout(const char *prefix)
+Layout::create(const char *prefix)
{
- layout = NEW(new Layout(prefix));
+ if (layout == NULL) {
+ layout = NEW(new Layout(prefix));
+ }
}
static char *
@@ -72,12 +74,46 @@ Layout::relative(const char *file)
return layout_relative(prefix, file);
}
+void
+Layout::relative(char *buf, size_t bufsz, const char *file)
+{
+ char *path = layout_relative(prefix, file);
+ if (path) {
+ size_t path_len = strlen(path) + 1;
+ if (path_len > bufsz) {
+ ink_error("Provided buffer is too small: %d, required %d\n",
+ bufsz, path_len);
+ }
+ else {
+ strcpy(buf, path);
+ }
+ xfree(path);
+ }
+}
+
char *
Layout::relative_to(const char *dir, const char *file)
{
return layout_relative(dir, file);
}
+void
+Layout::relative_to(char *buf, size_t bufsz, const char *dir, const char *file)
+{
+ char *path = layout_relative(dir, file);
+ if (path) {
+ size_t path_len = strlen(path) + 1;
+ if (path_len > bufsz) {
+ ink_error("Provided buffer is too small: %d, required %d\n",
+ bufsz, path_len);
+ }
+ else {
+ strcpy(buf, path);
+ }
+ xfree(path);
+ }
+}
+
Layout::Layout(const char *_prefix)
{
if (_prefix) {