media/libpng/arm/linux.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* contrib/arm-neon/linux.c
michael@0 2 *
michael@0 3 * Copyright (c) 2014 Glenn Randers-Pehrson
michael@0 4 * Written by John Bowler, 2014.
michael@0 5 * Last changed in libpng 1.6.10 [March 6, 2014]
michael@0 6 *
michael@0 7 * This code is released under the libpng license.
michael@0 8 * For conditions of distribution and use, see the disclaimer
michael@0 9 * and license in png.h
michael@0 10 *
michael@0 11 * SEE contrib/arm-neon/README before reporting bugs
michael@0 12 *
michael@0 13 * STATUS: SUPPORTED
michael@0 14 * BUG REPORTS: png-mng-implement@sourceforge.net
michael@0 15 *
michael@0 16 * png_have_neon implemented for Linux by reading the widely available
michael@0 17 * pseudo-file /proc/cpuinfo.
michael@0 18 *
michael@0 19 * This code is strict ANSI-C and is probably moderately portable, it does
michael@0 20 * however use <stdio.h> and assumes that /proc/cpuinfo is never localized.
michael@0 21 */
michael@0 22 #include <stdio.h>
michael@0 23
michael@0 24 static int
michael@0 25 png_have_neon(png_structp png_ptr)
michael@0 26 {
michael@0 27 FILE *f = fopen("/proc/cpuinfo", "rb");
michael@0 28
michael@0 29 if (f != NULL)
michael@0 30 {
michael@0 31 /* This is a simple state machine which reads the input byte-by-byte until
michael@0 32 * it gets a match on the 'neon' feature or reaches the end of the stream.
michael@0 33 */
michael@0 34 static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
michael@0 35 static const char ch_neon[] = { 78, 69, 79, 78 };
michael@0 36
michael@0 37 enum
michael@0 38 {
michael@0 39 StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine
michael@0 40 } state;
michael@0 41 int counter;
michael@0 42
michael@0 43 for (state=StartLine, counter=0;;)
michael@0 44 {
michael@0 45 int ch = fgetc(f);
michael@0 46
michael@0 47 if (ch == EOF)
michael@0 48 {
michael@0 49 /* EOF means error or end-of-file, return false; neon at EOF is
michael@0 50 * assumed to be a mistake.
michael@0 51 */
michael@0 52 fclose(f);
michael@0 53 return 0;
michael@0 54 }
michael@0 55
michael@0 56 switch (state)
michael@0 57 {
michael@0 58 case StartLine:
michael@0 59 /* Match spaces at the start of line */
michael@0 60 if (ch <= 32) /* skip control characters and space */
michael@0 61 break;
michael@0 62
michael@0 63 counter=0;
michael@0 64 state = Feature;
michael@0 65 /* FALL THROUGH */
michael@0 66
michael@0 67 case Feature:
michael@0 68 /* Match 'FEATURE', ASCII case insensitive. */
michael@0 69 if ((ch & ~0x20) == ch_feature[counter])
michael@0 70 {
michael@0 71 if (++counter == (sizeof ch_feature))
michael@0 72 state = Colon;
michael@0 73 break;
michael@0 74 }
michael@0 75
michael@0 76 /* did not match 'feature' */
michael@0 77 state = SkipLine;
michael@0 78 /* FALL THROUGH */
michael@0 79
michael@0 80 case SkipLine:
michael@0 81 skipLine:
michael@0 82 /* Skip everything until we see linefeed or carriage return */
michael@0 83 if (ch != 10 && ch != 13)
michael@0 84 break;
michael@0 85
michael@0 86 state = StartLine;
michael@0 87 break;
michael@0 88
michael@0 89 case Colon:
michael@0 90 /* Match any number of space or tab followed by ':' */
michael@0 91 if (ch == 32 || ch == 9)
michael@0 92 break;
michael@0 93
michael@0 94 if (ch == 58) /* i.e. ':' */
michael@0 95 {
michael@0 96 state = StartTag;
michael@0 97 break;
michael@0 98 }
michael@0 99
michael@0 100 /* Either a bad line format or a 'feature' prefix followed by
michael@0 101 * other characters.
michael@0 102 */
michael@0 103 state = SkipLine;
michael@0 104 goto skipLine;
michael@0 105
michael@0 106 case StartTag:
michael@0 107 /* Skip space characters before a tag */
michael@0 108 if (ch == 32 || ch == 9)
michael@0 109 break;
michael@0 110
michael@0 111 state = Neon;
michael@0 112 counter = 0;
michael@0 113 /* FALL THROUGH */
michael@0 114
michael@0 115 case Neon:
michael@0 116 /* Look for 'neon' tag */
michael@0 117 if ((ch & ~0x20) == ch_neon[counter])
michael@0 118 {
michael@0 119 if (++counter == (sizeof ch_neon))
michael@0 120 state = HaveNeon;
michael@0 121 break;
michael@0 122 }
michael@0 123
michael@0 124 state = SkipTag;
michael@0 125 /* FALL THROUGH */
michael@0 126
michael@0 127 case SkipTag:
michael@0 128 /* Skip non-space characters */
michael@0 129 if (ch == 10 || ch == 13)
michael@0 130 state = StartLine;
michael@0 131
michael@0 132 else if (ch == 32 || ch == 9)
michael@0 133 state = StartTag;
michael@0 134 break;
michael@0 135
michael@0 136 case HaveNeon:
michael@0 137 /* Have seen a 'neon' prefix, but there must be a space or new
michael@0 138 * line character to terminate it.
michael@0 139 */
michael@0 140 if (ch == 10 || ch == 13 || ch == 32 || ch == 9)
michael@0 141 {
michael@0 142 fclose(f);
michael@0 143 return 1;
michael@0 144 }
michael@0 145
michael@0 146 state = SkipTag;
michael@0 147 break;
michael@0 148
michael@0 149 default:
michael@0 150 png_error(png_ptr, "png_have_neon: internal error (bug)");
michael@0 151 }
michael@0 152 }
michael@0 153 }
michael@0 154
michael@0 155 else
michael@0 156 png_warning(png_ptr, "/proc/cpuinfo open failed");
michael@0 157
michael@0 158 return 0;
michael@0 159 }

mercurial