gwenhywfar  5.7.2
c_install.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_install.h"
16 #include "utils.h"
17 
18 #include <gwenhywfar/debug.h>
19 #include <gwenhywfar/directory.h>
20 
21 
22 
23 
24 int GWB_InstallFiles(const char *fileName, const char *destDir)
25 {
26  GWB_KEYVALUEPAIR_LIST *kvpList;
27  GWB_KEYVALUEPAIR *kvp;
28  GWEN_BUFFER *destPathBuf;
29 
30  kvpList=GWB_Utils_ReadInstallFileList(fileName);
31  if (kvpList==NULL) {
32  DBG_ERROR(NULL, "Error reading install file list (file \"%s\")", fileName);
33  return GWEN_ERROR_GENERIC;
34  }
35 
36  destPathBuf=GWEN_Buffer_new(0, 256, 0, 1);
37  kvp=GWB_KeyValuePair_List_First(kvpList);
38  while(kvp) {
39  const char *sDestPath;
40  const char *sSrcPath;
41  int rv;
42 
43  sDestPath=GWB_KeyValuePair_GetKey(kvp);
44  sSrcPath=GWB_KeyValuePair_GetValue(kvp);
45  if (destDir) {
46  GWEN_Buffer_AppendString(destPathBuf, destDir);
48  GWEN_Buffer_AppendString(destPathBuf, sDestPath);
49  sDestPath=GWEN_Buffer_GetStart(destPathBuf);
50  }
51 
52  fprintf(stdout, "Installing file '%s'\n", sSrcPath);
53  rv=GWB_Utils_CopyFile(sSrcPath, sDestPath);
54  if (rv<0) {
55  fprintf(stderr, "ERROR: Error installing file \"%s\"\n", sSrcPath);
56  GWEN_Buffer_free(destPathBuf);
57  GWB_KeyValuePair_List_free(kvpList);
58  return 2;
59  }
60  GWEN_Buffer_Reset(destPathBuf);
61  kvp=GWB_KeyValuePair_List_Next(kvp);
62  }
63  GWEN_Buffer_free(destPathBuf);
64  GWB_KeyValuePair_List_free(kvpList);
65  return 0;
66 }
67 
68 
69 
70 
71 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define GWEN_DIR_SEPARATOR_S
#define NULL
Definition: binreloc.c:300
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
GWB_KEYVALUEPAIR_LIST * GWB_Utils_ReadInstallFileList(const char *fileName)
Definition: utils.c:199
#define GWEN_ERROR_GENERIC
Definition: error.h:62
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
int GWB_Utils_CopyFile(const char *sSrcPath, const char *sDestPath)
Definition: utils.c:452
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
struct GWB_KEYVALUEPAIR GWB_KEYVALUEPAIR
Definition: keyvaluepair.h:19
const char * GWB_KeyValuePair_GetValue(const GWB_KEYVALUEPAIR *kvp)
Definition: keyvaluepair.c:97
const char * GWB_KeyValuePair_GetKey(const GWB_KEYVALUEPAIR *kvp)
Definition: keyvaluepair.c:79
int GWB_InstallFiles(const char *fileName, const char *destDir)
Definition: c_install.c:24
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989