blob: 3bac6111b79d30f228d11494cdca454d8475fa63 [file] [log] [blame]
xNombre232e9ca2020-07-03 22:10:22 +02001
Alex Naidis7a055fd2016-10-01 12:23:07 +02002/* contrib/mips-msa/linux.c
3 *
xNombre232e9ca2020-07-03 22:10:22 +02004 * Copyright (c) 2020 Cosmin Truta
Alex Naidis7a055fd2016-10-01 12:23:07 +02005 * Copyright (c) 2016 Glenn Randers-Pehrson
6 * Written by Mandar Sahastrabuddhe, 2016.
Alex Naidis7a055fd2016-10-01 12:23:07 +02007 *
8 * This code is released under the libpng license.
9 * For conditions of distribution and use, see the disclaimer
10 * and license in png.h
11 *
12 * SEE contrib/mips-msa/README before reporting bugs
13 *
14 * STATUS: SUPPORTED
15 * BUG REPORTS: png-mng-implement@sourceforge.net
16 *
17 * png_have_msa implemented for Linux by reading the widely available
18 * pseudo-file /proc/cpuinfo.
19 *
20 * This code is strict ANSI-C and is probably moderately portable; it does
21 * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
22 */
23
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27
28static int
29png_have_msa(png_structp png_ptr)
30{
31 FILE *f = fopen("/proc/cpuinfo", "rb");
32
33 char *string = "msa";
34 char word[10];
35
36 if (f != NULL)
37 {
38 while(!feof(f))
39 {
40 int ch = fgetc(f);
41 static int i = 0;
42
43 while(!(ch <= 32))
44 {
45 word[i++] = ch;
46 ch = fgetc(f);
47 }
48
49 int val = strcmp(string, word);
50
xNombre232e9ca2020-07-03 22:10:22 +020051 if (val == 0) {
52 fclose(f);
Alex Naidis7a055fd2016-10-01 12:23:07 +020053 return 1;
xNombre232e9ca2020-07-03 22:10:22 +020054 }
Alex Naidis7a055fd2016-10-01 12:23:07 +020055
56 i = 0;
57 memset(word, 0, 10);
58 }
59
60 fclose(f);
61 }
62#ifdef PNG_WARNINGS_SUPPORTED
63 else
64 png_warning(png_ptr, "/proc/cpuinfo open failed");
65#endif
66 return 0;
67}