_cs_funcs.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include "_stdio.h"
  8. /**********************************************************************/
  9. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  10. /**********************************************************************/
  11. ssize_t _cs_read(void *cookie, char *buf, size_t bufsize)
  12. {
  13. return read(*((int *) cookie), buf, bufsize);
  14. }
  15. /**********************************************************************/
  16. ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize)
  17. {
  18. return write(*((int *) cookie), (char *) buf, bufsize);
  19. }
  20. /**********************************************************************/
  21. int _cs_seek(void *cookie, register __offmax_t *pos, int whence)
  22. {
  23. __offmax_t res;
  24. #ifdef __UCLIBC_HAS_LFS__
  25. res = lseek64(*((int *) cookie), *pos, whence);
  26. #else
  27. res = lseek(*((int *) cookie), *pos, whence);
  28. #endif
  29. return (res >= 0) ? ((*pos = res), 0) : ((int) res);
  30. }
  31. /**********************************************************************/
  32. int _cs_close(void *cookie)
  33. {
  34. return close(*((int *) cookie));
  35. }
  36. /**********************************************************************/
  37. #else
  38. /**********************************************************************/
  39. int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence)
  40. {
  41. __offmax_t res;
  42. #ifdef __UCLIBC_HAS_LFS__
  43. res = lseek64(stream->__filedes, *pos, whence);
  44. #else
  45. res = lseek(stream->__filedes, *pos, whence);
  46. #endif
  47. return (res >= 0) ? ((*pos = res), 0) : ((int) res);
  48. }
  49. /**********************************************************************/
  50. #endif
  51. /**********************************************************************/