1*a67afe4dSAndroid Build Coastguard Worker /* contrib/powerpc-vsx/linux.c 2*a67afe4dSAndroid Build Coastguard Worker * 3*a67afe4dSAndroid Build Coastguard Worker * Copyright (c) 2017 Glenn Randers-Pehrson 4*a67afe4dSAndroid Build Coastguard Worker * Written by Vadim Barkov, 2017. 5*a67afe4dSAndroid Build Coastguard Worker * 6*a67afe4dSAndroid Build Coastguard Worker * This code is released under the libpng license. 7*a67afe4dSAndroid Build Coastguard Worker * For conditions of distribution and use, see the disclaimer 8*a67afe4dSAndroid Build Coastguard Worker * and license in png.h 9*a67afe4dSAndroid Build Coastguard Worker * 10*a67afe4dSAndroid Build Coastguard Worker * STATUS: TESTED 11*a67afe4dSAndroid Build Coastguard Worker * BUG REPORTS: [email protected] 12*a67afe4dSAndroid Build Coastguard Worker * 13*a67afe4dSAndroid Build Coastguard Worker * png_have_vsx implemented for Linux by reading the widely available 14*a67afe4dSAndroid Build Coastguard Worker * pseudo-file /proc/cpuinfo. 15*a67afe4dSAndroid Build Coastguard Worker * 16*a67afe4dSAndroid Build Coastguard Worker * This code is strict ANSI-C and is probably moderately portable; it does 17*a67afe4dSAndroid Build Coastguard Worker * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized. 18*a67afe4dSAndroid Build Coastguard Worker */ 19*a67afe4dSAndroid Build Coastguard Worker 20*a67afe4dSAndroid Build Coastguard Worker #include <stdio.h> 21*a67afe4dSAndroid Build Coastguard Worker #include <string.h> 22*a67afe4dSAndroid Build Coastguard Worker #include <stdlib.h> 23*a67afe4dSAndroid Build Coastguard Worker #include "png.h" 24*a67afe4dSAndroid Build Coastguard Worker 25*a67afe4dSAndroid Build Coastguard Worker #ifndef MAXLINE 26*a67afe4dSAndroid Build Coastguard Worker # define MAXLINE 1024 27*a67afe4dSAndroid Build Coastguard Worker #endif 28*a67afe4dSAndroid Build Coastguard Worker 29*a67afe4dSAndroid Build Coastguard Worker static int png_have_vsx(png_structp png_ptr)30*a67afe4dSAndroid Build Coastguard Workerpng_have_vsx(png_structp png_ptr) 31*a67afe4dSAndroid Build Coastguard Worker { 32*a67afe4dSAndroid Build Coastguard Worker FILE *f; 33*a67afe4dSAndroid Build Coastguard Worker 34*a67afe4dSAndroid Build Coastguard Worker const char *string = "altivec supported"; 35*a67afe4dSAndroid Build Coastguard Worker char input[MAXLINE]; 36*a67afe4dSAndroid Build Coastguard Worker char *token = NULL; 37*a67afe4dSAndroid Build Coastguard Worker 38*a67afe4dSAndroid Build Coastguard Worker PNG_UNUSED(png_ptr) 39*a67afe4dSAndroid Build Coastguard Worker 40*a67afe4dSAndroid Build Coastguard Worker f = fopen("/proc/cpuinfo", "r"); 41*a67afe4dSAndroid Build Coastguard Worker if (f != NULL) 42*a67afe4dSAndroid Build Coastguard Worker { 43*a67afe4dSAndroid Build Coastguard Worker memset(input,0,MAXLINE); 44*a67afe4dSAndroid Build Coastguard Worker while(fgets(input,MAXLINE,f) != NULL) 45*a67afe4dSAndroid Build Coastguard Worker { 46*a67afe4dSAndroid Build Coastguard Worker token = strstr(input,string); 47*a67afe4dSAndroid Build Coastguard Worker if(token != NULL) 48*a67afe4dSAndroid Build Coastguard Worker return 1; 49*a67afe4dSAndroid Build Coastguard Worker } 50*a67afe4dSAndroid Build Coastguard Worker } 51*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_WARNINGS_SUPPORTED 52*a67afe4dSAndroid Build Coastguard Worker else 53*a67afe4dSAndroid Build Coastguard Worker png_warning(png_ptr, "/proc/cpuinfo open failed"); 54*a67afe4dSAndroid Build Coastguard Worker #endif 55*a67afe4dSAndroid Build Coastguard Worker return 0; 56*a67afe4dSAndroid Build Coastguard Worker } 57