[GRASS5] DB default settings now defined in new mapset

Markus Neteler neteler at itc.it
Tue Oct 18 11:25:42 EDT 2005


Hello Paul,

On Tue, Oct 18, 2005 at 04:07:56PM +0100, Paul Kelly wrote:
> Hello Markus
> 
> On Tue, 18 Oct 2005, Markus Neteler wrote:
> 
> >Unfortunately, I don't manage to program it:
> >In file lib/init/mke_mapset.c
> >
> >/* generate DB settings file in new mapset */
> >       sprintf(buffer,"'%s'/'%s'/VAR", location, mapset);
> >       if ((fd = creat (buffer, O_RDWR)) < 0) {
> >               perror (buffer);
> >               G_fatal_error("Cannot create VAR file in new mapset");
> >       }
> >
> >       fprintf (fd, "DB_DRIVER: dbf\n");
> >       fprintf (fd, "DB_DATABASE: 
> >       $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n");
> >       fclose (fd);
> >
> >mke_mapset.c: In function `make_mapset':
> >mke_mapset.c:33: warning: assignment makes pointer from integer without a 
> >cast
> >
> >My usual string problems... Then it happily segfaults.
> >Any idea?
> 
> I think creat() only returns a file descriptor. But fprintf and fclose 
> have a stream as their first argument. So you need to call fdopen() to 
> derive a stream from the file descriptor returned by creat. I think. But 
> why not just do it all in one step with fopen() instead of creat(). I have 
> never seen creat() used like that.

I was looking at lock.c in the same directory. Maybe it's wrong
as well?
 
> Also to be more buffer overflow-safe you could write
> sprintf(buffer,"'%s'/'%s'/VAR", location, mapset);
> instead as
> char *buffer;
> G_asprintf(&buffer,"'%s'/'%s'/VAR", location, mapset);
> /* do something with buffer */
> G_free(buffer);
> 
> Hope this helps a little bit.

Cool - I got it working.

Thanks for the quick help,

 Markus

PS: Now I have to learn TCL to fix the GUI as well




More information about the grass-dev mailing list