Print this page
OS-2444 richmond hardware maps need to support ivy bridge

@@ -21,12 +21,13 @@
  */
 /*
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
-
-#pragma ident   "%Z%%M% %I%     %E% SMI"
+/*
+ * Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ */
 
 #include <strings.h>
 #include <ctype.h>
 #include <fm/libtopo.h>
 #include <fm/topo_mod.h>

@@ -54,10 +55,61 @@
         if (s != NULL)
                 topo_hdl_free(thp, s, strlen(s) + 1);
 }
 
 char *
+topo_hdl_strsplit(topo_hdl_t *hdl, const char *input, const char *sep,
+    char **lastp)
+{
+        size_t seplen = strlen(sep);
+        const char *scanstart;
+        char *token;
+        char *ret;
+
+        if (input != NULL) {
+                /*
+                 * Start scanning at beginning of input:
+                 */
+                scanstart = input;
+        } else {
+                /*
+                 * If we have already finished scanning, return NULL.
+                 */
+                if (*lastp == NULL)
+                        return (NULL);
+
+                /*
+                 * Otherwise, start scanning where we left off:
+                 */
+                scanstart = *lastp;
+        }
+
+        token = strstr(scanstart, sep);
+        if (token != NULL) {
+                /*
+                 * We still have a separator, so advance the next-start
+                 * pointer past it:
+                 */
+                *lastp = token + seplen;
+                /*
+                 * Copy out this element:
+                 */
+                ret = topo_hdl_alloc(hdl, token - scanstart + 1);
+                (void) strncpy(ret, scanstart, token - scanstart);
+                ret[token - scanstart] = '\0';
+        } else {
+                /*
+                 * We have no separator, so this is the last element:
+                 */
+                *lastp = NULL;
+                ret = topo_hdl_strdup(hdl, scanstart);
+        }
+
+        return (ret);
+}
+
+char *
 topo_mod_strdup(topo_mod_t *mod, const char *s)
 {
         return (topo_hdl_strdup(mod->tm_hdl, s));
 }
 

@@ -65,10 +117,17 @@
 topo_mod_strfree(topo_mod_t *mod, char *s)
 {
         topo_hdl_strfree(mod->tm_hdl, s);
 }
 
+char *
+topo_mod_strsplit(topo_mod_t *mod, const char *input, const char *sep,
+    char **lastp)
+{
+        return (topo_hdl_strsplit(mod->tm_hdl, input, sep, lastp));
+}
+
 const char *
 topo_strbasename(const char *s)
 {
         const char *p = strrchr(s, '/');