![]() |
2010-06-13
, 08:55
|
|
Posts: 664 |
Thanked: 160 times |
Joined on Jul 2008
@ Australia
|
#2
|
#include <glib.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> char* getUsbMode(void); gboolean check(gchar*); int main(){ gchar *dir = "scratchbox/users/user/home/user/photoapplet/200910a0"; GMainLoop *loop = NULL; loop = g_main_loop_new(NULL, FALSE); g_timeout_add_seconds(3, (GSourceFunc)check, dir); g_main_loop_run(loop); return 0; } gboolean check(gchar *dir){ if (g_file_test(dir, G_FILE_TEST_EXISTS)){ printf("Can access %s\n", dir); }else{ printf("Can't access directory.\n"); char *usb_mode = NULL; usb_mode = getUsbMode(); if (strcmp(usb_mode, "MASS_STORAGE") == 0){ printf("USB mass storage mode activated.\n"); } } return TRUE; } char* getUsbMode(){ char *file = "/tmp/.current_usb_mode"; char *mode, val[15]; mode = (char *) malloc(sizeof(char*)); assert(mode != NULL); FILE *fPtr; if ((fPtr = fopen(file, "r")) != NULL){ fgets(val, 15, fPtr); val[strlen(val) - 2] = '\0'; strcpy(mode, val); printf("%s\n", mode); fclose(fPtr); return mode; }else return "READ_FAILED"; }
![]() |
2010-06-13
, 09:14
|
|
Posts: 664 |
Thanked: 160 times |
Joined on Jul 2008
@ Australia
|
#4
|
What are you allocating here?Code:mode = (char *) malloc(sizeof(char*));
![]() |
2010-06-13
, 09:16
|
|
Posts: 4,274 |
Thanked: 5,358 times |
Joined on Sep 2007
@ Looking at y'all and sighing
|
#5
|
memory to store string which is read from the file and stored in array of char.
The Following User Says Thank You to qwerty12 For This Useful Post: | ||
![]() |
2010-06-13
, 11:45
|
|
Posts: 664 |
Thanked: 160 times |
Joined on Jul 2008
@ Australia
|
#6
|
![]() |
2010-06-13
, 13:36
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#7
|
memory to store string which is read from the file and stored in array of char.
EDIT: I can't believe it, I thought it was neededbut it was the source of problem damn me.... THANK YOU.
printf("%d\n", sizeof(char *));
I'm getting segmentation fault randomly in my desktop app for fremantle and I just couldn't figure out what's causing it and the exact source code. I'm using gtk+, gdb and maemo-summoner in scratchbox. Following is the error message and the backtrace from gdb: Thanks