The main function of gnunet-base32.
41{
42 int decode = 0;
45 "decode",
47 "run decoder modus, otherwise runs as encoder"),
48 &decode),
52 };
54 char *in;
55 unsigned int in_size;
56 ssize_t iret;
57 char *out;
58 size_t out_size;
59
62 &argc, &argv))
63 return 2;
66 argc,
67 argv);
69 return 1;
71 return 0;
72 in_size = 0;
73 in = NULL;
74 iret = 1;
75 while (iret > 0)
76 {
77
78 char buf[4092];
79
80 iret = read (0,
81 buf,
82 sizeof (buf));
83 if (iret < 0)
84 {
86 return 2;
87 }
88 if (iret > 0)
89 {
90 if (iret + in_size < in_size)
91 {
94 return 1;
95 }
97 in_size,
98 in_size + iret);
99 memcpy (&in[in_size - iret],
100 buf,
101 iret);
102 }
103 }
104 if (decode)
105 {
106
107
108 out_size = in_size * 5 / 8;
112 in_size,
113 out,
114 out_size)) &&
115 (out_size > 0) )
116 {
117 out_size--;
120 in_size,
121 out,
122 out_size))
123 {
126 return 3;
127 }
128 }
129 }
130 else
131 {
133 in_size);
134 out_size = strlen (out);
135 }
136 {
137 size_t pos = 0;
138
139 while (pos < out_size)
140 {
141 iret = write (1,
142 &out[pos],
143 out_size - pos);
144 if (iret <= 0)
145 return 4;
146 pos += iret;
147 }
148 }
151 return 0;
152}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static int ret
Final status code.
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition of a command line option.