LinuxQuestions.org
Review your favorite Linux distribution.
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 07-04-2014, 01:30 AM   #1
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Rep: Reputation: Disabled
error in time program


I tried this program for getting current time but i am getting errors.
code:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include<linux/time.h>
static int
hz_show(struct seq_file *m, void *v)
{
struct timeval time;
unsigned long local_time;

do_gettimeofday(&time);
local_time = (u32)(time.tv_sec - (sys_tz.tz_minuteswest * 60));
rtc_time_to_tm(local_time, &tm);

printk(" @ (%04d-%02d-%02d %02d:%02d:%02d)\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);

return 0;
}

static int
hz_open(struct inode *inode, struct file *file)
{
return single_open(file, hz_show, NULL);
}

static const struct file_operations hz_fops = {
.owner = THIS_MODULE,
.open = hz_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int __init
hz_init(void)
{
printk(KERN_INFO "Loading hz module, HZ = %d.\n", HZ);
proc_create("hi", 0, NULL, &hz_fops);
return 0;
}

static void __exit
hz_exit(void)
{
remove_proc_entry("hz", NULL);
printk(KERN_INFO "Unloading hz module.\n");
}

module_init(hz_init);
module_exit(hz_exit);

MODULE_LICENSE("GPL");

error:

In function ‘hz_show’:
/home/s/lt.c:16: error: implicit declaration of function ‘rtc_time_to_tm ’
/home/s/lt.c:16: error: ‘tm’ undeclared (first use in this function)
/home/s/lt.c:16: error: (Each undeclared identifier is reported only once /home/s/lt.c:16: error: for each function it appears in.)
make[2]: *** [/home/s/lt.o] Error 1
make[1]: *** [_module_/home/s] Error 2

How should i correct this?
 
Old 07-04-2014, 01:44 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
looks like you need an additional include:
#include <linux/rtc.h>
 
Old 07-04-2014, 02:11 AM   #3
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Original Poster
Rep: Reputation: Disabled
I still get tm undeclared though i have included time.h
 
Old 07-04-2014, 02:43 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
because the variable tm is undeclared.
you need to declare it for example:
struct rtc_time *tm;
 
Old 07-04-2014, 03:52 AM   #5
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Original Poster
Rep: Reputation: Disabled
tm is actually a structure in time.h
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
 
Old 07-04-2014, 04:20 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
you have an undeclared variable, not an undefined struct. You must declare the variable tm before usage.
 
  


Reply

Tags
linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Help with fortran program--encountered run time error fu3lc3ll$ Programming 6 05-21-2011 07:25 AM
[SOLVED] How to run a program for a specific amount of time starting at a specific time? thiemster Linux - Newbie 12 05-18-2010 10:04 AM
Idle time vs program time kinkle Linux - General 4 03-11-2009 10:57 PM


All times are GMT -5. The time now is 01:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration