Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: xz/debug/hex2bin.c

Issue 2869016: Add an unpatched version of xz, XZ Utils, to /trunk/deps/third_party (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « xz/debug/full_flush.c ('k') | xz/debug/known_sizes.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file hex2bin.c
4 /// \brief Converts hexadecimal input strings to binary
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #include "sysdefs.h"
14 #include <stdio.h>
15 #include <ctype.h>
16
17
18 static int
19 getbin(int x)
20 {
21 if (x >= '0' && x <= '9')
22 return x - '0';
23
24 if (x >= 'A' && x <= 'F')
25 return x - 'A' + 10;
26
27 return x - 'a' + 10;
28 }
29
30
31 int
32 main(void)
33 {
34 while (true) {
35 int byte = getchar();
36 if (byte == EOF)
37 return 0;
38 if (!isxdigit(byte))
39 continue;
40
41 const int digit = getchar();
42 if (digit == EOF || !isxdigit(digit)) {
43 fprintf(stderr, "Invalid input\n");
44 return 1;
45 }
46
47 byte = (getbin(byte) << 4) | getbin(digit);
48 if (putchar(byte) == EOF) {
49 perror(NULL);
50 return 1;
51 }
52 }
53 }
OLDNEW
« no previous file with comments | « xz/debug/full_flush.c ('k') | xz/debug/known_sizes.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698