Help - Search - Members - Calendar
Full Version: Envz Utilities
Linuxhelp > Support > Programming in Linux
I'm trying to perform file manipulation using the envz utilities and I'm having problems using envz_add. I have no problem with envz_get, but when I use envz_add to update a value I get a seg fault.

If anyone has used the envz utilities, I would appreciate the help. Below is an example of what I'm trying to do.

pFile = fopen(file, "r+");

if(pFile != NULL)
fseek(pFile, 0, SEEK_END);
size = ftell(pFile);
fseek(pFile, 0, SEEK_SET);

filebuf = malloc(size);
fread(filebuf, size, 1, pFile);

envz_add(&filebuf, &size, key, value); // Seg Fault occurs here filebuf is char *, size is size_t
// key is char[], value is char[]

try this...

filebuf = (char *)malloc(size);

The problem might be:

1.Either malloc() has failed
2. Or fread() has failed.

Just tell me which one has actually failed.You can find that out...using strace and gdb.
do a
$strace a.out
I figured out the problem. The strings in the file need to be NULL terminated. When creating the test file is there any way to NULL terminate a string?
I don't know if that's possible.All the files are EOF terminated and trying to make them NULL terminated is kind of weird.

Why not use this...
while(pFile != EOF)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.