RE: Use of fgets, puts, rewind in Gtk+
Thanks a lot, it was indeed a security problem, now it is solved. Sucheta On Fri, 13 Oct 2006, Madhusudan E wrote: Hi, There is absolutely no problem in doing file operations in GTK based applications. Just check the validity of your operations. Check the validity of your file name , path, Security options ( Read only etc). Always remember to close the file. Nothing to worry much, some silly thing has gone wrong. Rgds, Madhusudan E Hello, I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? Thanks regards, Sucheta Ghosh Indian Statistical Institute, Kolkata ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Use of fgets, puts, rewind in Gtk+
Let me clarify the situation one by one: I can see some problems here, but that's not really GTK-related; Then my question is: how the same code works fine as a simple c file, when I am not using this inside Gtk+? 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) What I have written is only a small piece of code, where I had written the extract only to explain the problem in short. I have done the error checking, the result is fopen() is not getting the null value, but fgets() is getting the null value. And I have declared all the variables unless it would not compile, as I said earlier this is a runtime problem. 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) I have done it in my Gtk+ coding only did not shown it here. And all the other things I have done due to the demand of my application. Thanks regards, Sucheta Ghosh On Thu, 12 Oct 2006, Progss wrote: Sucheta Ghosh napisa?(a): I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? I can see some problems here, but that's not really GTK-related; well - there's also a change that included snippet was simply too short 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) 3) You're reading the same file 8 times - and that's *at least* non-optimal - of course that depends on what exactly you're going to achieve, however I'm quite convinced 4) I'd be really careful about placing some external file operations nside of a callback function. but this depends on your overall application purpose and design. Best regards Waldek -- Czas pozegnac finansowe problemy. Kredyt Citibank - prosty kredyt na wszystkie potrzeby. Sprawdz: http://link.interia.pl/f19a5 ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Use of fgets, puts, rewind in Gtk+
On 10/12/06, Sucheta Ghosh [EMAIL PROTECTED] wrote: Hello, I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Please, copy-paste the error. Do you have any idea that how to overcome this problem? Thanks regards, Sucheta Ghosh Indian Statistical Institute, Kolkata ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Use of fgets, puts, rewind in Gtk+
On Fri, 2006-10-13 at 10:16 +0530, Sucheta Ghosh wrote: Let me clarify the situation one by one: I can see some problems here, but that's not really GTK-related; Then my question is: how the same code works fine as a simple c file, when I am not using this inside Gtk+? Probably because you are just lucky. Often times code that's not quite correct can work fine in a small, standalone test case but fails when run in another context. By the way you never did post the runtime error message you got. Unfortunately without knowing what that error was we cannot help you. 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) What I have written is only a small piece of code, where I had written the extract only to explain the problem in short. I have done the error checking, the result is fopen() is not getting the null value, but fgets() is getting the null value. And I have declared all the variables unless it would not compile, as I said earlier this is a runtime problem. 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) I have done it in my Gtk+ coding only did not shown it here. And all the other things I have done due to the demand of my application. Thanks regards, Sucheta Ghosh On Thu, 12 Oct 2006, Progss wrote: Sucheta Ghosh napisa?(a): I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? I can see some problems here, but that's not really GTK-related; well - there's also a change that included snippet was simply too short 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) 3) You're reading the same file 8 times - and that's *at least* non-optimal - of course that depends on what exactly you're going to achieve, however I'm quite convinced 4) I'd be really careful about placing some external file operations nside of a callback function. but this depends on your overall application purpose and design. Best regards Waldek -- Czas pozegnac finansowe problemy. Kredyt Citibank - prosty kredyt na wszystkie potrzeby. Sprawdz: http://link.interia.pl/f19a5 ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Use of fgets, puts, rewind in Gtk+
Hello, I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? Thanks regards, Sucheta Ghosh Indian Statistical Institute, Kolkata ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Use of fgets, puts, rewind in Gtk+
Sucheta Ghosh napisał(a): I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? I can see some problems here, but that's not really GTK-related; well - there's also a change that included snippet was simply too short 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) 3) You're reading the same file 8 times - and that's *at least* non-optimal - of course that depends on what exactly you're going to achieve, however I'm quite convinced 4) I'd be really careful about placing some external file operations nside of a callback function. but this depends on your overall application purpose and design. Best regards Waldek -- Czas pozegnac finansowe problemy. Kredyt Citibank - prosty kredyt na wszystkie potrzeby. Sprawdz: http://link.interia.pl/f19a5 ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Use of fgets, puts, rewind in Gtk+
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thu, Oct 12, 2006 at 08:14:50PM +0200, Progss wrote: Let me add some cents to Progss' two dollars :-) Sucheta Ghosh napisa?(a): I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? I can see some problems here, but that's not really GTK-related; well - there's also a change that included snippet was simply too short Exactly. Where are n, a[], s and all of them declared? 1) no error checking for fopen(), fgets() - You don't to anything if they fail (and that's most probable) If fopen() fails, it returns NULL. An fread() or fgets() or whatever will core dump on that. 2) can't see any fclose() - multiple fopen()s without closing the file is BAD :) No crash, but a memory leak. Your program will accumulate file descriptors until it runs out of them. This is what they call file descriptor leak. 3) You're reading the same file 8 times - and that's *at least* non-optimal - of course that depends on what exactly you're going to achieve, however I'm quite convinced Yes, this looked strange to me as well. But who knows -- may be something is changing the file (but it must be very quickly indeed). Or it may be a special file in /proc, yielding different results for each read pass. 4) I'd be really careful about placing some external file operations nside of a callback function. but this depends on your overall application purpose and design. Basically I don't see a problem in that -- besides the feeling that file operations are often taking longer time. And of course, things that take longer time shouldn't go in a callback, if you don't want your app to freeze some times. Regards - -- tomas -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFFLxRUBcgs9XrR2kYRAif8AJ4q2sbecDywzz8ek/bXsCe5a5ZtAgCfZQRx lFF8Fg+pixaj6WfLM9Kk4RA= =4LtO -END PGP SIGNATURE- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: Use of fgets, puts, rewind in Gtk+
Hi, There is absolutely no problem in doing file operations in GTK based applications. Just check the validity of your operations. Check the validity of your file name , path, Security options ( Read only etc). Always remember to close the file. Nothing to worry much, some silly thing has gone wrong. Rgds, Madhusudan E Hello, I wished to read a file and get some lines from there like this: - fp=fopen(filename, r); for(k=0; k8; k++){ n=a[k]; for (i=1; i=n; i++) //Here 'n' is the line number fgets(s, 100, fp); puts(s); rewind(fp); } - - This is the code snippet, which is working so well after compiling with 'gcc' compiler, but when I added this code inside Gtk+ callback.c, a runtime error is occuring before execution of 'fgets'. I have already included 'stdio.h', but even then it is not executing. Do you have any idea that how to overcome this problem? Thanks regards, Sucheta Ghosh Indian Statistical Institute, Kolkata ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list