gwenhywfar  5.10.1
c_clean.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Feb 08 2021
3  copyright : (C) 2021 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 
15 #include "c_clean.h"
16 #include "utils.h"
17 #include "gwenbuild/filenames.h"
18 
19 #include <gwenhywfar/debug.h>
20 #include <gwenhywfar/directory.h>
21 
22 #include <unistd.h>
23 
24 
25 
26 
27 int GWB_Clean(const char *fname)
28 {
29  GWB_FILE_LIST2 *fileList;
30 
31  fileList=GWB_Utils_ReadFileList2(fname);
32  if (fileList) {
33  GWB_FILE_LIST2_ITERATOR *it;
34 
35  it=GWB_File_List2_First(fileList);
36  if (it) {
37  GWB_FILE *file;
38  GWEN_BUFFER *fnameBuf;
39 
40  fnameBuf=GWEN_Buffer_new(0, 256, 0, 1);
41  file=GWB_File_List2Iterator_Data(it);
42  while(file) {
44  const char *s;
45 
46  s=GWB_File_GetFolder(file);
47  if (s && *s) {
48  GWEN_Buffer_AppendString(fnameBuf, s);
50  }
52  fprintf(stdout, "Deleting '%s'\n", GWEN_Buffer_GetStart(fnameBuf));
53  unlink(GWEN_Buffer_GetStart(fnameBuf));
54  GWEN_Buffer_Reset(fnameBuf);
55  }
56 
57  file=GWB_File_List2Iterator_Next(it);
58  }
59 
60  GWB_File_List2Iterator_free(it);
61  }
62  GWB_File_List2_free(fileList);
63  }
64 
65  return 0;
66 }
67 
68 
69 
70 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define GWEN_DIR_SEPARATOR_S
struct GWB_FILE GWB_FILE
Definition: file.h:18
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
Definition: buffer.c:650
const char * GWB_File_GetFolder(const GWB_FILE *f)
Definition: file.c:127
const char * GWB_File_GetName(const GWB_FILE *f)
Definition: file.c:146
GWB_FILE_LIST2 * GWB_Utils_ReadFileList2(const char *fileName)
Definition: utils.c:71
int GWB_Clean(const char *fname)
Definition: c_clean.c:27
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
uint32_t GWB_File_GetFlags(const GWB_FILE *f)
Definition: file.c:99
#define GWB_FILE_FLAGS_GENERATED
Definition: file.h:23
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989