GRASS Programmer's Manual  6.4.1(2011)
rename.c
Go to the documentation of this file.
00001 
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <unistd.h>
00021 #include <grass/gis.h>
00022 
00023 
00035 int G_rename_file(const char *oldname, const char *newname)
00036 {
00037 
00038 #ifdef __MINGW32__
00039     remove(newname);
00040 #endif
00041 
00042     return rename(oldname, newname);
00043 }
00044 
00062 int G_rename(const char *element, const char *oldname, const char *newname)
00063 {
00064     const char *mapset;
00065     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
00066     char from[512], to[512];
00067 
00068     /* name in mapset legal only if mapset is current mapset */
00069     mapset = G_mapset();
00070     if (G__name_is_fully_qualified(oldname, xname, xmapset)
00071         && strcmp(mapset, xmapset))
00072         return -1;
00073     if (G__name_is_fully_qualified(newname, xname, xmapset)
00074         && strcmp(mapset, xmapset))
00075         return -1;
00076 
00077     /* if file does not exist return 0 */
00078     if (access(G__file_name(from, element, oldname, mapset), 0) != 0)
00079         return 0;
00080 
00081     G__file_name(to, element, newname, mapset);
00082 
00083     /* return result of rename */
00084     return G_rename_file(from, to) == 0 ? 1 : -1;
00085 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines