ql_newlib.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* system calls for the Visium processor.
  2. Copyright (c) 2015 Rolls-Royce Controls and Data Services Limited.
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Rolls-Royce Controls and Data Services Limited nor
  12. the names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. THE POSSIBILITY OF SUCH DAMAGE. */
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <sys/time.h>
  28. #include <fcntl.h>
  29. #include <unistd.h>
  30. #include <stdarg.h>
  31. #include <string.h>
  32. #include "ql_fs.h"
  33. #include "ql_log.h"
  34. #include "ql_api_osi.h"
  35. #define QL_NEWLIB_LOG_LEVEL QL_LOG_LEVEL_INFO
  36. #define QL_NEWLIB_LOG(msg, ...) QL_LOG(QL_NEWLIB_LOG_LEVEL, "ql_NEWLIB", msg, ##__VA_ARGS__)
  37. #define QL_NEWLIB_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_NEWLIB", msg, ##__VA_ARGS__)
  38. extern QFILE ql_open(const char *file_name, int mode);
  39. int close (int fildes)
  40. {
  41. return ql_fclose(fildes);
  42. }
  43. int fstat (int fildes, struct stat *st)
  44. {
  45. return ql_fstat(fildes,st);
  46. }
  47. int gettimeofday (struct timeval *__p, void *__tz)
  48. {
  49. ql_timeval_t *timeval = (ql_timeval_t *)__p;
  50. ql_gettimeofday(timeval);
  51. return 0;
  52. }
  53. /*如果参数fildes所代表的文件描述词为一终端机则返回1,否则返回0*/
  54. int isatty (int fildes)
  55. {
  56. return 0;
  57. }
  58. off_t lseek (int fildes, off_t offset, int whence)
  59. {
  60. return ql_fseek(fildes, offset, whence);
  61. }
  62. int open (const char *path, int oflag, ...)
  63. {
  64. int fd = ql_open(path, oflag);
  65. QL_NEWLIB_LOG("open %s %d %d",path,oflag,fd);
  66. return fd;
  67. }
  68. int read (int fildes, void *buf, size_t nbyte)
  69. {
  70. size_t size = ql_fread(buf, nbyte, 1, fildes);
  71. QL_NEWLIB_LOG("read %d %d %s %d",fildes,nbyte,buf,size);
  72. return size;
  73. }
  74. int rename (const char *old, const char *new)
  75. {
  76. return ql_rename(old,new);
  77. }
  78. int stat (const char *path, struct stat *st)
  79. {
  80. return ql_stat(path, st);
  81. }
  82. int unlink (const char *path)
  83. {
  84. return ql_remove(path);
  85. }
  86. int write (int fildes, const void *buf, size_t nbyte)
  87. {
  88. size_t size = ql_fwrite((void *)buf, nbyte, 1, fildes);
  89. QL_NEWLIB_LOG("write %d %d %s %d",fildes,nbyte,buf,size);
  90. return size;
  91. }