fcntl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @file fcntl.h
  3. * @author fslongjin ([email protected])
  4. * @brief
  5. * @version 0.1
  6. * @date 2022-04-26
  7. *
  8. * @copyright Copyright (c) 2022
  9. *
  10. */
  11. #pragma once
  12. #define O_RDONLY 00000000 // Open Read-only
  13. #define O_WRONLY 00000001 // Open Write-only
  14. #define O_RDWR 00000002 // Open read/write
  15. #define O_ACCMODE 00000003 // Mask for file access modes
  16. #define O_CREAT 00000100 // Create file if it does not exist
  17. #define O_EXCL 00000200 // Fail if file already exists
  18. #define O_NOCTTY 00000400 // Do not assign controlling terminal
  19. #define O_TRUNC 00001000 // 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
  20. #define O_APPEND 00002000 // 文件指针会被移动到文件末尾
  21. #define O_NONBLOCK 00004000 // 非阻塞式IO模式
  22. #define O_EXEC 00010000 // 以仅执行的方式打开(非目录文件)
  23. #define O_SEARCH 00020000 // Open the directory for search only
  24. #define O_DIRECTORY 00040000 // 打开的必须是一个目录
  25. #define O_NOFOLLOW 00100000 // Do not follow symbolic links
  26. /*
  27. * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is
  28. * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
  29. * unlinkat. The two functions do completely different things and therefore,
  30. * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
  31. * faccessat would be undefined behavior and thus treating it equivalent to
  32. * AT_EACCESS is valid undefined behavior.
  33. */
  34. // 作为当前工作目录的文件描述符(用于指代cwd)
  35. #define AT_FDCWD -100
  36. #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
  37. #define AT_EACCESS 0x200 /* Test access permitted for effective IDs, not real IDs. */
  38. #define AT_REMOVEDIR 0x200 /* Remove directory instead of unlinking file. */
  39. #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
  40. #define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
  41. #define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
  42. #define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
  43. #define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
  44. #define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
  45. #define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
  46. #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
  47. /**
  48. * @brief 打开文件的接口
  49. *
  50. * @param path 文件路径
  51. * @param options 打开选项
  52. * @param ...
  53. * @return int 文件描述符
  54. */
  55. int open(const char * path, int options, ...);