inotify.nim 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. {.deprecated: [Tinotify_event: InotifyEvent].}
  21. # Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.
  22. const
  23. IN_ACCESS* = 0x00000001 # File was accessed.
  24. IN_MODIFY* = 0x00000002 # File was modified.
  25. IN_ATTRIB* = 0x00000004 # Metadata changed.
  26. IN_CLOSE_WRITE* = 0x00000008 # Writtable file was closed.
  27. IN_CLOSE_NOWRITE* = 0x00000010 # Unwrittable file closed.
  28. IN_CLOSE* = (IN_CLOSE_WRITE or IN_CLOSE_NOWRITE) # Close.
  29. IN_OPEN* = 0x00000020 # File was opened.
  30. IN_MOVED_FROM* = 0x00000040 # File was moved from X.
  31. IN_MOVED_TO* = 0x00000080 # File was moved to Y.
  32. IN_MOVE* = (IN_MOVED_FROM or IN_MOVED_TO) # Moves.
  33. IN_CREATE* = 0x00000100 # Subfile was created.
  34. IN_DELETE* = 0x00000200 # Subfile was deleted.
  35. IN_DELETE_SELF* = 0x00000400 # Self was deleted.
  36. IN_MOVE_SELF* = 0x00000800 # Self was moved.
  37. # Events sent by the kernel.
  38. const
  39. IN_UNMOUNT* = 0x00002000 # Backing fs was unmounted.
  40. IN_Q_OVERFLOW* = 0x00004000 # Event queued overflowed.
  41. IN_IGNORED* = 0x00008000 # File was ignored.
  42. # Special flags.
  43. const
  44. IN_ONLYDIR* = 0x01000000 # Only watch the path if it is a
  45. # directory.
  46. IN_DONT_FOLLOW* = 0x02000000 # Do not follow a sym link.
  47. IN_EXCL_UNLINK* = 0x04000000 # Exclude events on unlinked
  48. # objects.
  49. IN_MASK_ADD* = 0x20000000 # Add to the mask of an already
  50. # existing watch.
  51. IN_ISDIR* = 0x40000000 # Event occurred against dir.
  52. IN_ONESHOT* = 0x80000000 # Only send event once.
  53. # All events which a program can wait on.
  54. const
  55. IN_ALL_EVENTS* = (IN_ACCESS or IN_MODIFY or IN_ATTRIB or IN_CLOSE_WRITE or
  56. IN_CLOSE_NOWRITE or IN_OPEN or IN_MOVED_FROM or IN_MOVED_TO or
  57. IN_CREATE or IN_DELETE or IN_DELETE_SELF or IN_MOVE_SELF)
  58. # Create and initialize inotify instance.
  59. proc inotify_init*(): cint{.cdecl, importc: "inotify_init",
  60. header: "<sys/inotify.h>".}
  61. # Create and initialize inotify instance.
  62. proc inotify_init1*(flags: cint): cint{.cdecl, importc: "inotify_init1",
  63. header: "<sys/inotify.h>".}
  64. # Add watch of object NAME to inotify instance FD. Notify about
  65. # events specified by MASK.
  66. proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint{.
  67. cdecl, importc: "inotify_add_watch", header: "<sys/inotify.h>".}
  68. # Remove the watch specified by WD from the inotify instance FD.
  69. proc inotify_rm_watch*(fd: cint; wd: cint): cint{.cdecl,
  70. importc: "inotify_rm_watch", header: "<sys/inotify.h>".}