\r
/** Parse a path producing the target device, device instance, and file path.\r
\r
+ It is the caller's responsibility to free() FullPath and MapPath when they\r
+ are no longer needed.\r
+\r
@param[in] path\r
@param[out] FullPath\r
@param[out] DevNode\r
@param[out] Which\r
+ @param[out] MapPath OPTIONAL. If not NULL, it points to the place to save a pointer\r
+ to the extracted map name. If the path didn't have a map name,\r
+ then *MapPath is set to NULL.\r
\r
@retval RETURN_SUCCESS The path was parsed successfully.\r
@retval RETURN_NOT_FOUND The path does not map to a valid device.\r
IN const char *path,\r
OUT wchar_t **FullPath,\r
OUT DeviceNode **DevNode,\r
- OUT int *Which\r
+ OUT int *Which,\r
+ OUT wchar_t **MapPath\r
)\r
{\r
int MapLen;\r
// Get the Map Name, including the trailing ':'. */\r
MPath = calloc(MapLen+2, sizeof(wchar_t));\r
if(MPath != NULL) {\r
- wmemcpy(MPath, WPath, MapLen+2);\r
+ wmemcpy(MPath, WPath, MapLen+1);\r
}\r
else {\r
errno = ENOMEM;\r
if(!RETURN_ERROR(Status)) {\r
*FullPath = WPath;\r
*Which = Instance;\r
+ if(MapPath != NULL) {\r
+ *MapPath = MPath;\r
+ }\r
+ else if(MPath != NULL) {\r
+ free(MPath); /* Caller doesn't want it so let MPath go free */\r
+ }\r
\r
/* At this point, WPath is an absolute path,\r
MPath is either NULL or points to the Map Name,\r
if(Node != NULL) {\r
Status = RETURN_SUCCESS;\r
}\r
+ else {\r
+ Status = RETURN_NOT_FOUND;\r
+ }\r
}\r
else {\r
/* This is a mapped path. */\r
*DevNode = Node;\r
}\r
}\r
- if(MPath != NULL) {\r
- free(MPath); // We don't need this any more.\r
- }\r
return Status;\r
}\r
+\r
+/**\r
+ Parses a normalized wide character path and returns a pointer to the entry\r
+ following the last \. If a \ is not found in the path the return value will\r
+ be the same as the input value. All error conditions return NULL.\r
+\r
+ The behavior when passing in a path that has not been normalized is undefined.\r
+\r
+ @param Path - A pointer to a wide character string containing a path to a\r
+ directory or a file.\r
+\r
+ @return Pointer to the file name or terminal directory. NULL if an error is\r
+ detected.\r
+**/\r
+wchar_t *\r
+EFIAPI\r
+GetFileNameFromPath (\r
+ const wchar_t *Path\r
+ )\r
+{\r
+ wchar_t *Tail;\r
+\r
+ if (Path == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ Tail = wcsrchr(Path, L'\\');\r
+ if(Tail == NULL) {\r
+ Tail = (wchar_t *) Path;\r
+ } else {\r
+ // Move to the next character after the '\\' to get the file name.\r
+ Tail++;\r
+ }\r
+\r
+ return Tail;\r
+}\r