Re: [gmime-devel] Need code snippet for MIME decoding



Hi Jeff,

i think the issue is resolved. It could be because of some memory issues here. Sorry for the trouble. Let me see more on this.

thanks
Prasad.


On Thu, Feb 21, 2013 at 11:35 AM, prasad antony <prasadantonymad gmail com> wrote:
Hi Jeff,

Here is my code snippet. I was not using gmime APIs to create my file path location.

const char* outputfile = "/home/prasad/filepathdir/"
char *temp = NULL;
const char* name;
char *tempfile = NULL;

name = g_mime_part_get_filename ((GMimePart *) part);
            temp = (char *)malloc(strlen(name) + 1);  --------> In this line itself I am getting segmentation fault because of strlen(name)--------->
            strcpy(temp,name); 
            printf("%s\n",temp);
            tempfile = (char*)malloc(strlen(outputfile) + strlen(name) + 1);
            strcpy(tempfile,outputfile);
            strcat(tempfile,temp);

            if ((fd = open (tempfile, O_CREAT | O_WRONLY, 0666)) != -1) {
                content = g_mime_part_get_content_object ((GMimePart *) part);
                stream = g_mime_stream_fs_new (fd);

I can do this even without temp variable. strcat(tempfile,name). While accessing the variable name to standard C functions it is giving segmentation fault.

In parallel let me try with your suggestion to do it with gmime APIs....But I would like to understand why the segmentation fault with my code....

Thanks so much Jeff for your quick reply....

Thanks
Prasad.


On Thu, Feb 21, 2013 at 6:26 AM, Jeffrey Stedfast <fejj gnome org> wrote:
On 2/20/2013 6:38 AM, prasad antony wrote:
Hi Jeff,

I am facing one more issue with this program. In this program datatype of variable "name" is const char *. Once we access the file name in to this variable we are opening a file with the same name on the current directory and dumping the content. "name = g_mime_part_get_filename ((GMimePart *) part);" and fd=open(name,....)

 If I want to change the location in which I should get the content what needs to be done?

const char *name = g_mime_part_get_filename ((GMimePart *) part);
char *path = g_build_filename ("/full/path/to", name);
int fd = open (path, ...);
g_free (path);


Reason I am asking is I already wrote the program to define my own location and append this file name with that location so that I can open this file on that location.

How did you do this?


But by accessing the variable "name" it is giving segmentation fault.

Sounds like you somehow corrupted the memory pointed to by name. Did you free() it? Don't.


Even if I do a strlen(name) after the line "name = g_mime_part_get_filename ((GMimePart *) part); , it is giving segmentation fault. Why I am not able to do operations with this variable? But I am able to open file with this name. Can you please help....

I don't know, do you have a code snippet to show what you did?

Jeff





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]