GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rename.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <grass/gis.h>
22 
23 
35 int G_rename_file(const char *oldname, const char *newname)
36 {
37 
38 #ifdef __MINGW32__
39  remove(newname);
40 #endif
41 
42  return rename(oldname, newname);
43 }
44 
62 int G_rename(const char *element, const char *oldname, const char *newname)
63 {
64  const char *mapset;
65  char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
66  char from[512], to[512];
67 
68  /* name in mapset legal only if mapset is current mapset */
69  mapset = G_mapset();
70  if (G__name_is_fully_qualified(oldname, xname, xmapset)
71  && strcmp(mapset, xmapset))
72  return -1;
73  if (G__name_is_fully_qualified(newname, xname, xmapset)
74  && strcmp(mapset, xmapset))
75  return -1;
76 
77  /* if file does not exist return 0 */
78  if (access(G__file_name(from, element, oldname, mapset), 0) != 0)
79  return 0;
80 
81  G__file_name(to, element, newname, mapset);
82 
83  /* return result of rename */
84  return G_rename_file(from, to) == 0 ? 1 : -1;
85 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
char xmapset[512]
Definition: g3dcats.c:89
int G_rename(const char *element, const char *oldname, const char *newname)
Rename a database file.
Definition: rename.c:62
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:33
int G_rename_file(const char *oldname, const char *newname)
Rename a file in the filesystem.
Definition: rename.c:35
char xname[512]
Definition: g3dcats.c:89
int G__name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:57