Changeset a6b36334 in rtems


Ignore:
Timestamp:
Mar 12, 2020, 2:43:17 PM (4 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
c584d4e
Parents:
5662210
git-author:
Sebastian Huber <sebastian.huber@…> (03/12/20 14:43:17)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/16/20 10:54:26)
Message:

score: Add _IO_Base64()

Update #3904.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    r5662210 ra6b36334  
    10121012librtemscpu_a_SOURCES += score/src/wkspaceisunifieddefault.c
    10131013librtemscpu_a_SOURCES += score/src/wkstringduplicate.c
     1014librtemscpu_a_SOURCES += score/src/iobase64.c
    10141015librtemscpu_a_SOURCES += score/src/ioprintf.c
    10151016librtemscpu_a_SOURCES += score/src/iovprintf.c
  • cpukit/include/rtems/score/io.h

    r5662210 ra6b36334  
    2424#endif /* __cplusplus */
    2525
    26 typedef void ( *IO_Put_char )(int c, void *arg);
     26typedef void ( *IO_Put_char )( int c, void *arg );
    2727
    2828int _IO_Printf(
     
    4040);
    4141
     42/**
     43 * @brief Outputs the source buffer in base64 encoding.
     44 *
     45 * After word length of output characters produced by the encoding a word break
     46 * is produced.
     47 *
     48 * @param put_char The put character function.
     49 * @param arg The argument passed to the put character function.
     50 * @param src The pointer to the source buffer begin.
     51 * @param srclen The length of the source buffer in bytes.
     52 * @param wordbreak The word break string.
     53 * @param wordlen The word length in bytes.  If the word length is less than
     54 *   four, then a word length of four will be used.
     55 *
     56 * @return The count of output characters.
     57 */
     58int _IO_Base64(
     59  IO_Put_char  put_char,
     60  void        *arg,
     61  const void  *src,
     62  size_t       len,
     63  const char  *wordbreak,
     64  int          wordlen
     65);
     66
    4267#ifdef __cplusplus
    4368}
  • testsuites/sptests/spprintk/init.c

    r5662210 ra6b36334  
    188188}
    189189
     190static void test_io_base64( test_context *ctx )
     191{
     192  unsigned char buf[] = "abcdefghi";
     193  int n;
     194
     195  clear( ctx );
     196  n = _IO_Base64( put_char, ctx, buf, 9, "\n", 0 );
     197  rtems_test_assert( n == 14 );
     198  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZGVm\nZ2hp" ) == 0 );
     199
     200  clear( ctx );
     201  n = _IO_Base64( put_char, ctx, buf, 8, "\n", 4 );
     202  rtems_test_assert( n == 14 );
     203  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZGVm\nZ2g=" ) == 0 );
     204
     205  clear( ctx );
     206  n = _IO_Base64( put_char, ctx, buf, 7, "\n", 4 );
     207  rtems_test_assert( n == 14 );
     208  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZGVm\nZw==" ) == 0 );
     209
     210  clear( ctx );
     211  n = _IO_Base64( put_char, ctx, buf, 6, "\n", 4 );
     212  rtems_test_assert( n == 9 );
     213  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZGVm" ) == 0 );
     214
     215  clear( ctx );
     216  n = _IO_Base64( put_char, ctx, buf, 5, "\n", 4 );
     217  rtems_test_assert( n == 9 );
     218  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZGU=" ) == 0 );
     219
     220  clear( ctx );
     221  n = _IO_Base64( put_char, ctx, buf, 4, "\n", 4 );
     222  rtems_test_assert( n == 9 );
     223  rtems_test_assert( strcmp( ctx->buf, "YWJj\nZA==" ) == 0 );
     224
     225  clear( ctx );
     226  n = _IO_Base64( put_char, ctx, buf, 3, "\n", 4 );
     227  rtems_test_assert( n == 4 );
     228  rtems_test_assert( strcmp( ctx->buf, "YWJj" ) == 0 );
     229
     230  clear( ctx );
     231  n = _IO_Base64( put_char, ctx, buf, 2, "\n", 4 );
     232  rtems_test_assert( n == 4 );
     233  rtems_test_assert( strcmp( ctx->buf, "YWI=" ) == 0 );
     234
     235  clear( ctx );
     236  n = _IO_Base64( put_char, ctx, buf, 1, "\n", 4 );
     237  rtems_test_assert( n == 4 );
     238  rtems_test_assert( strcmp( ctx->buf, "YQ==" ) == 0 );
     239
     240  clear( ctx );
     241  n = _IO_Base64( put_char, ctx, buf, 0, "\n", 4 );
     242  rtems_test_assert( n == 0 );
     243}
     244
    190245static rtems_task Init(
    191246  rtems_task_argument argument
     
    202257  do_getchark();
    203258  test_io_printf(&test_instance);
     259  test_io_base64(&test_instance);
    204260
    205261  TEST_END();
Note: See TracChangeset for help on using the changeset viewer.