LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-08-2014, 11:12 AM   #1
MichaelStein
LQ Newbie
 
Registered: Apr 2014
Posts: 14

Rep: Reputation: Disabled
Getting errors with inotify


Hi there fellas,

I am new to inotify. I was trying to copy an example from a web tutorial but when I try to run it I get errors. To be more specific, I am trying to find out why the function 'read()' is being recorded as an error.

//This is the sample program to notify us for the file creation and file deletion takes place in “/tmp” directory
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>
//#include <linux/inotify.h>

#define EVENT_SIZE ( sizeof( struct inotify_event) )
#define EVENT_BUF_LEN ( 1024*( EVENT_SIZE) )

int main()
{
int length, i =0;
int fd;
int wd;
char buffer( EVENT_BUF_LEN);

fd = inotify_init();

if( fd < 0)
{
perror( "inotify_init" );
}

wd = inotify_add_watch( fd, "/home/michaelstein/Desktop/Data.txt", IN_CREATE | IN_DELETE );

length = read(fd, buffer, EVENT_BUF_LEN);

if( length < 0 )
{
perror( "read" );
}

while( i < 0 )
{
struct inotify_event *event = ( struct inotify_event * ) &buffer[i];
if( event->length )
{
if(event->mask & IN_CREATE )
{
if(event->mask & IN_ISDIR )
{
printf("New directory %n was created.\n", event->name);
}
else
{
printf("New file %n was created. \n", event->name);
}
}
else if(event->mask & IN_DELETE)
{
if(event->mask & IN_ISDIR )
{
printf("Directory %n deleted.\n", event->name);
}
else
{
printf("File %n deleted. \n", event->name);
}
}
}
i += EVENT_SIZE + event->len;
}

inotify_rm_watch( fd, wd );

close( fd );

}

I the following errors:

inotify.cxx: In function ‘int main()’:
inotify.cxx:16:28: warning: overflow in implicit constant conversion [-Woverflow]
inotify.cxx:27:41: error: ‘read’ was not declared in this scope
inotify.cxx:36:69: error: invalid types ‘char[int]’ for array subscript
inotify.cxx:37:14: error: ‘struct inotify_event’ has no member named ‘length’

If anyone has anything that could enlighten me I would be very grateful. Additionally, if anyone could point to a code snippet about inotify or else a site that gives detailed information about inotify I would be equally indebted.
Thank you.
 
Old 04-08-2014, 03:35 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,149

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
Because you aren't including the header file that read calls out:

Code:
man 2 read

NAME
       read - read from a file descriptor

SYNOPSIS
       #include <unistd.h>

       ssize_t read(int fd, void *buf, size_t count);
 
  


Reply

Tags
inotify



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using inotify sniper8752 Linux - Newbie 1 04-06-2013 08:37 PM
[SOLVED] inotify Navodar Linux - Kernel 1 02-08-2011 12:03 PM
inotify chymeira Linux - General 3 03-06-2009 04:58 AM
udev and inotify aeruzcar Linux - General 3 03-24-2007 12:42 PM
Mounting Inotify? trscookie Linux - Software 1 12-19-2005 01:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration