fx_directory_name_extract.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************************************************** | ||
| 2 | * Copyright (c) 2024 Microsoft Corporation | ||
| 3 | * Copyright (c) 2026-present Eclipse ThreadX contributors | ||
| 4 | * | ||
| 5 | * This program and the accompanying materials are made available under the | ||
| 6 | * terms of the MIT License which is available at | ||
| 7 | * https://opensource.org/licenses/MIT. | ||
| 8 | * | ||
| 9 | * SPDX-License-Identifier: MIT | ||
| 10 | **************************************************************************/ | ||
| 11 | |||
| 12 | |||
| 13 | /**************************************************************************/ | ||
| 14 | /**************************************************************************/ | ||
| 15 | /** */ | ||
| 16 | /** FileX Component */ | ||
| 17 | /** */ | ||
| 18 | /** Directory */ | ||
| 19 | /** */ | ||
| 20 | /**************************************************************************/ | ||
| 21 | /**************************************************************************/ | ||
| 22 | |||
| 23 | #define FX_SOURCE_CODE | ||
| 24 | |||
| 25 | |||
| 26 | /* Include necessary system files. */ | ||
| 27 | |||
| 28 | #include "fx_api.h" | ||
| 29 | #include "fx_system.h" | ||
| 30 | #include "fx_directory.h" | ||
| 31 | #include "fx_utility.h" | ||
| 32 | |||
| 33 | |||
| 34 | /**************************************************************************/ | ||
| 35 | /* */ | ||
| 36 | /* FUNCTION RELEASE */ | ||
| 37 | /* */ | ||
| 38 | /* _fx_directory_name_extract PORTABLE C */ | ||
| 39 | /* 6.1 */ | ||
| 40 | /* AUTHOR */ | ||
| 41 | /* */ | ||
| 42 | /* William E. Lamie, Microsoft Corporation */ | ||
| 43 | /* */ | ||
| 44 | /* DESCRIPTION */ | ||
| 45 | /* */ | ||
| 46 | /* This function extracts the file name from the supplied input */ | ||
| 47 | /* string. If there is nothing left after the extracted name, a NULL */ | ||
| 48 | /* is returned to the caller. Otherwise, if something is left, a */ | ||
| 49 | /* pointer to it is returned. */ | ||
| 50 | /* */ | ||
| 51 | /* INPUT */ | ||
| 52 | /* */ | ||
| 53 | /* source_ptr Source string pointer */ | ||
| 54 | /* dest_ptr Destination string pointer */ | ||
| 55 | /* */ | ||
| 56 | /* OUTPUT */ | ||
| 57 | /* */ | ||
| 58 | /* Pointer to Next Name (if multiple directories) */ | ||
| 59 | /* */ | ||
| 60 | /* CALLS */ | ||
| 61 | /* */ | ||
| 62 | /* None */ | ||
| 63 | /* */ | ||
| 64 | /* CALLED BY */ | ||
| 65 | /* */ | ||
| 66 | /* FileX System Functions */ | ||
| 67 | /* */ | ||
| 68 | /**************************************************************************/ | ||
| 69 | 9188130 | CHAR *_fx_directory_name_extract(CHAR *source_ptr, CHAR *dest_ptr) | |
| 70 | { | ||
| 71 | |||
| 72 | UINT i; | ||
| 73 | |||
| 74 | |||
| 75 | /* Set the destination string to NULL. */ | ||
| 76 | 9188130 | dest_ptr[0] = 0; | |
| 77 | |||
| 78 | /* Is a backslash present? */ | ||
| 79 |
4/4✓ Branch 2 → 3 taken 8678865 times.
✓ Branch 2 → 4 taken 509265 times.
✓ Branch 3 → 4 taken 27653 times.
✓ Branch 3 → 5 taken 8651212 times.
|
9188130 | if ((*source_ptr == '\\') || (*source_ptr == '/')) |
| 80 | { | ||
| 81 | |||
| 82 | /* Advance the string pointer. */ | ||
| 83 | 536918 | source_ptr++; | |
| 84 | } | ||
| 85 | |||
| 86 | /* Loop to remove any leading spaces. */ | ||
| 87 |
2/2✓ Branch 7 → 6 taken 1872 times.
✓ Branch 7 → 8 taken 9188130 times.
|
9190002 | while (*source_ptr == ' ') |
| 88 | { | ||
| 89 | |||
| 90 | /* Position past leading space. */ | ||
| 91 | 1872 | source_ptr++; | |
| 92 | } | ||
| 93 | |||
| 94 | /* Loop to extract the name. */ | ||
| 95 | 9188130 | i = 0; | |
| 96 |
2/2✓ Branch 14 → 9 taken 85309344 times.
✓ Branch 14 → 15 taken 9049325 times.
|
94358669 | while (*source_ptr) |
| 97 | { | ||
| 98 | |||
| 99 | /* If another backslash is present, break the loop. */ | ||
| 100 |
4/4✓ Branch 9 → 10 taken 85180433 times.
✓ Branch 9 → 15 taken 128911 times.
✓ Branch 10 → 11 taken 85170548 times.
✓ Branch 10 → 15 taken 9885 times.
|
85309344 | if ((*source_ptr == '\\') || (*source_ptr == '/')) |
| 101 | { | ||
| 102 | break; | ||
| 103 | } | ||
| 104 | |||
| 105 | /* Long name can be at most 255 characters, but are further limited by the | ||
| 106 | FX_MAX_LONG_NAME_LEN define. */ | ||
| 107 |
2/2✓ Branch 11 → 12 taken 9 times.
✓ Branch 11 → 13 taken 85170539 times.
|
85170548 | if (i == FX_MAX_LONG_NAME_LEN - 1) |
| 108 | { | ||
| 109 | 9 | break; | |
| 110 | } | ||
| 111 | |||
| 112 | /* Store the character. */ | ||
| 113 | 85170539 | dest_ptr[i] = *source_ptr++; | |
| 114 | |||
| 115 | /* Increment the character counter. */ | ||
| 116 | 85170539 | i++; | |
| 117 | } | ||
| 118 | |||
| 119 | /* NULL-terminate the string. */ | ||
| 120 | 9188130 | dest_ptr[i] = 0; | |
| 121 | |||
| 122 | /* Determine if we can backup to the previous character. */ | ||
| 123 |
2/2✓ Branch 15 → 16 taken 9188121 times.
✓ Branch 15 → 17 taken 9 times.
|
9188130 | if (i) |
| 124 | { | ||
| 125 | |||
| 126 | /* Yes, we can move backwards. */ | ||
| 127 | 9188121 | i--; | |
| 128 | } | ||
| 129 | |||
| 130 | /* Get rid of trailing blanks in the destination string. */ | ||
| 131 |
2/2✓ Branch 19 → 18 taken 459 times.
✓ Branch 19 → 20 taken 9188130 times.
|
9188589 | while (dest_ptr[i] == ' ') |
| 132 | { | ||
| 133 | |||
| 134 | /* Set this entry to NULL. */ | ||
| 135 | 459 | dest_ptr[i] = 0; | |
| 136 | |||
| 137 | /* Backup to the next character. Since leading spaces have been removed, | ||
| 138 | we know that the index is always greater than 1. */ | ||
| 139 | 459 | i--; | |
| 140 | } | ||
| 141 | |||
| 142 | /* Determine if the source string is now at the end. */ | ||
| 143 |
2/2✓ Branch 20 → 21 taken 9049325 times.
✓ Branch 20 → 22 taken 138805 times.
|
9188130 | if (*source_ptr == 0) |
| 144 | { | ||
| 145 | |||
| 146 | /* Yes, return a NULL pointer. */ | ||
| 147 | 9049325 | source_ptr = FX_NULL; | |
| 148 | } | ||
| 149 | |||
| 150 | /* Return the last pointer position in the source. */ | ||
| 151 | 9188130 | return(source_ptr); | |
| 152 | } | ||
| 153 | |||
| 154 |