123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include <unistd.h> /* for POSIX 1003.1 */
- #include <errno.h> /* for EINTR */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <elf.h>
- #include <asm/hwcap.h>
- static size_t
- safe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)
- {
- size_t ntotal = 0;
- char *buffer = png_voidcast(char*, buffer_in);
- while (nbytes > 0)
- {
- unsigned int nread;
- int iread;
-
- if (nbytes > INT_MAX)
- nread = INT_MAX;
- else
- nread = (unsigned int)nbytes;
- iread = read(fd, buffer, nread);
- if (iread == -1)
- {
-
- if (errno != EINTR)
- {
- png_warning(png_ptr, "/proc read failed");
- return 0;
- }
- }
- else if (iread < 0)
- {
-
- png_warning(png_ptr, "OS /proc read bug");
- return 0;
- }
- else if (iread > 0)
- {
-
- buffer += iread;
- nbytes -= (unsigned int)iread;
- ntotal += (unsigned int)iread;
- }
- else
- return ntotal;
- }
- return ntotal;
- }
- static int
- png_have_neon(png_structp png_ptr)
- {
- int fd = open("/proc/self/auxv", O_RDONLY);
- Elf32_auxv_t aux;
-
- if (fd == -1)
- {
- png_warning(png_ptr, "/proc/self/auxv open failed");
- return 0;
- }
- while (safe_read(png_ptr, fd, &aux, sizeof aux) == sizeof aux)
- {
- if (aux.a_type == AT_HWCAP && (aux.a_un.a_val & HWCAP_NEON) != 0)
- {
- close(fd);
- return 1;
- }
- }
- close(fd);
- return 0;
- }
|