FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
utility.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
17 
18 #include <stdio.h>
19 #include <sys/stat.h>
20 #include "utility.h"
21 
28 int file_dir_existed(char *path_name)
29 {
30  struct stat sts;
31  int existed = 1; // 0: not existed, 1: existed, default existed
32  if ((stat (path_name, &sts)) == -1)
33  {
34  //printf ("The file or dir %s doesn't exist...\n", path_name);
35  existed = 0;
36  }
37  return existed;
38 }
39 
45 int RemoveDir(char *dirpath)
46 {
47  char RMcmd[MAX_LENGTH];
48  int rc;
49  memset(RMcmd, '\0', sizeof(RMcmd));
50  snprintf(RMcmd, MAX_LENGTH-1, "rm -rf '%s'", dirpath);
51  rc = system(RMcmd);
52  return rc;
53 } /* RemoveDir() */
54 
55 #if 0
56 int main()
57 {
58  int result = file_dir_existed("./test-data");
59  printf("result is:%d\n", result);
60  return 0;
61 }
62 #endif
int RemoveDir(char *dirpath)
Remove all files under dirpath.
Definition: utility.c:45