inotify.nim 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2012 Dominik Picheta
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. {.deadCodeElim: on.} # dce option deprecated
  10. # Get the platform-dependent flags.
  11. # Structure describing an inotify event.
  12. type
  13. InotifyEvent*{.pure, final, importc: "struct inotify_event",
  14. header: "<sys/inotify.h>".} = object
  15. wd*{.importc: "wd".}: cint # Watch descriptor.
  16. mask*{.importc: "mask".}: uint32 # Watch mask.
  17. cookie*{.importc: "cookie".}: uint32 # Cookie to synchronize two events.
  18. len*{.importc: "len".}: uint32 # Length (including NULs) of name.
  19. name*{.importc: "name".}: char # Name.
  20. # Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.
  21. const
  22. IN_ACCESS* = 0x00000001 # File was accessed.
  23. IN_MODIFY* = 0x00000002 # File was modified.
  24. IN_ATTRIB* = 0x00000004 # Metadata changed.
  25. IN_CLOSE_WRITE* = 0x00000008 # Writtable file was closed.
  26. IN_CLOSE_NOWRITE* = 0x00000010 # Unwrittable file closed.
  27. IN_CLOSE* = (IN_CLOSE_WRITE or IN_CLOSE_NOWRITE) # Close.
  28. IN_OPEN* = 0x00000020 # File was opened.
  29. IN_MOVED_FROM* = 0x00000040 # File was moved from X.
  30. IN_MOVED_TO* = 0x00000080 # File was moved to Y.
  31. IN_MOVE* = (IN_MOVED_FROM or IN_MOVED_TO) # Moves.
  32. IN_CREATE* = 0x00000100 # Subfile was created.
  33. IN_DELETE* = 0x00000200 # Subfile was deleted.
  34. IN_DELETE_SELF* = 0x00000400 # Self was deleted.
  35. IN_MOVE_SELF* = 0x00000800 # Self was moved.
  36. # Events sent by the kernel.
  37. const
  38. IN_UNMOUNT* = 0x00002000 # Backing fs was unmounted.
  39. IN_Q_OVERFLOW* = 0x00004000 # Event queued overflowed.
  40. IN_IGNORED* = 0x00008000 # File was ignored.
  41. # Special flags.
  42. const
  43. IN_ONLYDIR* = 0x01000000 # Only watch the path if it is a
  44. # directory.
  45. IN_DONT_FOLLOW* = 0x02000000 # Do not follow a sym link.
  46. IN_EXCL_UNLINK* = 0x04000000 # Exclude events on unlinked
  47. # objects.
  48. IN_MASK_ADD* = 0x20000000 # Add to the mask of an already
  49. # existing watch.
  50. IN_ISDIR* = 0x40000000 # Event occurred against dir.
  51. IN_ONESHOT* = 0x80000000 # Only send event once.
  52. # All events which a program can wait on.
  53. const
  54. IN_ALL_EVENTS* = (IN_ACCESS or IN_MODIFY or IN_ATTRIB or IN_CLOSE_WRITE or
  55. IN_CLOSE_NOWRITE or IN_OPEN or IN_MOVED_FROM or IN_MOVED_TO or
  56. IN_CREATE or IN_DELETE or IN_DELETE_SELF or IN_MOVE_SELF)
  57. # Create and initialize inotify instance.
  58. proc inotify_init*(): cint{.cdecl, importc: "inotify_init",
  59. header: "<sys/inotify.h>".}
  60. # Create and initialize inotify instance.
  61. proc inotify_init1*(flags: cint): cint{.cdecl, importc: "inotify_init1",
  62. header: "<sys/inotify.h>".}
  63. # Add watch of object NAME to inotify instance FD. Notify about
  64. # events specified by MASK.
  65. proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint{.
  66. cdecl, importc: "inotify_add_watch", header: "<sys/inotify.h>".}
  67. # Remove the watch specified by WD from the inotify instance FD.
  68. proc inotify_rm_watch*(fd: cint; wd: cint): cint{.cdecl,
  69. importc: "inotify_rm_watch", header: "<sys/inotify.h>".}