• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

tests/base64.c

Go to the documentation of this file.
00001 /*
00002  * This file is part of Libav.
00003  *
00004  * Libav is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * Libav is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with Libav; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00019 /*
00020  * Based on libavutil/base64.c
00021  */
00022 
00023 #include <stdio.h>
00024 
00025 int main(void)
00026 {
00027     static const char b64[] =
00028         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
00029     unsigned i_bits = 0;
00030     int i_shift     = 0;
00031     int out_len     = 0;
00032     int in;
00033 
00034 #define putb64()                                        \
00035     do {                                                \
00036         putchar(b64[(i_bits << 6 >> i_shift) & 0x3f]);  \
00037         out_len++;                                      \
00038         i_shift -= 6;                                   \
00039     } while (0)
00040 
00041     while ((in = getchar()) != EOF) {
00042         i_bits   = (i_bits << 8) + in;
00043         i_shift += 8;
00044         while (i_shift > 6)
00045             putb64();
00046     }
00047     while (i_shift > 0)
00048         putb64();
00049     while (out_len++ & 3)
00050         putchar('=');
00051     putchar('\n');
00052 
00053     return 0;
00054 }
Generated on Thu Jul 11 2013 15:38:24 for Libav by doxygen 1.7.1