7

So I'm trying to write a C program that uses inotify. I've used pyinotify before so I understand how it works. However, I'm following some guide and it tells me to include <linux/inotify.h>. The problem is that this header only has macro definitions, not the funciton prototypes. It looks like the functions are prototyped in <sys/inotify.h>.

My question is what's the difference between linux/inotify.h and sys/inotify.h? Why are there both?

Falmarri
  • 47,727
  • 41
  • 151
  • 191

1 Answers1

8

sys/inotify.h is part of the GNU C library. It exposes the structures and functions that your program will use in order to receive filesystem change notifications. It can be considered as the public API of the notification system.

linux/inotify.h is part of the Linux kernel. It defines the kernel structures and constants used to implement the notification system itself. You shouldn't include that file unless you're writing something like a kernel module, because it's Linux-specific and thus not portable.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • sys/inotify.h is not part of the standard library! (It is, however, part of the libraries typically available on a linux box) – Billy ONeal Dec 12 '10 at 08:07
  • @Billy, my `sys/inotify.h` says `This file is part of the GNU C library` right in the top of the file, and my package manager says it's installed by `glibc`. What does yours say? – Frédéric Hamidi Dec 12 '10 at 08:17
  • 2
    @Frédéric: GNU C Library != Standard Library. Standard Library == `ISO/IEC 9899:1990` or `ISO/IEC 9899:1999`. – Billy ONeal Dec 12 '10 at 08:18
  • @Billy, `glibc` is an implementation of the standard library defined in the ISO standards you're citing. What's the problem? :) – Frédéric Hamidi Dec 12 '10 at 08:30
  • 4
    Sure, but not all of glibc belongs to the standard. This is one of those bits. – Ignacio Vazquez-Abrams Dec 12 '10 at 09:00
  • 3
    @Frédéric Hamidi: Glibc contains **tons** of GNU and POSIX specific stuff -- namely *anything* in the "sys/" folder for headers, "unistd.h", stuff for sockets... etc. The standard library is only `assert.h`, `ctype.h`, `errno.h`, `float.h`, `iso646.h`, `limits.h`, `locale.h`, `math.h`, `setjmp.h`, `signal.h`, `stdarg.h`, `stddef.h`, `stdio.h`, `stdlib.h`, `string.h`, and `time.h`. (Well a few things were added in C99 but I don't have that list ATM..) – Billy ONeal Dec 12 '10 at 09:09
  • @Billy, @Ignacio, thanks for the clarification, I'll add `GNU` to my answer then :) – Frédéric Hamidi Dec 12 '10 at 09:24
  • 2
    To echo GNU != POSIX, BSD does not have `inotify` as the functionality is in `kqueue`. For portability, try http://mark.heily.com/pnotify/ – chrisaycock Dec 12 '10 at 09:30