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