From ee5804fa14d128e07f71abedc8f008a92f95c3a7 Mon Sep 17 00:00:00 2001 From: Vadim Barkov Date: Sat, 14 Jan 2017 16:47:10 +0300 Subject: [PATCH] Added PowerPC detection code for linux --- contrib/powerpc-vsx/linux.c | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 contrib/powerpc-vsx/linux.c diff --git a/contrib/powerpc-vsx/linux.c b/contrib/powerpc-vsx/linux.c new file mode 100644 index 000000000..c522f0ddb --- /dev/null +++ b/contrib/powerpc-vsx/linux.c @@ -0,0 +1,57 @@ +/* contrib/powerpc-vsx/linux.c + * + * Copyright (c) 2016 Glenn Randers-Pehrson + * Written by Vadim Barkov, 2017. + * + * This code is released under the libpng license. + * For conditions of distribution and use, see the disclaimer + * and license in png.h + * + * SEE contrib/powerpc-vsx/README before reporting bugs + * + * STATUS: COMPILED + * BUG REPORTS: png-mng-implement@sourceforge.net + * + * png_have_vsx implemented for Linux by reading the widely available + * pseudo-file /proc/cpuinfo. Result is cached so if function will be called + * multiple times only one reading is perfomed. + * + * This code is strict ANSI-C and is probably moderately portable; it does + * however use and it assumes that /proc/cpuinfo is never localized. + */ + +#include +#include +#include +#include "png.h" + +#ifndef MAXLINE +# define MAXLINE 1024 +#endif + +static int +png_have_vsx(png_structp png_ptr) +{ + FILE *f; + + const char *string = "altivec supported"; + char input[MAXLINE]; + char *token = NULL; + + f = fopen("/proc/cpuinfo", "r"); + if (f != NULL) + { + memset(input,0,MAXLINE); + while(fgets(input,MAXLINE,f) != NULL) + { + token = strstr(input,string); + if(token != NULL) + return cachedResult; + } + } +#ifdef PNG_WARNINGS_SUPPORTED + else + png_warning(png_ptr, "/proc/cpuinfo open failed"); +#endif + return cachedResult; +}