Changeset 5811:28f6eed531d7 in roaraudio for libroar/env.c
- Timestamp:
- 01/05/13 01:29:03 (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/env.c
r5754 r5811 121 121 } 122 122 123 static char * __get_path(const char ** inpath) { 124 char buf_path[64]; 125 size_t i; 126 127 (*inpath)++; 128 129 for (i = 0; i < sizeof(buf_path); i++) { 130 if ( (*inpath)[i] == '/' || (*inpath)[i] == 0 ) { 131 break; 132 } else { 133 buf_path[i] = (*inpath)[i]; 134 } 135 } 136 137 if ( i == sizeof(buf_path) ) { 138 roar_err_set(ROAR_ERROR_NOSPC); 139 return NULL; 140 } 141 142 buf_path[i] = 0; 143 144 (*inpath) += i; 145 146 return roar_libroar_get_path(buf_path, 0, NULL, NULL); 147 } 148 123 149 int roar_env_render_path_r(char * out, size_t len, const char * inpath) { 124 150 size_t inlen; … … 126 152 size_t homelen = 0; 127 153 const char * home; 128 enum { UNKNOWN, COPY, HOME } mode = UNKNOWN; 154 const char * prefix = NULL; 155 char * prefix_path = NULL; 156 enum { UNKNOWN, COPY, HOME, PREFIX } mode = UNKNOWN; 129 157 130 158 if ( len == 0 && inpath == NULL ) … … 159 187 needlen = inlen + homelen - 1; 160 188 mode = HOME; 161 } 162 163 if ( len < (needlen + 1) ) 164 return -1; 189 prefix = home; 190 inpath++; 191 } else if ( inpath[0] == '$' ) { 192 prefix_path = __get_path(&inpath); 193 if ( prefix_path == NULL ) 194 return -1; 195 needlen = roar_mm_strlen(inpath) + roar_mm_strlen(prefix_path) + 1; 196 mode = PREFIX; 197 prefix = prefix_path; 198 } 199 200 if ( len < (needlen + 1) ) { 201 if ( prefix_path != NULL ) 202 roar_mm_free(prefix_path); 203 roar_err_set(ROAR_ERROR_NOSPC); 204 return -1; 205 } 165 206 166 207 switch (mode) { … … 170 211 break; 171 212 case HOME: 172 roar_mm_strlcpy(out, home, len); 173 roar_mm_strlcat(out, inpath+1, len); // strip only ~, so we have the / if home is not /-terminated. 213 case PREFIX: 214 roar_mm_strlcpy(out, prefix, len); 215 roar_mm_strlcat(out, inpath, len); // strip only ~, so we have the / if home is not /-terminated. 174 216 break; 175 217 default: 218 if ( prefix_path != NULL ) 219 roar_mm_free(prefix_path); 220 roar_err_set(ROAR_ERROR_NOTSUP); 176 221 return -1; 177 222 break; 178 223 } 179 224 225 if ( prefix_path != NULL ) 226 roar_mm_free(prefix_path); 180 227 return 0; 181 228 }
Note: See TracChangeset
for help on using the changeset viewer.