FOSSology  4.4.0
Open Source License Compliance by Open Source Software
utility.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #include <stdio.h>
8 #include <sys/stat.h>
9 #include "utility.h"
10 
17 int file_dir_existed(char *path_name)
18 {
19  struct stat sts;
20  int existed = 1; // 0: not existed, 1: existed, default existed
21  if ((stat (path_name, &sts)) == -1)
22  {
23  //printf ("The file or dir %s doesn't exist...\n", path_name);
24  existed = 0;
25  }
26  return existed;
27 }
28 
34 int RemoveDir(char *dirpath)
35 {
36  char RMcmd[MAX_LENGTH];
37  int rc;
38  memset(RMcmd, '\0', sizeof(RMcmd));
39  snprintf(RMcmd, MAX_LENGTH-1, "rm -rf '%s'", dirpath);
40  rc = system(RMcmd);
41  return rc;
42 } /* RemoveDir() */
43 
44 #if 0
45 int main()
46 {
47  int result = file_dir_existed("./test-data");
48  printf("result is:%d\n", result);
49  return 0;
50 }
51 #endif
int RemoveDir(char *dirpath)
Remove all files under dirpath.
Definition: utility.c:34