problem on file io
- From: rachit goel <panthers0072001 yahoo co uk>
- To: gtk-app-devel-list gnome org
- Subject: problem on file io
- Date: Thu, 4 May 2006 06:38:15 +0100 (BST)
Hi all ,
I am facing a problem in file io.
The issue is that i use libwnck to get the current active window and then need to append it and the
timestamp in a file .
This is where i am facing a problem. When i looked at the gtk's help base i couldn,t find any file io
functions, so I decided to use the simple C file io mechanism now here i face a very big probs.
C is not designed to handle multi-byte chars.
Now i use "mbstowcs()" to convert multibyte to wchar.
this is working fine, i think, now when i try to write this to file using fwprintf or fputws i get warning
for implicit declaration of these functions and nothing happens in file and the screen also.
the code i am using is :--
# define WNCK_I_KNOW_THIS_IS_UNSTABLE
# include <glib/gprintf.h>
# include <libwnck/libwnck.h>
# include <gdk/gdk.h>
# include <gtk/gtk.h>
# include <glib.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <time.h>
# include <wchar.h>
# include <string.h>
# include <stdarg.h>
//
-----------some global declarations ---------
main()
{.
.
.
.
exe_dir = g_path_get_dirname(argv[0]);
.
.
.
file_name = g_strdup_printf("%s/data.log",exe_dir);
memset (&state, '\0', sizeof (state));
logfile = fopen (file_name,"a");
fwide(logfile,0); // gives implicit declaration too
g_timeout_add(1500,timeout_func,NULL);
gtk_main ();
sync();
fclose (logfile);
g_free(file_name);
}
int timeout_func()
{
//screen = wnck_screen_get_default() ;
char *file_str;
int fp;
GError **error;
WnckWindow* window1 = wnck_screen_get_active_window(screen);
time1 = time(NULL);
gulong win_xid = wnck_window_get_xid (window1);
if (win_xid != last_active_xid)
{
last_window = window1;
last_time = time1 ;
last_active_xid = win_xid;
last_name = wnck_window_get_name(window1);
last_app = wnck_window_get_application (window1);
last_app_name = wnck_application_get_name(last_app);
last_pid = wnck_application_get_pid(last_app);
file_str = g_strdup_printf("/proc/%d/cmdline",last_pid);
fp = open(file_str , O_RDONLY);
g_printf("\nfp = %d , time = %ld\n",fp,(long int)last_time);
if (fp > -1)
{
read(fp , last_app_command , 1000);
}
close (fp);
g_printf("win_xid = %lu , name = %s , pid = %d \n filename = %s , appname = %s , command = %s\n" ,
last_active_xid , last_name ,last_pid , file_str , last_app_name , last_app_command);
g_free(file_str);
char * str = g_strdup_printf("%s,%ld\n",last_app_command,(long int)last_time) ;
int count = g_utf8_strlen(str,-1);
int size = count *6 ;
g_printf ("\nstring = %s, size = %d , strlen = %d\n" , str , size,count); //fputs(str ,logfile),
wchar_t *dest = NULL ;
int count1 = mbstowcs(dest , str,count+2);//,&state);
//fputws(dest,logfile);
fwprintf (logfile,"%ls",dest);//"\nwidestring = %ls",
//fputws(dest,stdout);
//,size,count
}
return TRUE;
}
also i am using this to compile and build :-----------
gcc -Wall -O2 keytrap.c -o keyboard `pkg-config --cflags --libs libwnck-1.0`
the only probs here is the file handling
can somebody please tell me what is wrong here and the write prcedure too .
thanks in advance .........
---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]