| 202 | |
| 203 | |
| 204 | CHAR8* |
| 205 | OsPathPeerFilePath ( |
| 206 | IN CHAR8 *OldPath, |
| 207 | IN CHAR8 *Peer |
| 208 | ) |
| 209 | /*++ |
| 210 | |
| 211 | Routine Description: |
| 212 | |
| 213 | This function replaces the final portion of a path with an alternative |
| 214 | 'peer' filename. For example: |
| 215 | "a/b/../c", "peer" -> "a/b/../peer" |
| 216 | "a/b/", "peer" -> "a/b/peer" |
| 217 | "/a", "peer" -> "/peer" |
| 218 | "a", "peer" -> "peer" |
| 219 | |
| 220 | This function does not check for the existence of the file. |
| 221 | |
| 222 | Arguments: |
| 223 | |
| 224 | OldPath Path name of replace the final segment |
| 225 | Peer The new path name to concatenate to become the peer path |
| 226 | |
| 227 | Returns: |
| 228 | |
| 229 | A CHAR8* string, which must be freed by the caller |
| 230 | |
| 231 | --*/ |
| 232 | { |
| 233 | CHAR8 *Result; |
| 234 | INTN Offset; |
| 235 | |
| 236 | Result = (CHAR8 *) malloc (strlen (OldPath) + strlen (Peer) + 1); |
| 237 | if (Result == NULL) { |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | strcpy (Result, OldPath); |
| 242 | |
| 243 | // |
| 244 | // Search for the last '/' or '\' in the string. If found, replace |
| 245 | // everything following it with Peer |
| 246 | // |
| 247 | for (Offset = strlen (Result); Offset >= 0; Offset--) { |
| 248 | if ((Result[Offset] == '/') || (Result[Offset] == '\\')) { |
| 249 | Result[Offset + 1] = '\0'; |
| 250 | strcat (Result, Peer); |
| 251 | return Result; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // |
| 256 | // Neither a '/' nor a '\' was found. Therefore, we simply return Peer. |
| 257 | // |
| 258 | strcpy (Result, Peer); |
| 259 | return Result; |
| 260 | } |
| 261 |
no test coverage detected