lha_arch.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Copyright (c) 2012, Simon Howard
  3. Permission to use, copy, modify, and/or distribute this software
  4. for any purpose with or without fee is hereby granted, provided
  5. that the above copyright notice and this permission notice appear
  6. in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  8. WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  9. WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  10. AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  11. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef LHASA_LHA_ARCH_H
  17. #define LHASA_LHA_ARCH_H
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <stdint.h>
  21. #define LHA_ARCH_UNIX 1
  22. #define LHA_ARCH_WINDOWS 2
  23. #ifdef _WIN32
  24. #define LHA_ARCH LHA_ARCH_WINDOWS
  25. #else
  26. #define LHA_ARCH LHA_ARCH_UNIX
  27. #endif
  28. typedef enum {
  29. LHA_FILE_NONE,
  30. LHA_FILE_FILE,
  31. LHA_FILE_DIRECTORY,
  32. LHA_FILE_ERROR,
  33. } LHAFileType;
  34. /**
  35. * Cross-platform version of vasprintf().
  36. *
  37. * @param result Pointer to a variable to store the resulting string.
  38. * @param fmt Format string.
  39. * @param args Additional arguments for printf().
  40. * @return Number of characters in resulting string, or -1 if
  41. * an error occurred in generating the string.
  42. */
  43. int lha_arch_vasprintf(char **result, char *fmt, va_list args);
  44. /**
  45. * Change the mode of the specified FILE handle to be binary mode.
  46. *
  47. * @param handle The FILE handle.
  48. */
  49. void lha_arch_set_binary(FILE *handle);
  50. /**
  51. * Create a directory.
  52. *
  53. * @param path Path to the directory to create.
  54. * @param unix_perms Unix permissions for the directory to create.
  55. * @return Non-zero if the directory was created successfully.
  56. */
  57. int lha_arch_mkdir(char *path, unsigned int unix_perms);
  58. /**
  59. * Change the Unix ownership of the specified file or directory.
  60. * If this is not a Unix system, do nothing.
  61. *
  62. * @param filename Path to the file or directory.
  63. * @param unix_uid The UID to set.
  64. * @param unix_gid The GID to set.
  65. * @return Non-zero if set successfully.
  66. */
  67. int lha_arch_chown(char *filename, int unix_uid, int unix_gid);
  68. /**
  69. * Change the Unix permissions on the specified file or directory.
  70. *
  71. * @param filename Path to the file or directory.
  72. * @param unix_perms The permissions to set.
  73. * @return Non-zero if set successfully.
  74. */
  75. int lha_arch_chmod(char *filename, int unix_perms);
  76. /**
  77. * Set the file creation / modification time on the specified file or
  78. * directory.
  79. *
  80. * @param filename Path to the file or directory.
  81. * @param timestamp The Unix timestamp to set.
  82. * @return Non-zero if set successfully.
  83. */
  84. int lha_arch_utime(char *filename, unsigned int timestamp);
  85. /**
  86. * Set the file creation, modification and access times for the
  87. * specified file or directory, using 64-bit Windows timestamps.
  88. *
  89. * @param filename Path to the file or directory.
  90. * @param creation_time 64-bit Windows FILETIME value for the
  91. * creation time of the file.
  92. * @param modification_time Modification time of the file.
  93. * @param access_time Last access time of the file.
  94. * @return Non-zero if set successfully.
  95. */
  96. int lha_arch_set_windows_timestamps(char *filename,
  97. uint64_t creation_time,
  98. uint64_t modification_time,
  99. uint64_t access_time);
  100. /**
  101. * Open a new file for writing.
  102. *
  103. * @param filename Path to the file or directory.
  104. * @param unix_uid Unix UID to set for the new file, or -1 to not set.
  105. * @param unix_gid Unix GID to set for the new file, or -1 to not set.
  106. * @param unix_perms Unix permissions to set for the new file, or -1 to not
  107. * set.
  108. * @return Standard C file handle.
  109. */
  110. FILE *lha_arch_fopen(char *filename, int unix_uid,
  111. int unix_gid, int unix_perms);
  112. /**
  113. * Query whether the specified file exists.
  114. *
  115. * @param filename Path to the file.
  116. * @return The type of file.
  117. */
  118. LHAFileType lha_arch_exists(char *filename);
  119. /**
  120. * Create a symbolic link.
  121. *
  122. * If a file already exists at the location of the link to be created, it is
  123. * overwritten.
  124. *
  125. * @param path Path to the symbolic link to create.
  126. * @param target Target for the symbolic link.
  127. * @return Non-zero for success.
  128. */
  129. int lha_arch_symlink(char *path, char *target);
  130. #endif /* ifndef LHASA_LHA_ARCH_H */