Browse Source

Set all members to NULL or 0 manually and implement fopen under EASYCSV_W

redesign
Pradana AUMARS 11 months ago
parent
commit
b2f9953f31
  1. 37
      src/easycsv.c

37
src/easycsv.c

@ -688,22 +688,35 @@ _easycsv_priv_init(const char *fp,
const EASYCSV_ERRORMSG error)
{
_easycsv *_priv = malloc(sizeof(_easycsv));
memset(_priv, 0, sizeof(*_priv)); // set all members to NULL or 0
_priv->file = NULL;
_priv->temp = NULL;
_priv->fp = NULL;
_priv->tmpfp = NULL;
_priv->rows = 0;
_priv->cols = 0;
#ifdef EASYCSV_DEBUG
_priv->start = 0;
#endif
_priv->error = error;
/* Open file according to mode */
switch (mode) {
case EASYCSV_R:
case EASYCSV_W: {
case EASYCSV_R: {
_priv->file = fopen(fp, "r");
break;
}
case EASYCSV_W: {
_priv->file = fopen(fp, "w");
break;
}
default: {
_easycsv_printerror(_priv, EASYCSV_UNKNOWNIOMODE);
_easycsv_priv_free(_priv);
return NULL;
}
}
if (_priv->file == NULL)
{
@ -724,17 +737,14 @@ _easycsv_priv_init(const char *fp,
_priv->rows = _easycsv_rows(_priv, mode);
_priv->cols = _easycsv_columns(_priv, mode);
}
else {
_priv->rows = 0;
_priv->cols = 0;
}
if (mode == EASYCSV_W) {
/* csv->tmpfp = malloc(16 + stfp + 1); */
/* strncpy(csv->tmpfp, prefix, 16); */
if (mode == EASYCSV_W) {
/* csv->tmpfp = malloc(16 + stfp + 1); */
/* strncpy(csv->tmpfp, prefix, 16); */
/* strncat(csv->tmpfp, fp, stfp); */
do {
/* Write to temporary file */
unsigned int i = 1;
@ -784,8 +794,7 @@ _easycsv_priv_init(const char *fp,
*/
}
}
return _priv;
}

Loading…
Cancel
Save