123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include <stdio.h>
- static int
- png_have_neon(png_structp png_ptr)
- {
- FILE *f = fopen("/proc/cpuinfo", "rb");
- if (f != NULL)
- {
-
- static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
- static const char ch_neon[] = { 78, 69, 79, 78 };
- enum
- {
- StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine
- } state;
- int counter;
- for (state=StartLine, counter=0;;)
- {
- int ch = fgetc(f);
- if (ch == EOF)
- {
-
- fclose(f);
- return 0;
- }
- switch (state)
- {
- case StartLine:
-
- if (ch <= 32)
- break;
- counter=0;
- state = Feature;
-
- case Feature:
-
- if ((ch & ~0x20) == ch_feature[counter])
- {
- if (++counter == (sizeof ch_feature))
- state = Colon;
- break;
- }
-
- state = SkipLine;
-
- case SkipLine:
- skipLine:
-
- if (ch != 10 && ch != 13)
- break;
- state = StartLine;
- break;
- case Colon:
-
- if (ch == 32 || ch == 9)
- break;
- if (ch == 58)
- {
- state = StartTag;
- break;
- }
-
- state = SkipLine;
- goto skipLine;
- case StartTag:
-
- if (ch == 32 || ch == 9)
- break;
- state = Neon;
- counter = 0;
-
- case Neon:
-
- if ((ch & ~0x20) == ch_neon[counter])
- {
- if (++counter == (sizeof ch_neon))
- state = HaveNeon;
- break;
- }
- state = SkipTag;
-
- case SkipTag:
-
- if (ch == 10 || ch == 13)
- state = StartLine;
- else if (ch == 32 || ch == 9)
- state = StartTag;
- break;
- case HaveNeon:
-
- if (ch == 10 || ch == 13 || ch == 32 || ch == 9)
- {
- fclose(f);
- return 1;
- }
- state = SkipTag;
- break;
- default:
- png_error(png_ptr, "png_have_neon: internal error (bug)");
- }
- }
- }
- #ifdef PNG_WARNINGS_SUPPORTED
- else
- png_warning(png_ptr, "/proc/cpuinfo open failed");
- #endif
- return 0;
- }
|