sqliterk_os.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Tencent is pleased to support the open source community by making
  3. * WCDB available.
  4. *
  5. * Copyright (C) 2017 THL A29 Limited, a Tencent company.
  6. * All rights reserved.
  7. *
  8. * Licensed under the BSD 3-Clause License (the "License"); you may not use
  9. * this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * https://opensource.org/licenses/BSD-3-Clause
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #ifndef sqliterk_os_h
  21. #define sqliterk_os_h
  22. #include "SQLiteRepairKit.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. typedef struct sqliterk_file sqliterk_file;
  26. // sqliterk_os is the virtual layer to fit different os or platform.
  27. // TODO
  28. typedef struct sqliterk_os sqliterk_os;
  29. // memory allocation and set the allocated memory to zero-values
  30. void *sqliterkOSMalloc(size_t size);
  31. void sqliterkOSFree(void *p);
  32. int sqliterkOSLog(sqliterk_loglevel loglevel,
  33. int result,
  34. const char *format,
  35. ...)
  36. #ifdef __GNUC__
  37. __attribute__((format(printf, 3, 4)))
  38. #endif
  39. ;
  40. int sqliterkOSRegister(sqliterk_os os);
  41. #define sqliterkOSDebug(result, ...) \
  42. sqliterkOSLog(sqliterk_loglevel_debug, result, ##__VA_ARGS__)
  43. #define sqliterkOSWarning(result, ...) \
  44. sqliterkOSLog(sqliterk_loglevel_warning, result, ##__VA_ARGS__)
  45. #define sqliterkOSError(result, ...) \
  46. sqliterkOSLog(sqliterk_loglevel_error, result, ##__VA_ARGS__)
  47. #define sqliterkOSInfo(result, ...) \
  48. sqliterkOSLog(sqliterk_loglevel_info, result, ##__VA_ARGS__)
  49. int sqliterkOSReadOnlyOpen(const char *path, sqliterk_file **file);
  50. int sqliterkOSClose(sqliterk_file *file);
  51. int sqliterkOSRead(sqliterk_file *file,
  52. off_t offset,
  53. unsigned char *data,
  54. size_t *size);
  55. int sqliterkOSFileSize(sqliterk_file *file, size_t *filesize);
  56. const char *sqliterkOSGetFilePath(sqliterk_file *file);
  57. #endif /* sqliterk_os_h */