xattr.pas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. {
  2. * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. The rights granted to you under the License
  10. * may not be used to create, or enable the creation or redistribution of,
  11. * unlawful or unlicensed copies of an Apple operating system, or to
  12. * circumvent, violate, or enable the circumvention or violation of, any
  13. * terms of an Apple operating system software license agreement.
  14. *
  15. * Please obtain a copy of the License at
  16. * http://www.opensource.apple.com/apsl/ and read it before using this file.
  17. *
  18. * The Original Code and all software distributed under the License are
  19. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  20. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  21. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  23. * Please see the License for the specific language governing rights and
  24. * limitations under the License.
  25. *
  26. * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  27. }
  28. { Pascal Translation: Peter N Lewis, <[email protected]>, August 2006 }
  29. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2012 }
  30. {
  31. Modified for use with Free Pascal
  32. Version 308
  33. Please report any bugs to <[email protected]>
  34. }
  35. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  36. {$mode macpas}
  37. {$modeswitch cblocks}
  38. {$packenum 1}
  39. {$macro on}
  40. {$inline on}
  41. {$calling mwpascal}
  42. {$IFNDEF FPC_DOTTEDUNITS}
  43. unit xattr;
  44. {$ENDIF FPC_DOTTEDUNITS}
  45. interface
  46. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  47. {$setc GAP_INTERFACES_VERSION := $0308}
  48. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  49. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  50. {$endc}
  51. {$ifc defined CPUPOWERPC and defined CPUI386}
  52. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  53. {$endc}
  54. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  55. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  56. {$endc}
  57. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  58. {$setc __ppc__ := 1}
  59. {$elsec}
  60. {$setc __ppc__ := 0}
  61. {$endc}
  62. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  63. {$setc __ppc64__ := 1}
  64. {$elsec}
  65. {$setc __ppc64__ := 0}
  66. {$endc}
  67. {$ifc not defined __i386__ and defined CPUI386}
  68. {$setc __i386__ := 1}
  69. {$elsec}
  70. {$setc __i386__ := 0}
  71. {$endc}
  72. {$ifc not defined __x86_64__ and defined CPUX86_64}
  73. {$setc __x86_64__ := 1}
  74. {$elsec}
  75. {$setc __x86_64__ := 0}
  76. {$endc}
  77. {$ifc not defined __arm__ and defined CPUARM}
  78. {$setc __arm__ := 1}
  79. {$elsec}
  80. {$setc __arm__ := 0}
  81. {$endc}
  82. {$ifc not defined __arm64__ and defined CPUAARCH64}
  83. {$setc __arm64__ := 1}
  84. {$elsec}
  85. {$setc __arm64__ := 0}
  86. {$endc}
  87. {$ifc defined cpu64}
  88. {$setc __LP64__ := 1}
  89. {$elsec}
  90. {$setc __LP64__ := 0}
  91. {$endc}
  92. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  93. {$error Conflicting definitions for __ppc__ and __i386__}
  94. {$endc}
  95. {$ifc defined __ppc__ and __ppc__}
  96. {$setc TARGET_CPU_PPC := TRUE}
  97. {$setc TARGET_CPU_PPC64 := FALSE}
  98. {$setc TARGET_CPU_X86 := FALSE}
  99. {$setc TARGET_CPU_X86_64 := FALSE}
  100. {$setc TARGET_CPU_ARM := FALSE}
  101. {$setc TARGET_CPU_ARM64 := FALSE}
  102. {$setc TARGET_OS_MAC := TRUE}
  103. {$setc TARGET_OS_IPHONE := FALSE}
  104. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  105. {$setc TARGET_OS_EMBEDDED := FALSE}
  106. {$elifc defined __ppc64__ and __ppc64__}
  107. {$setc TARGET_CPU_PPC := FALSE}
  108. {$setc TARGET_CPU_PPC64 := TRUE}
  109. {$setc TARGET_CPU_X86 := FALSE}
  110. {$setc TARGET_CPU_X86_64 := FALSE}
  111. {$setc TARGET_CPU_ARM := FALSE}
  112. {$setc TARGET_CPU_ARM64 := FALSE}
  113. {$setc TARGET_OS_MAC := TRUE}
  114. {$setc TARGET_OS_IPHONE := FALSE}
  115. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  116. {$setc TARGET_OS_EMBEDDED := FALSE}
  117. {$elifc defined __i386__ and __i386__}
  118. {$setc TARGET_CPU_PPC := FALSE}
  119. {$setc TARGET_CPU_PPC64 := FALSE}
  120. {$setc TARGET_CPU_X86 := TRUE}
  121. {$setc TARGET_CPU_X86_64 := FALSE}
  122. {$setc TARGET_CPU_ARM := FALSE}
  123. {$setc TARGET_CPU_ARM64 := FALSE}
  124. {$ifc defined iphonesim}
  125. {$setc TARGET_OS_MAC := FALSE}
  126. {$setc TARGET_OS_IPHONE := TRUE}
  127. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  128. {$elsec}
  129. {$setc TARGET_OS_MAC := TRUE}
  130. {$setc TARGET_OS_IPHONE := FALSE}
  131. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  132. {$endc}
  133. {$setc TARGET_OS_EMBEDDED := FALSE}
  134. {$elifc defined __x86_64__ and __x86_64__}
  135. {$setc TARGET_CPU_PPC := FALSE}
  136. {$setc TARGET_CPU_PPC64 := FALSE}
  137. {$setc TARGET_CPU_X86 := FALSE}
  138. {$setc TARGET_CPU_X86_64 := TRUE}
  139. {$setc TARGET_CPU_ARM := FALSE}
  140. {$setc TARGET_CPU_ARM64 := FALSE}
  141. {$ifc defined iphonesim}
  142. {$setc TARGET_OS_MAC := FALSE}
  143. {$setc TARGET_OS_IPHONE := TRUE}
  144. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  145. {$elsec}
  146. {$setc TARGET_OS_MAC := TRUE}
  147. {$setc TARGET_OS_IPHONE := FALSE}
  148. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  149. {$endc}
  150. {$setc TARGET_OS_EMBEDDED := FALSE}
  151. {$elifc defined __arm__ and __arm__}
  152. {$setc TARGET_CPU_PPC := FALSE}
  153. {$setc TARGET_CPU_PPC64 := FALSE}
  154. {$setc TARGET_CPU_X86 := FALSE}
  155. {$setc TARGET_CPU_X86_64 := FALSE}
  156. {$setc TARGET_CPU_ARM := TRUE}
  157. {$setc TARGET_CPU_ARM64 := FALSE}
  158. {$setc TARGET_OS_MAC := FALSE}
  159. {$setc TARGET_OS_IPHONE := TRUE}
  160. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  161. {$setc TARGET_OS_EMBEDDED := TRUE}
  162. {$elifc defined __arm64__ and __arm64__}
  163. {$setc TARGET_CPU_PPC := FALSE}
  164. {$setc TARGET_CPU_PPC64 := FALSE}
  165. {$setc TARGET_CPU_X86 := FALSE}
  166. {$setc TARGET_CPU_X86_64 := FALSE}
  167. {$setc TARGET_CPU_ARM := FALSE}
  168. {$setc TARGET_CPU_ARM64 := TRUE}
  169. {$ifc defined ios}
  170. {$setc TARGET_OS_MAC := FALSE}
  171. {$setc TARGET_OS_IPHONE := TRUE}
  172. {$setc TARGET_OS_EMBEDDED := TRUE}
  173. {$elsec}
  174. {$setc TARGET_OS_MAC := TRUE}
  175. {$setc TARGET_OS_IPHONE := FALSE}
  176. {$setc TARGET_OS_EMBEDDED := FALSE}
  177. {$endc}
  178. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  179. {$elsec}
  180. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  181. {$endc}
  182. {$ifc defined __LP64__ and __LP64__ }
  183. {$setc TARGET_CPU_64 := TRUE}
  184. {$elsec}
  185. {$setc TARGET_CPU_64 := FALSE}
  186. {$endc}
  187. {$ifc defined FPC_BIG_ENDIAN}
  188. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  189. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  190. {$elifc defined FPC_LITTLE_ENDIAN}
  191. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  192. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  193. {$elsec}
  194. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  195. {$endc}
  196. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  197. {$setc CALL_NOT_IN_CARBON := FALSE}
  198. {$setc OLDROUTINENAMES := FALSE}
  199. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  200. {$setc OPAQUE_UPP_TYPES := TRUE}
  201. {$setc OTCARBONAPPLICATION := TRUE}
  202. {$setc OTKERNEL := FALSE}
  203. {$setc PM_USE_SESSION_APIS := TRUE}
  204. {$setc TARGET_API_MAC_CARBON := TRUE}
  205. {$setc TARGET_API_MAC_OS8 := FALSE}
  206. {$setc TARGET_API_MAC_OSX := TRUE}
  207. {$setc TARGET_CARBON := TRUE}
  208. {$setc TARGET_CPU_68K := FALSE}
  209. {$setc TARGET_CPU_MIPS := FALSE}
  210. {$setc TARGET_CPU_SPARC := FALSE}
  211. {$setc TARGET_OS_UNIX := FALSE}
  212. {$setc TARGET_OS_WIN32 := FALSE}
  213. {$setc TARGET_RT_MAC_68881 := FALSE}
  214. {$setc TARGET_RT_MAC_CFM := FALSE}
  215. {$setc TARGET_RT_MAC_MACHO := TRUE}
  216. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  217. {$setc TYPE_BOOL := FALSE}
  218. {$setc TYPE_EXTENDED := FALSE}
  219. {$setc TYPE_LONGLONG := TRUE}
  220. {$IFDEF FPC_DOTTEDUNITS}
  221. uses MacOsApi.MacTypes;
  222. {$ELSE FPC_DOTTEDUNITS}
  223. uses MacTypes;
  224. {$ENDIF FPC_DOTTEDUNITS}
  225. {$endc} {not MACOSALLINCLUDE}
  226. {$ALIGN POWER}
  227. const
  228. // Options for pathname based xattr calls
  229. XATTR_NOFOLLOW = $0001; // Don't follow symbolic links
  230. // Options for setxattr calls
  231. XATTR_CREATE = $0002; // set the value, fail if attr already exists
  232. XATTR_REPLACE = $0004; // set the value, fail if attr does not exist
  233. // Set this to bypass authorization checking (eg. if doing auth-related work)
  234. XATTR_NOSECURITY = $0008;
  235. { Set this to bypass the default extended attribute file (dot-underscore file) }
  236. const
  237. XATTR_NODEFAULT = $0010;
  238. { option for f/getxattr() and f/listxattr() to expose the HFS Compression extended attributes }
  239. const
  240. XATTR_SHOWCOMPRESSION = $0020;
  241. const
  242. XATTR_MAXNAMELEN = 127;
  243. { See the ATTR_CMN_FNDRINFO section of getattrlist(2) for details on FinderInfo }
  244. const
  245. XATTR_FINDERINFO_NAME = 'com.apple.FinderInfo';
  246. const
  247. XATTR_RESOURCEFORK_NAME = 'com.apple.ResourceFork';
  248. function getxattr( path: ConstCStringPtr; name: ConstCStringPtr; value: UnivPtr; siz: size_t; position: UInt32; options: SInt32 ): ssize_t; external name '_getxattr';
  249. function fgetxattr( fd: SInt32; name: ConstCStringPtr; value: UnivPtr; siz: size_t; position: UInt32; options: SInt32 ): ssize_t; external name '_fgetxattr';
  250. function setxattr( path: ConstCStringPtr; name: ConstCStringPtr; value: {const} UnivPtr; siz: size_t; position: UInt32; options: SInt32 ): SInt32; external name '_setxattr';
  251. function fsetxattr( fd: SInt32; name: ConstCStringPtr; value: {const} UnivPtr; siz: size_t; position: UInt32; options: SInt32 ): SInt32; external name '_fsetxattr';
  252. function removexattr( path: ConstCStringPtr; name: ConstCStringPtr; options: SInt32 ): SInt32; external name '_removexattr';
  253. function fremovexattr( fd: SInt32; name: ConstCStringPtr; options: SInt32 ): SInt32; external name '_fremovexattr';
  254. function listxattr( path: ConstCStringPtr; namebuff: UnivPtr; siz: size_t; options: SInt32 ): ssize_t; external name '_listxattr';
  255. function flistxattr( fd: SInt32; namebuff: UnivPtr; siz: size_t; options: SInt32 ): ssize_t; external name '_flistxattr';
  256. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  257. end.
  258. {$endc} {not MACOSALLINCLUDE}