gwenhywfar  5.10.1
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 #include "gwenbuild/filenames.h"
18 
19 #include <gwenhywfar/debug.h>
20 #include <gwenhywfar/directory.h>
21 
22 
23 
24 
25 int GWB_InstallFiles(const char *fileName, const char *destDir)
26 {
27  GWB_KEYVALUEPAIR_LIST *kvpList;
28  GWB_KEYVALUEPAIR *kvp;
29  GWEN_BUFFER *destPathBuf;
30 
31  kvpList=GWB_Utils_ReadInstallFileList(fileName);
32  if (kvpList==NULL) {
33  DBG_ERROR(NULL, "Error reading install file list (file \"%s\")", fileName);
34  return GWEN_ERROR_GENERIC;
35  }
36 
37  destPathBuf=GWEN_Buffer_new(0, 256, 0, 1);
38  kvp=GWB_KeyValuePair_List_First(kvpList);
39  while(kvp) {
40  const char *sDestPath;
41  const char *sSrcPath;
42  int rv;
43 
44  sDestPath=GWB_KeyValuePair_GetKey(kvp);
45  sSrcPath=GWB_KeyValuePair_GetValue(kvp);
46  if (destDir) {
47  GWEN_Buffer_AppendString(destPathBuf, destDir);
49  GWEN_Buffer_AppendString(destPathBuf, sDestPath);
50  sDestPath=GWEN_Buffer_GetStart(destPathBuf);
51  }
52 
53  fprintf(stdout, "Installing file '%s'\n", sSrcPath);
54  rv=GWB_Utils_CopyFile(sSrcPath, sDestPath);
55  if (rv<0) {
56  fprintf(stderr, "ERROR: Error installing file \"%s\"\n", sSrcPath);
57  GWEN_Buffer_free(destPathBuf);
58  GWB_KeyValuePair_List_free(kvpList);
59  return 2;
60  }
61  GWEN_Buffer_Reset(destPathBuf);
62  kvp=GWB_KeyValuePair_List_Next(kvp);
63  }
64  GWEN_Buffer_free(destPathBuf);
65  GWB_KeyValuePair_List_free(kvpList);
66  return 0;
67 }
68 
69 
70 
71 
72 
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:202
#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:460
#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:25
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989