remove.c

Go to the documentation of this file.
00001 /***********************************************************************
00002  *
00003  *  G_remove (element, name)
00004  *     char *element          mapset element containing name
00005  *     char *name             file name to be removed
00006  *
00007  *  Only files in current mapset can be removed
00008  *
00009  *  Returns  -1  on fail
00010  *            0  if no file
00011  *            1  if successful
00012  *
00013  ***********************************************************************/
00014 
00015 #include <stdio.h>
00016 #include <string.h>
00017 #include <unistd.h>
00018 #include <stdlib.h>
00019 #include "gis.h"
00020 
00021 
00037 int G_remove ( char *element, char *name)
00038 {
00039     char path[1040];
00040     char *mapset;
00041     char xname[512], xmapset[512];
00042     char cmd[1100];
00043 
00044     if (G_legal_filename(name) < 0)
00045             return -1;
00046 
00047 /* name in mapset legal only if mapset is current mapset */
00048     mapset = G_mapset();
00049     if (G__name_is_fully_qualified (name, xname, xmapset)
00050     && strcmp (mapset, xmapset))
00051             return -1;
00052 
00053 /* if file does not exist, return 0 */
00054     if (access (G__file_name (path, element, name, mapset),0) != 0)
00055             return 0;
00056 
00057     if ( remove ( path ) == 0)
00058             return 1;
00059     if (strchr(path, '\''))
00060             return -1;
00061 
00062     sprintf(cmd, "rm -rf '%s'", path);
00063 
00064     if (G_system(cmd) == 0)
00065             return 1;
00066 
00067     return -1;
00068 }
00069 

Generated on Mon Jan 1 19:49:26 2007 for GRASS by  doxygen 1.5.1