[GRASS-windows] Re: [winGRASS] v.db.addcol

Moritz Lennert mlennert at club.worldonline.be
Fri Nov 23 10:58:02 EST 2007


On Sat, November 10, 2007 14:20, Glynn Clements wrote:
>
> Moritz Lennert wrote:
>
>> > Call remove() first.
>> >
>> I've found the following other places where I have the feeling that this
>> needs to be done, but would like confirmation that these are correct:
>
> [snip]
>
> I think that we need a G_rename_file() function (G_rename() already
> exists; that renames maps etc). Ideally, the remove() call should only
> be used on Windows.

Does this look like what you meant ? I imagine I should add some error
checking in there ?


Index: rename.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/gis/rename.c,v
retrieving revision 2.4
diff -u -r2.4 rename.c
--- rename.c	14 Apr 2007 23:02:00 -0000	2.4
+++ rename.c	23 Nov 2007 15:08:44 -0000
@@ -19,6 +19,33 @@


 /**
+ * \fn int G_rename_file (char *oldname, char *newname)
+ *
+ * \brief Rename a file in the filesystem.
+ *
+ * The file or directory <b>oldname</b> is renamed to <b>newname</b>.<br>
+ *
+ *
+ * \param[in] oldname
+ * \param[in] newname
+ * \return 0 if <b>oldname</b> does not exist
+ * \return 1 if successful
+ * \return -1 on error
+ */
+
+int G_rename_file ( const char *oldname, const char *newname )
+{
+    char from[512], to[512];
+
+#ifdef __MINGW32__
+  remove(to);
+#endif
+
+return rename(from, to) == 0 ? 1 : -1;
+}
+
+
+/**
  * \fn int G_rename (char *element, char *oldname, char *newname)
  *
  * \brief Rename a database file.
@@ -60,5 +87,5 @@
     G__file_name (to, element, newname, mapset);

     /* return result of rename */
-    return rename(from, to) == 0 ? 1 : -1;
+    return G_rename_file(from, to);
 }

Moritz

>
>> One I don't know how to interpret what happens is this in
>> lib/g3d/g3dclose.c:
>
> It appears to have been copied verbatim from lib/gis/closecell.c. The
> original has since been modified to simply call rename() rather than
> messing around with link() or CopyFile().
>
> --
> Glynn Clements <glynn at gclements.plus.com>
>




More information about the grass-windows mailing list