linux.c 1.3 KB

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