⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_str.lst

📁 stm32+ucos-ii
💻 LST
📖 第 1 页 / 共 5 页
字号:
   \   00000020   7047               BX       LR               ;; return
    295          }
    296          
    297          
    298          /*$PAGE*/
    299          /*
    300          *********************************************************************************************************
    301          *                                             Str_Copy()
    302          *
    303          * Description : Copy source string to destination string buffer.
    304          *
    305          * Argument(s) : pstr_dest   Pointer to destination string buffer to receive source string copy   (see Note #1a).
    306          *
    307          *               pstr_src    Pointer to source      string to copy into destination string buffer (see Note #1b).
    308          *
    309          * Return(s)   : Pointer to destination string, if NO error(s) [see Note #2b1].
    310          *
    311          *               Pointer to NULL,               otherwise      (see Note #2b2A).
    312          *
    313          * Caller(s)   : Application.
    314          *
    315          * Note(s)     : (1) (a) Destination buffer size NOT validated; buffer overruns MUST be prevented by caller.
    316          *
    317          *                       (1) Destination buffer size MUST be large enough to accommodate the entire source
    318          *                           string size including the terminating NULL character.
    319          *
    320          *                   (b) Source buffer NOT modified.
    321          *
    322          *               (2) (a) IEEE Std 1003.1, 2004 Edition, Section 'strcpy() : DESCRIPTION' states that :
    323          *
    324          *                       (1) "The strcpy() function shall copy the string pointed to by 's2' ('pstr_src') 
    325          *                            ... into the array pointed to by 's1' ('pstr_dest')" ...
    326          *                       (2) "(including the terminating null byte)."
    327          *
    328          *                   (b) IEEE Std 1003.1, 2004 Edition, Section 'strcpy() : RETURN VALUE' states that :
    329          *
    330          *                       (1) "The strcpy() function shall return 's1' ('pstr_dest');" ...
    331          *                       (2) "no return value is reserved to indicate an error."
    332          *                           (A) #### This requirement is intentionally NOT implemented in order to return 
    333          *                               NULL for any error(s).
    334          *
    335          *                   (c) IEEE Std 1003.1, 2004 Edition, Section 'strcpy() : DESCRIPTION' states that "if
    336          *                       copying takes place between objects that overlap, the behavior is undefined".
    337          *
    338          *               (3) String copy terminates when :
    339          *
    340          *                   (a) Destination/Source string pointer(s) are passed NULL pointers.
    341          *                       (1) No string copy performed; NULL pointer returned.
    342          *
    343          *                   (b) Destination/Source string pointer(s) point to NULL.
    344          *                       (1) String buffer(s) overlap with NULL address; NULL pointer returned.
    345          *
    346          *                   (c) Source string's terminating NULL character found.
    347          *                       (1) Entire source string copied into destination string buffer (see Note #2a).
    348          *********************************************************************************************************
    349          */
    350          

   \                                 In section .text, align 2, keep-with-next
    351          CPU_CHAR  *Str_Copy (       CPU_CHAR  *pstr_dest,
    352                               const  CPU_CHAR  *pstr_src)
    353          {
   \                     Str_Copy:
   \   00000000   70B5               PUSH     {R4-R6,LR}
   \   00000002   0400               MOVS     R4,R0
   \   00000004   0D00               MOVS     R5,R1
    354              CPU_CHAR  *pstr_rtn;
    355          
    356          
    357              pstr_rtn = Str_Copy_N(pstr_dest,
    358                                    pstr_src,
    359                                    DEF_INT_CPU_U_MAX_VAL);
   \   00000006   5FF0FF32           MOVS     R2,#-1
   \   0000000A   2900               MOVS     R1,R5
   \   0000000C   2000               MOVS     R0,R4
   \   0000000E   ........           BL       Str_Copy_N
   \   00000012   0600               MOVS     R6,R0
    360          
    361              return (pstr_rtn);
   \   00000014   3000               MOVS     R0,R6
   \   00000016   70BD               POP      {R4-R6,PC}       ;; return
    362          }
    363          
    364          
    365          /*$PAGE*/
    366          /*
    367          *********************************************************************************************************
    368          *                                            Str_Copy_N()
    369          *
    370          * Description : Copy source string to destination string buffer, up to a maximum number of characters.
    371          *
    372          * Argument(s) : pstr_dest   Pointer to destination string buffer to receive source string copy   (see Note #1a).
    373          *
    374          *               pstr_src    Pointer to source      string to copy into destination string buffer (see Note #1b).
    375          *
    376          *               len_max     Maximum number of characters  to copy (see Notes #2a2 & #3d).
    377          *
    378          * Return(s)   : Pointer to destination string, if NO error(s) [see Note #2b1].
    379          *
    380          *               Pointer to NULL,               otherwise      (see Note #2b2A).
    381          *
    382          * Caller(s)   : Application.
    383          *
    384          * Note(s)     : (1) (a) Destination buffer size NOT validated; buffer overruns MUST be prevented by caller.
    385          *
    386          *                       (1) Destination buffer size MUST be large enough to accommodate the entire source
    387          *                           string size including the terminating NULL character.
    388          *
    389          *                   (b) Source string buffer NOT modified.
    390          *
    391          *               (2) (a) (1) IEEE Std 1003.1, 2004 Edition, Section 'strncpy() : DESCRIPTION' states that :
    392          *
    393          *                           (A) "The strncpy() function shall copy ... the array pointed to by 's2' 
    394          *                               ('pstr_src') to the array pointed to by 's1' ('pstr_dest')"; ...
    395          *                           (B)  but "not more than 'n' ('len_max') bytes"                   ...
    396          *                           (C)  &   "(bytes that follow a null byte are not copied)".
    397          *
    398          *                       (2) (A) IEEE Std 1003.1, 2004 Edition, Section 'strncpy() : DESCRIPTION' adds that 
    399          *                              "if the array pointed to by 's2' ('pstr_src') is a string that is shorter 
    400          *                               than 'n' ('len_max') bytes, null bytes shall be appended to the copy in 
    401          *                               the array pointed to by 's1' ('pstr_dest'), until 'n' ('len_max') bytes 
    402          *                               in all are written."
    403          *
    404          *                               (1) #### Since Str_Copy() limits the maximum number of characters to copy 
    405          *                                   via Str_Copy_N() by the CPU's maximum number of addressable characters, 
    406          *                                   this requirement is intentionally NOT implemented to avoid appending 
    407          *                                   a potentially large number of unnecessary terminating NULL characters.
    408          *
    409          *                           (B) IEEE Std 1003.1, 2004 Edition, Section 'strncpy() : APPLICATION USAGE' also  
    410          *                               states that "if there is no null byte in the first 'n' ('len_max') bytes of 
    411          *                               the array pointed to by 's2' ('pstr_src'), the result is not null-terminated".
    412          *
    413          *                   (b) IEEE Std 1003.1, 2004 Edition, Section 'strncpy() : RETURN VALUE' states that :
    414          *
    415          *                       (1) "The strncpy() function shall return 's1' ('pstr_dest');" ...
    416          *                       (2) "no return value is reserved to indicate an error."
    417          *                           (A) #### This requirement is intentionally ignored in order to return NULL 
    418          *                               for any error(s).
    419          *
    420          *                   (c) IEEE Std 1003.1, 2004 Edition, Section 'strncpy() : DESCRIPTION' states that "if
    421          *                       copying takes place between objects that overlap, the behavior is undefined".
    422          *
    423          *               (3) String copy terminates when :
    424          *
    425          *                   (a) Destination/Source string pointer(s) are passed NULL pointers.
    426          *                       (1) No string copy performed; NULL pointer returned.
    427          *
    428          *                   (b) Destination/Source string pointer(s) point to NULL.
    429          *                       (1) String buffer(s) overlap with NULL address; NULL pointer returned.
    430          *
    431          *                   (c) Source string's terminating NULL character found.
    432          *                       (1) Entire source string copied into destination string buffer (see Note #2a1A).
    433          *
    434          *                   (d) 'len_max' number of characters copied.
    435          *                       (1) 'len_max' number of characters MAY include the terminating NULL character 
    436          *                           (see Note #2a1C).
    437          *                       (2) Null copies allowed (i.e. zero-length copies).
    438          *                           (A) No string copy performed; destination string returned  (see Note #2b1).
    439          *********************************************************************************************************
    440          */
    441          /*$PAGE*/

   \                                 In section .text, align 2, keep-with-next
    442          CPU_CHAR  *Str_Copy_N (       CPU_CHAR    *pstr_dest,
    443                                 const  CPU_CHAR    *pstr_src,
    444                                        CPU_SIZE_T   len_max)
    445          {
   \                     Str_Copy_N:
   \   00000000   70B4               PUSH     {R4-R6}
   \   00000002   0300               MOVS     R3,R0
    446                     CPU_CHAR    *pstr_copy_dest;
    447              const  CPU_CHAR    *pstr_copy_src;
    448                     CPU_SIZE_T   len_copy;
    449          
    450                                                                          /* Rtn NULL if str ptr(s) NULL (see Note #3a1).         */
    451              if (pstr_dest == (CPU_CHAR *)0) {
   \   00000004   002B               CMP      R3,#+0
   \   00000006   01D1               BNE.N    ??Str_Copy_N_0
    452                  return ((CPU_CHAR *)0);
   \   00000008   0020               MOVS     R0,#+0
   \   0000000A   21E0               B.N      ??Str_Copy_N_1
    453              }
    454              if (pstr_src  == (const CPU_CHAR *)0) {
   \                     ??Str_Copy_N_0:
   \   0000000C   0029               CMP      R1,#+0
   \   0000000E   01D1               BNE.N    ??Str_Copy_N_2
    455                  return ((CPU_CHAR *)0);
   \   00000010   0020               MOVS     R0,#+0
   \   00000012   1DE0               B.N      ??Str_Copy_N_1
    456              }
    457          
    458          
    459              pstr_copy_dest = pstr_dest;
   \                     ??Str_Copy_N_2:
   \   00000014   1C00               MOVS     R4,R3
    460              pstr_copy_src  = pstr_src;
   \   00000016   0D00               MOVS     R5,R1
    461              len_copy       = 0u;
   \   00000018   0020               MOVS     R0,#+0
   \   0000001A   0600               MOVS     R6,R0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -