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


   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"

  28 
  29 #include <strings.h>
  30 #include <ctype.h>
  31 #include <fm/libtopo.h>
  32 #include <fm/topo_mod.h>
  33 #include <topo_alloc.h>
  34 
  35 char *
  36 topo_hdl_strdup(topo_hdl_t *thp, const char *s)
  37 {
  38         char *p;
  39 
  40         if (s != NULL)
  41                 p = topo_hdl_alloc(thp, strlen(s) + 1);
  42         else
  43                 p = NULL;
  44 
  45         if (p != NULL)
  46                 (void) strcpy(p, s);
  47 
  48         return (p);
  49 }
  50 
  51 void
  52 topo_hdl_strfree(topo_hdl_t *thp, char *s)
  53 {
  54         if (s != NULL)
  55                 topo_hdl_free(thp, s, strlen(s) + 1);
  56 }
  57 
  58 char *



















































  59 topo_mod_strdup(topo_mod_t *mod, const char *s)
  60 {
  61         return (topo_hdl_strdup(mod->tm_hdl, s));
  62 }
  63 
  64 void
  65 topo_mod_strfree(topo_mod_t *mod, char *s)
  66 {
  67         topo_hdl_strfree(mod->tm_hdl, s);
  68 }
  69 







  70 const char *
  71 topo_strbasename(const char *s)
  72 {
  73         const char *p = strrchr(s, '/');
  74 
  75         if (p == NULL)
  76                 return (s);
  77 
  78         return (++p);
  79 }
  80 
  81 char *
  82 topo_strdirname(char *s)
  83 {
  84         static char slash[] = "/";
  85         static char dot[] = ".";
  86         char *p;
  87 
  88         if (s == NULL || *s == '\0')
  89                 return (dot);




   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  28  */
  29 
  30 #include <strings.h>
  31 #include <ctype.h>
  32 #include <fm/libtopo.h>
  33 #include <fm/topo_mod.h>
  34 #include <topo_alloc.h>
  35 
  36 char *
  37 topo_hdl_strdup(topo_hdl_t *thp, const char *s)
  38 {
  39         char *p;
  40 
  41         if (s != NULL)
  42                 p = topo_hdl_alloc(thp, strlen(s) + 1);
  43         else
  44                 p = NULL;
  45 
  46         if (p != NULL)
  47                 (void) strcpy(p, s);
  48 
  49         return (p);
  50 }
  51 
  52 void
  53 topo_hdl_strfree(topo_hdl_t *thp, char *s)
  54 {
  55         if (s != NULL)
  56                 topo_hdl_free(thp, s, strlen(s) + 1);
  57 }
  58 
  59 char *
  60 topo_hdl_strsplit(topo_hdl_t *hdl, const char *input, const char *sep,
  61     char **lastp)
  62 {
  63         size_t seplen = strlen(sep);
  64         const char *scanstart;
  65         char *token;
  66         char *ret;
  67 
  68         if (input != NULL) {
  69                 /*
  70                  * Start scanning at beginning of input:
  71                  */
  72                 scanstart = input;
  73         } else {
  74                 /*
  75                  * If we have already finished scanning, return NULL.
  76                  */
  77                 if (*lastp == NULL)
  78                         return (NULL);
  79 
  80                 /*
  81                  * Otherwise, start scanning where we left off:
  82                  */
  83                 scanstart = *lastp;
  84         }
  85 
  86         token = strstr(scanstart, sep);
  87         if (token != NULL) {
  88                 /*
  89                  * We still have a separator, so advance the next-start
  90                  * pointer past it:
  91                  */
  92                 *lastp = token + seplen;
  93                 /*
  94                  * Copy out this element:
  95                  */
  96                 ret = topo_hdl_alloc(hdl, token - scanstart + 1);
  97                 (void) strncpy(ret, scanstart, token - scanstart);
  98                 ret[token - scanstart] = '\0';
  99         } else {
 100                 /*
 101                  * We have no separator, so this is the last element:
 102                  */
 103                 *lastp = NULL;
 104                 ret = topo_hdl_strdup(hdl, scanstart);
 105         }
 106 
 107         return (ret);
 108 }
 109 
 110 char *
 111 topo_mod_strdup(topo_mod_t *mod, const char *s)
 112 {
 113         return (topo_hdl_strdup(mod->tm_hdl, s));
 114 }
 115 
 116 void
 117 topo_mod_strfree(topo_mod_t *mod, char *s)
 118 {
 119         topo_hdl_strfree(mod->tm_hdl, s);
 120 }
 121 
 122 char *
 123 topo_mod_strsplit(topo_mod_t *mod, const char *input, const char *sep,
 124     char **lastp)
 125 {
 126         return (topo_hdl_strsplit(mod->tm_hdl, input, sep, lastp));
 127 }
 128 
 129 const char *
 130 topo_strbasename(const char *s)
 131 {
 132         const char *p = strrchr(s, '/');
 133 
 134         if (p == NULL)
 135                 return (s);
 136 
 137         return (++p);
 138 }
 139 
 140 char *
 141 topo_strdirname(char *s)
 142 {
 143         static char slash[] = "/";
 144         static char dot[] = ".";
 145         char *p;
 146 
 147         if (s == NULL || *s == '\0')
 148                 return (dot);