gwenhywfar  5.7.2
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 
18 #include <gwenhywfar/debug.h>
19 #include <gwenhywfar/directory.h>
20 
21 #include <unistd.h>
22 
23 
24 
25 
26 int GWB_Clean(const char *fname)
27 {
28  GWB_FILE_LIST2 *fileList;
29 
30  fileList=GWB_Utils_ReadFileList2(fname);
31  if (fileList) {
32  GWB_FILE_LIST2_ITERATOR *it;
33 
34  it=GWB_File_List2_First(fileList);
35  if (it) {
36  GWB_FILE *file;
37  GWEN_BUFFER *fnameBuf;
38 
39  fnameBuf=GWEN_Buffer_new(0, 256, 0, 1);
40  file=GWB_File_List2Iterator_Data(it);
41  while(file) {
43  const char *s;
44 
45  s=GWB_File_GetFolder(file);
46  if (s && *s) {
47  GWEN_Buffer_AppendString(fnameBuf, s);
49  }
51  fprintf(stdout, "Deleting '%s'\n", GWEN_Buffer_GetStart(fnameBuf));
52  unlink(GWEN_Buffer_GetStart(fnameBuf));
53  GWEN_Buffer_Reset(fnameBuf);
54  }
55 
56  file=GWB_File_List2Iterator_Next(it);
57  }
58 
59  GWB_File_List2Iterator_free(it);
60  }
61  GWB_File_List2_free(fileList);
62  }
63 
64  return 0;
65 }
66 
67 
68 
69 
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:125
const char * GWB_File_GetName(const GWB_FILE *f)
Definition: file.c:144
GWB_FILE_LIST2 * GWB_Utils_ReadFileList2(const char *fileName)
Definition: utils.c:68
int GWB_Clean(const char *fname)
Definition: c_clean.c:26
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:97
#define GWB_FILE_FLAGS_GENERATED
Definition: file.h:23
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989