[GRASS-dev] Re: mkdir function
Glynn Clements
glynn at gclements.plus.com
Wed Dec 13 14:49:12 EST 2006
Markus Neteler wrote:
> > > Probably a search/replace of ' mkdir' would do, using G_mkdir() from
> > > ./lib/gis/paths.c
> > > ? Or we need to modify G_mkdir() to accepts two parameters.
> >
> > No, G_mkdir() is fine.
> >
> > On Unix, the mode argument should always be 0777, so the user has
> > complete control of the permissions via their umask; anything which
> > uses a more restrictive mode is second-guessing the user.
> >
> > The only programs which should be setting permissions explicitly are
> > those which provide some other mechanism for the user to control the
> > permissions.
>
> I have done the changes to G_mkdir() accordingly.
> Also added a G_lstat() in lib/gis/paths.c for a similar
> problem.
>
> Find attached a diff for review.
>
> The following 3 functions are too complicated for me (!)
> to fix:
> G_mkdir TODOS:
> lib/g3d/g3dwindowio.c
The only code here which uses mkdir() is commented out.
> lib/gis/mapset_msc.c
I'm currently testing the attached patch.
> lib/raster/io_fifo.c
Can't we just kill this? I don't even know if it still works, given
that almost no-one actually uses --enable-fifo.
In any case, I doubt that file will work on Windows.
--
Glynn Clements <glynn at gclements.plus.com>
-------------- next part --------------
Index: include/gis.h
===================================================================
RCS file: /grassrepository/grass6/include/gis.h,v
retrieving revision 1.36
diff -u -r1.36 gis.h
--- include/gis.h 3 Nov 2006 20:07:09 -0000 1.36
+++ include/gis.h 13 Dec 2006 19:44:34 -0000
@@ -107,6 +107,7 @@
#define GNAME_MAX 256
#define GMAPSET_MAX 256
+#define GPATH_MAX 4096
/* Macros for type size independent integers */
/* Use these for portability to ensure integers are truly 32bit */
Index: lib/gis/mapset_msc.c
===================================================================
RCS file: /grassrepository/grass6/lib/gis/mapset_msc.c,v
retrieving revision 1.5
diff -u -r1.5 mapset_msc.c
--- lib/gis/mapset_msc.c 10 Nov 2006 10:02:02 -0000 1.5
+++ lib/gis/mapset_msc.c 13 Dec 2006 19:44:34 -0000
@@ -17,24 +17,16 @@
#include <sys/types.h>
#include <sys/stat.h>
-#ifdef __MINGW32__
-# define mkdir(name, mode) ((mkdir) (name))
-#endif
-
int G__make_mapset_element (char *p_element)
{
- char command[1024];
- char *path;
+ char path[GPATH_MAX];
char *p;
- char *G_mapset();
char *element;
element = p_element;
if (*element == 0)
return 0;
- strcpy (path = command, "mkdir ");
- while (*path)
- path++;
+ path = command;
G__file_name (p = path, "", "", G_mapset());
while (*p)
@@ -53,21 +45,10 @@
if (*element == '/' || *element == 0)
{
*p = 0;
-/* MOD shapiro 16apr91 */
- if (access (path, 0) != 0)
- {
- mkdir(path, 0777);
- }
-/* end MOD */
if (access (path, 0) != 0)
- {
- system (command);
- }
+ G_mkdir(path, 0777);
if (access (path, 0) != 0)
- {
G_fatal_error (_("can't make mapset element %s (%s)"), p_element, path);
- exit(EXIT_FAILURE);
- }
if (*element == 0)
return 1;
}
@@ -84,12 +65,14 @@
****************************************************************/
int G__mapset_permissions (char *mapset)
{
- char path[2000];
+ char path[GPATH_MAX];
struct stat info;
G__file_name (path,"","",mapset);
- if (stat (path, &info) != 0)
+ if (G_lstat (path, &info) != 0)
+ return -1;
+ if (!S_ISDIR(info.st_mode))
return -1;
#ifndef __MINGW32__
@@ -113,12 +96,14 @@
****************************************************************/
int G__mapset_permissions2 ( char * gisdbase, char * location, char *mapset )
{
- char path[2000];
+ char path[GPATH_MAX];
struct stat info;
sprintf ( path, "%s/%s/%s", gisdbase, location, mapset );
- if (stat (path, &info) != 0)
+ if (G_lstat (path, &info) != 0)
+ return -1;
+ if (!S_ISDIR(info.st_mode))
return -1;
#ifndef __MINGW32__
More information about the grass-dev
mailing list