/src/ftk_file_system_dummy.c

http://ftk.googlecode.com/ · C · 138 lines · 84 code · 25 blank · 29 comment · 9 complexity · ed42557a7db2da391e324d247e4a8476 MD5 · raw file

  1. /*
  2. * File: ftk_file_system_posix.c
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: posix implemented file system adaptor.
  5. *
  6. * Copyright (c) 2009 - 2011 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2011-04-19 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk_util.h"
  31. #include "ftk_file_system.h"
  32. Ret ftk_file_get_info(const char* file_name, FtkFileInfo* info)
  33. {
  34. int ret = 0;
  35. struct stat st;
  36. return_val_if_fail(file_name != NULL && info != NULL, RET_FAIL);
  37. if((ret = stat(file_name, &st)) == 0)
  38. {
  39. memset(info, 0x00, sizeof(FtkFileInfo));
  40. info->uid = st.st_uid;
  41. info->gid = st.st_gid;
  42. info->mode = st.st_mode;
  43. info->size = st.st_size;
  44. info->is_dir = 0;
  45. info->last_access = st.st_atime;
  46. info->last_modify = st.st_mtime;
  47. ftk_strncpy(info->name, file_name, FTK_MAX_PATH);
  48. return RET_OK;
  49. }
  50. return RET_FAIL;
  51. }
  52. FtkFsHandle ftk_file_open(const char* file_name, const char* mode)
  53. {
  54. return_val_if_fail(file_name != NULL && mode != NULL, NULL);
  55. return fopen(file_name, mode);
  56. }
  57. int ftk_file_seek(FtkFsHandle file, size_t pos)
  58. {
  59. return fseek(file, pos, SEEK_SET);
  60. }
  61. int ftk_file_read(FtkFsHandle file, void* buffer, size_t length)
  62. {
  63. return fread(buffer, 1, length, file);
  64. }
  65. int ftk_file_write(FtkFsHandle file, const void* buffer, size_t length)
  66. {
  67. return fwrite(buffer, 1, length, file);
  68. }
  69. void ftk_file_close(FtkFsHandle file)
  70. {
  71. return_if_fail(file != NULL);
  72. fclose(file);
  73. }
  74. FtkFsHandle ftk_dir_open(const char* dir_name)
  75. {
  76. return NULL;
  77. }
  78. Ret ftk_dir_read(FtkFsHandle dir, FtkFileInfo* info)
  79. {
  80. return RET_FAIL;
  81. }
  82. void ftk_dir_close(FtkFsHandle dir)
  83. {
  84. return;
  85. }
  86. Ret ftk_fs_get_cwd(char cwd[FTK_MAX_PATH+1])
  87. {
  88. return RET_FAIL;
  89. }
  90. Ret ftk_fs_delete_dir(const char* dir)
  91. {
  92. return RET_FAIL;
  93. }
  94. Ret ftk_fs_delete_file(const char* file_name)
  95. {
  96. return RET_FAIL;
  97. }
  98. Ret ftk_fs_create_dir(const char* dir)
  99. {
  100. return RET_FAIL;
  101. }
  102. Ret ftk_fs_change_dir(const char* dir)
  103. {
  104. return RET_FAIL;
  105. }
  106. Ret ftk_fs_move(const char* dir_from, const char* dir_to)
  107. {
  108. return RET_FAIL;
  109. }
  110. int ftk_fs_is_root(const char* path)
  111. {
  112. return 0;
  113. }