1 2 /* contrib/mips-msa/linux.c 3 * 4 * Copyright (c) 2020 Cosmin Truta 5 * Copyright (c) 2016 Glenn Randers-Pehrson 6 * Written by Mandar Sahastrabuddhe, 2016. 7 * 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 28 static int png_have_msa(png_structp png_ptr)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 51 if (val == 0) { 52 fclose(f); 53 return 1; 54 } 55 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 } 68